vgtv.py 8.1 KB

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