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.

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