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.

296 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. def _real_extract(self, url):
  144. mobj = re.match(self._VALID_URL, url)
  145. video_id = mobj.group('id')
  146. host = mobj.group('host')
  147. appname = self._HOST_TO_APPNAME[host] if host else mobj.group('appname')
  148. vendor = self._APP_NAME_TO_VENDOR[appname]
  149. data = self._download_json(
  150. 'http://svp.vg.no/svp/api/v1/%s/assets/%s?appName=%s-website'
  151. % (vendor, video_id, appname),
  152. video_id, 'Downloading media JSON')
  153. if data.get('status') == 'inactive':
  154. raise ExtractorError(
  155. 'Video %s is no longer available' % video_id, expected=True)
  156. info = {
  157. 'formats': [],
  158. }
  159. if len(video_id) == 5:
  160. if appname == 'bttv':
  161. info = self._extract_video_info('btno', video_id)
  162. streams = data['streamUrls']
  163. stream_type = data.get('streamType')
  164. formats = []
  165. hls_url = streams.get('hls')
  166. if hls_url:
  167. formats.extend(self._extract_m3u8_formats(
  168. hls_url, video_id, 'mp4', m3u8_id='hls', fatal=False))
  169. hds_url = streams.get('hds')
  170. if hds_url:
  171. hdcore_sign = 'hdcore=3.7.0'
  172. f4m_formats = self._extract_f4m_formats(
  173. hds_url + '?%s' % hdcore_sign, video_id, f4m_id='hds', fatal=False)
  174. if f4m_formats:
  175. for entry in f4m_formats:
  176. # URLs without the extra param induce an 404 error
  177. entry.update({'extra_param_to_segment_url': hdcore_sign})
  178. formats.append(entry)
  179. mp4_urls = streams.get('pseudostreaming') or []
  180. mp4_url = streams.get('mp4')
  181. if mp4_url:
  182. mp4_urls.append(mp4_url)
  183. for mp4_url in mp4_urls:
  184. format_info = {
  185. 'url': mp4_url,
  186. }
  187. mobj = re.search(r'(\d+)_(\d+)_(\d+)', mp4_url)
  188. if mobj:
  189. tbr = int(mobj.group(3))
  190. format_info.update({
  191. 'width': int(mobj.group(1)),
  192. 'height': int(mobj.group(2)),
  193. 'tbr': tbr,
  194. 'format_id': 'mp4-%s' % tbr,
  195. })
  196. formats.append(format_info)
  197. info['formats'].extend(formats)
  198. if not info['formats']:
  199. properties = try_get(
  200. data, lambda x: x['streamConfiguration']['properties'], list)
  201. if properties and 'geoblocked' in properties:
  202. raise self.raise_geo_restricted(
  203. countries=[host.rpartition('.')[-1].partition('/')[0].upper()])
  204. self._sort_formats(info['formats'])
  205. info.update({
  206. 'id': video_id,
  207. 'title': self._live_title(data['title']) if stream_type == 'live' else data['title'],
  208. 'description': data['description'],
  209. 'thumbnail': data['images']['main'] + '?t[]=900x506q80',
  210. 'timestamp': data['published'],
  211. 'duration': float_or_none(data['duration'], 1000),
  212. 'view_count': data['displays'],
  213. 'is_live': True if stream_type == 'live' else False,
  214. })
  215. return info
  216. class BTArticleIE(InfoExtractor):
  217. IE_NAME = 'bt:article'
  218. IE_DESC = 'Bergens Tidende Articles'
  219. _VALID_URL = r'https?://(?:www\.)?bt\.no/(?:[^/]+/)+(?P<id>[^/]+)-\d+\.html'
  220. _TEST = {
  221. 'url': 'http://www.bt.no/nyheter/lokalt/Kjemper-for-internatet-1788214.html',
  222. 'md5': '2acbe8ad129b3469d5ae51b1158878df',
  223. 'info_dict': {
  224. 'id': '23199',
  225. 'ext': 'mp4',
  226. 'title': 'Alrekstad internat',
  227. 'description': 'md5:dc81a9056c874fedb62fc48a300dac58',
  228. 'thumbnail': r're:^https?://.*\.jpg',
  229. 'duration': 191,
  230. 'timestamp': 1289991323,
  231. 'upload_date': '20101117',
  232. 'view_count': int,
  233. },
  234. }
  235. def _real_extract(self, url):
  236. webpage = self._download_webpage(url, self._match_id(url))
  237. video_id = self._search_regex(
  238. r'<video[^>]+data-id="(\d+)"', webpage, 'video id')
  239. return self.url_result('bttv:%s' % video_id, 'VGTV')
  240. class BTVestlendingenIE(InfoExtractor):
  241. IE_NAME = 'bt:vestlendingen'
  242. IE_DESC = 'Bergens Tidende - Vestlendingen'
  243. _VALID_URL = r'https?://(?:www\.)?bt\.no/spesial/vestlendingen/#!/(?P<id>\d+)'
  244. _TESTS = [{
  245. 'url': 'http://www.bt.no/spesial/vestlendingen/#!/86588',
  246. 'md5': 'd7d17e3337dc80de6d3a540aefbe441b',
  247. 'info_dict': {
  248. 'id': '86588',
  249. 'ext': 'mov',
  250. 'title': 'Otto Wollertsen',
  251. 'description': 'Vestlendingen Otto Fredrik Wollertsen',
  252. 'timestamp': 1430473209,
  253. 'upload_date': '20150501',
  254. },
  255. 'skip': '404 Error',
  256. }, {
  257. 'url': 'http://www.bt.no/spesial/vestlendingen/#!/86255',
  258. 'md5': 'a2893f8632e96389f4bdf36aa9463ceb',
  259. 'info_dict': {
  260. 'id': '86255',
  261. 'ext': 'mov',
  262. 'title': 'Du må tåle å fryse og være sulten',
  263. 'description': 'md5:b8046f4d022d5830ddab04865791d063',
  264. 'upload_date': '20150321',
  265. 'timestamp': 1426942023,
  266. },
  267. }]
  268. def _real_extract(self, url):
  269. return self.url_result('bttv:%s' % self._match_id(url), 'VGTV')