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.

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