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.

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