You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

307 lines
10 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from .xstream import XstreamIE
  6. from ..utils import (
  7. ExtractorError,
  8. float_or_none,
  9. try_get,
  10. )
  11. class VGTVIE(XstreamIE):
  12. IE_DESC = 'VGTV, BTTV, FTV, Aftenposten and Aftonbladet'
  13. _GEO_BYPASS = False
  14. _HOST_TO_APPNAME = {
  15. 'vgtv.no': 'vgtv',
  16. 'bt.no/tv': 'bttv',
  17. 'aftenbladet.no/tv': 'satv',
  18. 'fvn.no/fvntv': 'fvntv',
  19. 'aftenposten.no/webtv': 'aptv',
  20. 'ap.vgtv.no/webtv': 'aptv',
  21. 'tv.aftonbladet.se/abtv': 'abtv',
  22. 'www.aftonbladet.se/tv': 'abtv',
  23. }
  24. _APP_NAME_TO_VENDOR = {
  25. 'vgtv': 'vgtv',
  26. 'bttv': 'bt',
  27. 'satv': 'sa',
  28. 'fvntv': 'fvn',
  29. 'aptv': 'ap',
  30. 'abtv': 'ab',
  31. }
  32. _VALID_URL = r'''(?x)
  33. (?:https?://(?:www\.)?
  34. (?P<host>
  35. %s
  36. )
  37. /?
  38. (?:
  39. (?:\#!/)?(?:video|live)/|
  40. embed?.*id=|
  41. a(?:rticles)?/
  42. )|
  43. (?P<appname>
  44. %s
  45. ):)
  46. (?P<id>\d+)
  47. ''' % ('|'.join(_HOST_TO_APPNAME.keys()), '|'.join(_APP_NAME_TO_VENDOR.keys()))
  48. _TESTS = [
  49. {
  50. # streamType: vod
  51. 'url': 'http://www.vgtv.no/#!/video/84196/hevnen-er-soet-episode-10-abu',
  52. 'md5': 'b8be7a234cebb840c0d512c78013e02f',
  53. 'info_dict': {
  54. 'id': '84196',
  55. 'ext': 'mp4',
  56. 'title': 'Hevnen er søt: Episode 10 - Abu',
  57. 'description': 'md5:e25e4badb5f544b04341e14abdc72234',
  58. 'thumbnail': r're:^https?://.*\.jpg',
  59. 'duration': 648.000,
  60. 'timestamp': 1404626400,
  61. 'upload_date': '20140706',
  62. 'view_count': int,
  63. },
  64. },
  65. {
  66. # streamType: wasLive
  67. 'url': 'http://www.vgtv.no/#!/live/100764/opptak-vgtv-foelger-em-kvalifiseringen',
  68. 'info_dict': {
  69. 'id': '100764',
  70. 'ext': 'flv',
  71. 'title': 'OPPTAK: VGTV følger EM-kvalifiseringen',
  72. 'description': 'md5:3772d9c0dc2dff92a886b60039a7d4d3',
  73. 'thumbnail': r're:^https?://.*\.jpg',
  74. 'duration': 9103.0,
  75. 'timestamp': 1410113864,
  76. 'upload_date': '20140907',
  77. 'view_count': int,
  78. },
  79. 'params': {
  80. # m3u8 download
  81. 'skip_download': True,
  82. },
  83. 'skip': 'Video is no longer available',
  84. },
  85. {
  86. # streamType: wasLive
  87. 'url': 'http://www.vgtv.no/#!/live/113063/direkte-v75-fra-solvalla',
  88. 'info_dict': {
  89. 'id': '113063',
  90. 'ext': 'mp4',
  91. 'title': 'V75 fra Solvalla 30.05.15',
  92. 'description': 'md5:b3743425765355855f88e096acc93231',
  93. 'thumbnail': r're:^https?://.*\.jpg',
  94. 'duration': 25966,
  95. 'timestamp': 1432975582,
  96. 'upload_date': '20150530',
  97. 'view_count': int,
  98. },
  99. 'params': {
  100. # m3u8 download
  101. 'skip_download': True,
  102. },
  103. },
  104. {
  105. 'url': 'http://www.aftenposten.no/webtv/#!/video/21039/trailer-sweatshop-i-can-t-take-any-more',
  106. 'md5': 'fd828cd29774a729bf4d4425fe192972',
  107. 'info_dict': {
  108. 'id': '21039',
  109. 'ext': 'mp4',
  110. 'title': 'TRAILER: «SWEATSHOP» - I can´t take any more',
  111. 'description': 'md5:21891f2b0dd7ec2f78d84a50e54f8238',
  112. 'duration': 66,
  113. 'timestamp': 1417002452,
  114. 'upload_date': '20141126',
  115. 'view_count': int,
  116. },
  117. 'params': {
  118. # m3u8 download
  119. 'skip_download': True,
  120. },
  121. },
  122. {
  123. 'url': 'http://www.bt.no/tv/#!/video/100250/norling-dette-er-forskjellen-paa-1-divisjon-og-eliteserien',
  124. 'only_matching': True,
  125. },
  126. {
  127. 'url': 'http://ap.vgtv.no/webtv#!/video/111084/de-nye-bysyklene-lettere-bedre-gir-stoerre-hjul-og-feste-til-mobil',
  128. 'only_matching': True,
  129. },
  130. {
  131. # geoblocked
  132. 'url': 'http://www.vgtv.no/#!/video/127205/inside-the-mind-of-favela-funk',
  133. 'only_matching': True,
  134. },
  135. {
  136. 'url': 'http://tv.aftonbladet.se/abtv/articles/36015',
  137. 'only_matching': True,
  138. },
  139. {
  140. 'url': 'https://www.aftonbladet.se/tv/a/36015',
  141. 'only_matching': True,
  142. },
  143. {
  144. 'url': 'abtv:140026',
  145. 'only_matching': True,
  146. },
  147. {
  148. 'url': 'http://www.vgtv.no/video/84196/hevnen-er-soet-episode-10-abu',
  149. 'only_matching': True,
  150. },
  151. ]
  152. def _real_extract(self, url):
  153. mobj = re.match(self._VALID_URL, url)
  154. video_id = mobj.group('id')
  155. host = mobj.group('host')
  156. appname = self._HOST_TO_APPNAME[host] if host else mobj.group('appname')
  157. vendor = self._APP_NAME_TO_VENDOR[appname]
  158. data = self._download_json(
  159. 'http://svp.vg.no/svp/api/v1/%s/assets/%s?appName=%s-website'
  160. % (vendor, video_id, appname),
  161. video_id, 'Downloading media JSON')
  162. if data.get('status') == 'inactive':
  163. raise ExtractorError(
  164. 'Video %s is no longer available' % video_id, expected=True)
  165. info = {
  166. 'formats': [],
  167. }
  168. if len(video_id) == 5:
  169. if appname == 'bttv':
  170. info = self._extract_video_info('btno', video_id)
  171. streams = data['streamUrls']
  172. stream_type = data.get('streamType')
  173. is_live = stream_type == 'live'
  174. formats = []
  175. hls_url = streams.get('hls')
  176. if hls_url:
  177. formats.extend(self._extract_m3u8_formats(
  178. hls_url, video_id, 'mp4',
  179. entry_protocol='m3u8' if is_live else 'm3u8_native',
  180. m3u8_id='hls', fatal=False))
  181. hds_url = streams.get('hds')
  182. if hds_url:
  183. hdcore_sign = 'hdcore=3.7.0'
  184. f4m_formats = self._extract_f4m_formats(
  185. hds_url + '?%s' % hdcore_sign, video_id, f4m_id='hds', fatal=False)
  186. if f4m_formats:
  187. for entry in f4m_formats:
  188. # URLs without the extra param induce an 404 error
  189. entry.update({'extra_param_to_segment_url': hdcore_sign})
  190. formats.append(entry)
  191. mp4_urls = streams.get('pseudostreaming') or []
  192. mp4_url = streams.get('mp4')
  193. if mp4_url:
  194. mp4_urls.append(mp4_url)
  195. for mp4_url in mp4_urls:
  196. format_info = {
  197. 'url': mp4_url,
  198. }
  199. mobj = re.search(r'(\d+)_(\d+)_(\d+)', mp4_url)
  200. if mobj:
  201. tbr = int(mobj.group(3))
  202. format_info.update({
  203. 'width': int(mobj.group(1)),
  204. 'height': int(mobj.group(2)),
  205. 'tbr': tbr,
  206. 'format_id': 'mp4-%s' % tbr,
  207. })
  208. formats.append(format_info)
  209. info['formats'].extend(formats)
  210. if not info['formats']:
  211. properties = try_get(
  212. data, lambda x: x['streamConfiguration']['properties'], list)
  213. if properties and 'geoblocked' in properties:
  214. raise self.raise_geo_restricted(
  215. countries=[host.rpartition('.')[-1].partition('/')[0].upper()])
  216. self._sort_formats(info['formats'])
  217. info.update({
  218. 'id': video_id,
  219. 'title': self._live_title(data['title']) if is_live else data['title'],
  220. 'description': data['description'],
  221. 'thumbnail': data['images']['main'] + '?t[]=900x506q80',
  222. 'timestamp': data['published'],
  223. 'duration': float_or_none(data['duration'], 1000),
  224. 'view_count': data['displays'],
  225. 'is_live': is_live,
  226. })
  227. return info
  228. class BTArticleIE(InfoExtractor):
  229. IE_NAME = 'bt:article'
  230. IE_DESC = 'Bergens Tidende Articles'
  231. _VALID_URL = r'https?://(?:www\.)?bt\.no/(?:[^/]+/)+(?P<id>[^/]+)-\d+\.html'
  232. _TEST = {
  233. 'url': 'http://www.bt.no/nyheter/lokalt/Kjemper-for-internatet-1788214.html',
  234. 'md5': '2acbe8ad129b3469d5ae51b1158878df',
  235. 'info_dict': {
  236. 'id': '23199',
  237. 'ext': 'mp4',
  238. 'title': 'Alrekstad internat',
  239. 'description': 'md5:dc81a9056c874fedb62fc48a300dac58',
  240. 'thumbnail': r're:^https?://.*\.jpg',
  241. 'duration': 191,
  242. 'timestamp': 1289991323,
  243. 'upload_date': '20101117',
  244. 'view_count': int,
  245. },
  246. }
  247. def _real_extract(self, url):
  248. webpage = self._download_webpage(url, self._match_id(url))
  249. video_id = self._search_regex(
  250. r'<video[^>]+data-id="(\d+)"', webpage, 'video id')
  251. return self.url_result('bttv:%s' % video_id, 'VGTV')
  252. class BTVestlendingenIE(InfoExtractor):
  253. IE_NAME = 'bt:vestlendingen'
  254. IE_DESC = 'Bergens Tidende - Vestlendingen'
  255. _VALID_URL = r'https?://(?:www\.)?bt\.no/spesial/vestlendingen/#!/(?P<id>\d+)'
  256. _TESTS = [{
  257. 'url': 'http://www.bt.no/spesial/vestlendingen/#!/86588',
  258. 'md5': 'd7d17e3337dc80de6d3a540aefbe441b',
  259. 'info_dict': {
  260. 'id': '86588',
  261. 'ext': 'mov',
  262. 'title': 'Otto Wollertsen',
  263. 'description': 'Vestlendingen Otto Fredrik Wollertsen',
  264. 'timestamp': 1430473209,
  265. 'upload_date': '20150501',
  266. },
  267. 'skip': '404 Error',
  268. }, {
  269. 'url': 'http://www.bt.no/spesial/vestlendingen/#!/86255',
  270. 'md5': 'a2893f8632e96389f4bdf36aa9463ceb',
  271. 'info_dict': {
  272. 'id': '86255',
  273. 'ext': 'mov',
  274. 'title': 'Du må tåle å fryse og være sulten',
  275. 'description': 'md5:b8046f4d022d5830ddab04865791d063',
  276. 'upload_date': '20150321',
  277. 'timestamp': 1426942023,
  278. },
  279. }]
  280. def _real_extract(self, url):
  281. return self.url_result('bttv:%s' % self._match_id(url), 'VGTV')