vgtv.py 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. ExtractorError,
  7. float_or_none,
  8. )
  9. class VGTVIE(InfoExtractor):
  10. IE_DESC = 'VGTV, BTTV, FTV, Aftenposten and Aftonbladet'
  11. _VALID_URL = r'''(?x)
  12. https?://(?:www\.)?
  13. (?P<host>
  14. vgtv.no|
  15. (?:bt|aftenbladet).no/tv|
  16. fvn.no/fvntv|
  17. aftenposten.no/webtv
  18. )
  19. /
  20. (?:
  21. \#!/(?:video|live)/|
  22. embed?.*id=
  23. )
  24. (?P<id>\d+)
  25. '''
  26. _TESTS = [
  27. {
  28. # streamType: vod
  29. 'url': 'http://www.vgtv.no/#!/video/84196/hevnen-er-soet-episode-10-abu',
  30. 'md5': 'b8be7a234cebb840c0d512c78013e02f',
  31. 'info_dict': {
  32. 'id': '84196',
  33. 'ext': 'mp4',
  34. 'title': 'Hevnen er søt: Episode 10 - Abu',
  35. 'description': 'md5:e25e4badb5f544b04341e14abdc72234',
  36. 'thumbnail': 're:^https?://.*\.jpg',
  37. 'duration': 648.000,
  38. 'timestamp': 1404626400,
  39. 'upload_date': '20140706',
  40. 'view_count': int,
  41. },
  42. },
  43. {
  44. # streamType: wasLive
  45. 'url': 'http://www.vgtv.no/#!/live/100764/opptak-vgtv-foelger-em-kvalifiseringen',
  46. 'info_dict': {
  47. 'id': '100764',
  48. 'ext': 'flv',
  49. 'title': 'OPPTAK: VGTV følger EM-kvalifiseringen',
  50. 'description': 'md5:3772d9c0dc2dff92a886b60039a7d4d3',
  51. 'thumbnail': 're:^https?://.*\.jpg',
  52. 'duration': 9103.0,
  53. 'timestamp': 1410113864,
  54. 'upload_date': '20140907',
  55. 'view_count': int,
  56. },
  57. 'params': {
  58. # m3u8 download
  59. 'skip_download': True,
  60. },
  61. 'skip': 'Video is no longer available',
  62. },
  63. {
  64. # streamType: wasLive
  65. 'url': 'http://www.vgtv.no/#!/live/113063/direkte-v75-fra-solvalla',
  66. 'info_dict': {
  67. 'id': '113063',
  68. 'ext': 'mp4',
  69. 'title': 'V75 fra Solvalla 30.05.15',
  70. 'description': 'md5:b3743425765355855f88e096acc93231',
  71. 'thumbnail': 're:^https?://.*\.jpg',
  72. 'duration': 25966,
  73. 'timestamp': 1432975582,
  74. 'upload_date': '20150530',
  75. 'view_count': int,
  76. },
  77. 'params': {
  78. # m3u8 download
  79. 'skip_download': True,
  80. },
  81. },
  82. {
  83. 'url': 'http://www.aftenposten.no/webtv/#!/video/21039/trailer-sweatshop-i-can-t-take-any-more',
  84. 'md5': '7fbc265a3ca4933a423c7a66aa879a67',
  85. 'info_dict': {
  86. 'id': '21039',
  87. 'ext': 'mp4',
  88. 'title': 'TRAILER: «SWEATSHOP» - I can´t take any more',
  89. 'description': 'md5:21891f2b0dd7ec2f78d84a50e54f8238',
  90. 'duration': 66,
  91. 'timestamp': 1417002452,
  92. 'upload_date': '20141126',
  93. 'view_count': int,
  94. }
  95. },
  96. {
  97. 'url': 'http://www.bt.no/tv/#!/video/100250/norling-dette-er-forskjellen-paa-1-divisjon-og-eliteserien',
  98. 'only_matching': True,
  99. },
  100. ]
  101. _HOST_WEBSITES = {
  102. 'vgtv.no': {
  103. 'vendor': 'vgtv',
  104. 'appname': 'vgtv',
  105. },
  106. 'bt.no/tv': {
  107. 'vendor': 'bt',
  108. 'appname': 'bttv',
  109. },
  110. 'aftenbladet.no/tv': {
  111. 'vendor': 'sa',
  112. 'appname': 'satv',
  113. },
  114. 'fvn.no/fvntv': {
  115. 'vendor': 'fvn',
  116. 'appname': 'fvntv',
  117. },
  118. 'aftenposten.no/webtv': {
  119. 'vendor': 'ap',
  120. 'appname': 'aptv',
  121. },
  122. }
  123. def _real_extract(self, url):
  124. mobj = re.match(self._VALID_URL, url)
  125. video_id = mobj.group('id')
  126. host = mobj.group('host')
  127. data = self._download_json(
  128. 'http://svp.vg.no/svp/api/v1/%s/assets/%s?appName=%s-website'
  129. % (self._HOST_WEBSITES[host]['vendor'], video_id, self._HOST_WEBSITES[host]['appname']),
  130. video_id, 'Downloading media JSON')
  131. if data.get('status') == 'inactive':
  132. raise ExtractorError(
  133. 'Video %s is no longer available' % video_id, expected=True)
  134. streams = data['streamUrls']
  135. stream_type = data.get('streamType')
  136. formats = []
  137. hls_url = streams.get('hls')
  138. if hls_url:
  139. m3u8_formats = self._extract_m3u8_formats(hls_url, video_id, 'mp4', m3u8_id='hls', fatal=False)
  140. if m3u8_formats:
  141. formats.extend(m3u8_formats)
  142. hds_url = streams.get('hds')
  143. # wasLive hds are always 404
  144. if hds_url and stream_type != 'wasLive':
  145. f4m_formats = self._extract_f4m_formats(hds_url + '?hdcore=3.2.0&plugin=aasp-3.2.0.77.18', video_id, f4m_id='hds', fatal=False)
  146. if f4m_formats:
  147. formats.extend(f4m_formats)
  148. mp4_urls = streams.get('pseudostreaming') or []
  149. mp4_url = streams.get('mp4')
  150. if mp4_url:
  151. mp4_urls.append(mp4_url)
  152. for mp4_url in mp4_urls:
  153. format_info = {
  154. 'url': mp4_url,
  155. 'preference': 1,
  156. }
  157. mobj = re.search('(\d+)_(\d+)_(\d+)', mp4_url)
  158. if mobj:
  159. vbr = int(mobj.group(3))
  160. format_info.update({
  161. 'width': int(mobj.group(1)),
  162. 'height': int(mobj.group(2)),
  163. 'vbr': vbr,
  164. 'format_id': 'mp4-%s' % vbr,
  165. })
  166. formats.append(format_info)
  167. self._sort_formats(formats)
  168. return {
  169. 'id': video_id,
  170. 'title': self._live_title(data['title']) if stream_type == 'live' else data['title'],
  171. 'description': data['description'],
  172. 'thumbnail': data['images']['main'] + '?t[]=900x506q80',
  173. 'timestamp': data['published'],
  174. 'duration': float_or_none(data['duration'], 1000),
  175. 'view_count': data['displays'],
  176. 'formats': formats,
  177. 'is_live': True if stream_type == 'live' else False,
  178. }
  179. class BTArticleIE(InfoExtractor):
  180. IE_NAME = 'bt:article'
  181. IE_DESC = 'Bergens Tidende Articles'
  182. _VALID_URL = 'http://(?:www\.)?bt\.no/(?:[^/]+/)+(?P<id>[^/]+)-\d+\.html'
  183. _TEST = {
  184. 'url': 'http://www.bt.no/nyheter/lokalt/Kjemper-for-internatet-1788214.html',
  185. 'md5': 'd055e8ee918ef2844745fcfd1a4175fb',
  186. 'info_dict': {
  187. 'id': '23199',
  188. 'ext': 'mp4',
  189. 'title': 'Alrekstad internat',
  190. 'description': 'md5:dc81a9056c874fedb62fc48a300dac58',
  191. 'thumbnail': 're:^https?://.*\.jpg',
  192. 'duration': 191,
  193. 'timestamp': 1289991323,
  194. 'upload_date': '20101117',
  195. 'view_count': int,
  196. },
  197. }
  198. def _real_extract(self, url):
  199. webpage = self._download_webpage(url, self._match_id(url))
  200. video_id = self._search_regex(
  201. r'SVP\.Player\.load\(\s*(\d+)', webpage, 'video id')
  202. return self.url_result('http://bt.no/tv/embed?id=%s' % video_id, 'VGTV')
  203. class BTVestlendingenIE(InfoExtractor):
  204. IE_NAME = 'bt:vestlendingen'
  205. IE_DESC = 'Bergens Tidende - Vestlendingen'
  206. _VALID_URL = 'http://(?:www\.)?bt\.no/spesial/vestlendingen/#!/(?P<id>\d+)'
  207. _TEST = {
  208. 'url': 'http://www.bt.no/spesial/vestlendingen/#!/86588',
  209. 'md5': 'd7d17e3337dc80de6d3a540aefbe441b',
  210. 'info_dict': {
  211. 'id': '86588',
  212. 'ext': 'mov',
  213. 'title': 'Otto Wollertsen',
  214. 'description': 'Vestlendingen Otto Fredrik Wollertsen',
  215. 'timestamp': 1430473209,
  216. 'upload_date': '20150501',
  217. },
  218. }
  219. def _real_extract(self, url):
  220. return self.url_result('http://bt.no/tv/embed?id=%s' % self._match_id(url), 'VGTV')