logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

vgtv.py (10882B)


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