logo

youtube-dl

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

orf.py (20485B)


  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..compat import compat_str
  6. from ..utils import (
  7. clean_html,
  8. determine_ext,
  9. float_or_none,
  10. HEADRequest,
  11. int_or_none,
  12. orderedSet,
  13. remove_end,
  14. str_or_none,
  15. strip_jsonp,
  16. unescapeHTML,
  17. unified_strdate,
  18. url_or_none,
  19. )
  20. class ORFTVthekIE(InfoExtractor):
  21. IE_NAME = 'orf:tvthek'
  22. IE_DESC = 'ORF TVthek'
  23. _VALID_URL = r'https?://tvthek\.orf\.at/(?:[^/]+/)+(?P<id>\d+)'
  24. _TESTS = [{
  25. 'url': 'http://tvthek.orf.at/program/Aufgetischt/2745173/Aufgetischt-Mit-der-Steirischen-Tafelrunde/8891389',
  26. 'playlist': [{
  27. 'md5': '2942210346ed779588f428a92db88712',
  28. 'info_dict': {
  29. 'id': '8896777',
  30. 'ext': 'mp4',
  31. 'title': 'Aufgetischt: Mit der Steirischen Tafelrunde',
  32. 'description': 'md5:c1272f0245537812d4e36419c207b67d',
  33. 'duration': 2668,
  34. 'upload_date': '20141208',
  35. },
  36. }],
  37. 'skip': 'Blocked outside of Austria / Germany',
  38. }, {
  39. 'url': 'http://tvthek.orf.at/topic/Im-Wandel-der-Zeit/8002126/Best-of-Ingrid-Thurnher/7982256',
  40. 'info_dict': {
  41. 'id': '7982259',
  42. 'ext': 'mp4',
  43. 'title': 'Best of Ingrid Thurnher',
  44. 'upload_date': '20140527',
  45. 'description': 'Viele Jahre war Ingrid Thurnher das "Gesicht" der ZIB 2. Vor ihrem Wechsel zur ZIB 2 im Jahr 1995 moderierte sie unter anderem "Land und Leute", "Österreich-Bild" und "Niederösterreich heute".',
  46. },
  47. 'params': {
  48. 'skip_download': True, # rtsp downloads
  49. },
  50. 'skip': 'Blocked outside of Austria / Germany',
  51. }, {
  52. 'url': 'http://tvthek.orf.at/topic/Fluechtlingskrise/10463081/Heimat-Fremde-Heimat/13879132/Senioren-betreuen-Migrantenkinder/13879141',
  53. 'only_matching': True,
  54. }, {
  55. 'url': 'http://tvthek.orf.at/profile/Universum/35429',
  56. 'only_matching': True,
  57. }]
  58. def _real_extract(self, url):
  59. playlist_id = self._match_id(url)
  60. webpage = self._download_webpage(url, playlist_id)
  61. data_jsb = self._parse_json(
  62. self._search_regex(
  63. r'<div[^>]+class=(["\']).*?VideoPlaylist.*?\1[^>]+data-jsb=(["\'])(?P<json>.+?)\2',
  64. webpage, 'playlist', group='json'),
  65. playlist_id, transform_source=unescapeHTML)['playlist']['videos']
  66. entries = []
  67. for sd in data_jsb:
  68. video_id, title = sd.get('id'), sd.get('title')
  69. if not video_id or not title:
  70. continue
  71. video_id = compat_str(video_id)
  72. formats = []
  73. for fd in sd['sources']:
  74. src = url_or_none(fd.get('src'))
  75. if not src:
  76. continue
  77. format_id_list = []
  78. for key in ('delivery', 'quality', 'quality_string'):
  79. value = fd.get(key)
  80. if value:
  81. format_id_list.append(value)
  82. format_id = '-'.join(format_id_list)
  83. ext = determine_ext(src)
  84. if ext == 'm3u8':
  85. m3u8_formats = self._extract_m3u8_formats(
  86. src, video_id, 'mp4', m3u8_id=format_id, fatal=False)
  87. if any('/geoprotection' in f['url'] for f in m3u8_formats):
  88. self.raise_geo_restricted()
  89. formats.extend(m3u8_formats)
  90. elif ext == 'f4m':
  91. formats.extend(self._extract_f4m_formats(
  92. src, video_id, f4m_id=format_id, fatal=False))
  93. elif ext == 'mpd':
  94. formats.extend(self._extract_mpd_formats(
  95. src, video_id, mpd_id=format_id, fatal=False))
  96. else:
  97. formats.append({
  98. 'format_id': format_id,
  99. 'url': src,
  100. 'protocol': fd.get('protocol'),
  101. })
  102. # Check for geoblocking.
  103. # There is a property is_geoprotection, but that's always false
  104. geo_str = sd.get('geoprotection_string')
  105. if geo_str:
  106. try:
  107. http_url = next(
  108. f['url']
  109. for f in formats
  110. if re.match(r'^https?://.*\.mp4$', f['url']))
  111. except StopIteration:
  112. pass
  113. else:
  114. req = HEADRequest(http_url)
  115. self._request_webpage(
  116. req, video_id,
  117. note='Testing for geoblocking',
  118. errnote=((
  119. 'This video seems to be blocked outside of %s. '
  120. 'You may want to try the streaming-* formats.')
  121. % geo_str),
  122. fatal=False)
  123. self._check_formats(formats, video_id)
  124. self._sort_formats(formats)
  125. subtitles = {}
  126. for sub in sd.get('subtitles', []):
  127. sub_src = sub.get('src')
  128. if not sub_src:
  129. continue
  130. subtitles.setdefault(sub.get('lang', 'de-AT'), []).append({
  131. 'url': sub_src,
  132. })
  133. upload_date = unified_strdate(sd.get('created_date'))
  134. thumbnails = []
  135. preview = sd.get('preview_image_url')
  136. if preview:
  137. thumbnails.append({
  138. 'id': 'preview',
  139. 'url': preview,
  140. 'preference': 0,
  141. })
  142. image = sd.get('image_full_url')
  143. if not image and len(data_jsb) == 1:
  144. image = self._og_search_thumbnail(webpage)
  145. if image:
  146. thumbnails.append({
  147. 'id': 'full',
  148. 'url': image,
  149. 'preference': 1,
  150. })
  151. entries.append({
  152. '_type': 'video',
  153. 'id': video_id,
  154. 'title': title,
  155. 'formats': formats,
  156. 'subtitles': subtitles,
  157. 'description': sd.get('description'),
  158. 'duration': int_or_none(sd.get('duration_in_seconds')),
  159. 'upload_date': upload_date,
  160. 'thumbnails': thumbnails,
  161. })
  162. return {
  163. '_type': 'playlist',
  164. 'entries': entries,
  165. 'id': playlist_id,
  166. }
  167. class ORFRadioIE(InfoExtractor):
  168. def _real_extract(self, url):
  169. mobj = re.match(self._VALID_URL, url)
  170. show_date = mobj.group('date')
  171. show_id = mobj.group('show')
  172. data = self._download_json(
  173. 'http://audioapi.orf.at/%s/api/json/current/broadcast/%s/%s'
  174. % (self._API_STATION, show_id, show_date), show_id)
  175. entries = []
  176. for info in data['streams']:
  177. loop_stream_id = str_or_none(info.get('loopStreamId'))
  178. if not loop_stream_id:
  179. continue
  180. title = str_or_none(data.get('title'))
  181. if not title:
  182. continue
  183. start = int_or_none(info.get('start'), scale=1000)
  184. end = int_or_none(info.get('end'), scale=1000)
  185. duration = end - start if end and start else None
  186. entries.append({
  187. 'id': loop_stream_id.replace('.mp3', ''),
  188. 'url': 'https://loopstream01.apa.at/?channel=%s&id=%s' % (self._LOOP_STATION, loop_stream_id),
  189. 'title': title,
  190. 'description': clean_html(data.get('subtitle')),
  191. 'duration': duration,
  192. 'timestamp': start,
  193. 'ext': 'mp3',
  194. 'series': data.get('programTitle'),
  195. })
  196. return {
  197. '_type': 'playlist',
  198. 'id': show_id,
  199. 'title': data.get('title'),
  200. 'description': clean_html(data.get('subtitle')),
  201. 'entries': entries,
  202. }
  203. class ORFFM4IE(ORFRadioIE):
  204. IE_NAME = 'orf:fm4'
  205. IE_DESC = 'radio FM4'
  206. _VALID_URL = r'https?://(?P<station>fm4)\.orf\.at/player/(?P<date>[0-9]+)/(?P<show>4\w+)'
  207. _API_STATION = 'fm4'
  208. _LOOP_STATION = 'fm4'
  209. _TEST = {
  210. 'url': 'http://fm4.orf.at/player/20170107/4CC',
  211. 'md5': '2b0be47375432a7ef104453432a19212',
  212. 'info_dict': {
  213. 'id': '2017-01-07_2100_tl_54_7DaysSat18_31295',
  214. 'ext': 'mp3',
  215. 'title': 'Solid Steel Radioshow',
  216. 'description': 'Die Mixshow von Coldcut und Ninja Tune.',
  217. 'duration': 3599,
  218. 'timestamp': 1483819257,
  219. 'upload_date': '20170107',
  220. },
  221. 'skip': 'Shows from ORF radios are only available for 7 days.',
  222. 'only_matching': True,
  223. }
  224. class ORFNOEIE(ORFRadioIE):
  225. IE_NAME = 'orf:noe'
  226. IE_DESC = 'Radio Niederösterreich'
  227. _VALID_URL = r'https?://(?P<station>noe)\.orf\.at/player/(?P<date>[0-9]+)/(?P<show>\w+)'
  228. _API_STATION = 'noe'
  229. _LOOP_STATION = 'oe2n'
  230. _TEST = {
  231. 'url': 'https://noe.orf.at/player/20200423/NGM',
  232. 'only_matching': True,
  233. }
  234. class ORFWIEIE(ORFRadioIE):
  235. IE_NAME = 'orf:wien'
  236. IE_DESC = 'Radio Wien'
  237. _VALID_URL = r'https?://(?P<station>wien)\.orf\.at/player/(?P<date>[0-9]+)/(?P<show>\w+)'
  238. _API_STATION = 'wie'
  239. _LOOP_STATION = 'oe2w'
  240. _TEST = {
  241. 'url': 'https://wien.orf.at/player/20200423/WGUM',
  242. 'only_matching': True,
  243. }
  244. class ORFBGLIE(ORFRadioIE):
  245. IE_NAME = 'orf:burgenland'
  246. IE_DESC = 'Radio Burgenland'
  247. _VALID_URL = r'https?://(?P<station>burgenland)\.orf\.at/player/(?P<date>[0-9]+)/(?P<show>\w+)'
  248. _API_STATION = 'bgl'
  249. _LOOP_STATION = 'oe2b'
  250. _TEST = {
  251. 'url': 'https://burgenland.orf.at/player/20200423/BGM',
  252. 'only_matching': True,
  253. }
  254. class ORFOOEIE(ORFRadioIE):
  255. IE_NAME = 'orf:oberoesterreich'
  256. IE_DESC = 'Radio Oberösterreich'
  257. _VALID_URL = r'https?://(?P<station>ooe)\.orf\.at/player/(?P<date>[0-9]+)/(?P<show>\w+)'
  258. _API_STATION = 'ooe'
  259. _LOOP_STATION = 'oe2o'
  260. _TEST = {
  261. 'url': 'https://ooe.orf.at/player/20200423/OGMO',
  262. 'only_matching': True,
  263. }
  264. class ORFSTMIE(ORFRadioIE):
  265. IE_NAME = 'orf:steiermark'
  266. IE_DESC = 'Radio Steiermark'
  267. _VALID_URL = r'https?://(?P<station>steiermark)\.orf\.at/player/(?P<date>[0-9]+)/(?P<show>\w+)'
  268. _API_STATION = 'stm'
  269. _LOOP_STATION = 'oe2st'
  270. _TEST = {
  271. 'url': 'https://steiermark.orf.at/player/20200423/STGMS',
  272. 'only_matching': True,
  273. }
  274. class ORFKTNIE(ORFRadioIE):
  275. IE_NAME = 'orf:kaernten'
  276. IE_DESC = 'Radio Kärnten'
  277. _VALID_URL = r'https?://(?P<station>kaernten)\.orf\.at/player/(?P<date>[0-9]+)/(?P<show>\w+)'
  278. _API_STATION = 'ktn'
  279. _LOOP_STATION = 'oe2k'
  280. _TEST = {
  281. 'url': 'https://kaernten.orf.at/player/20200423/KGUMO',
  282. 'only_matching': True,
  283. }
  284. class ORFSBGIE(ORFRadioIE):
  285. IE_NAME = 'orf:salzburg'
  286. IE_DESC = 'Radio Salzburg'
  287. _VALID_URL = r'https?://(?P<station>salzburg)\.orf\.at/player/(?P<date>[0-9]+)/(?P<show>\w+)'
  288. _API_STATION = 'sbg'
  289. _LOOP_STATION = 'oe2s'
  290. _TEST = {
  291. 'url': 'https://salzburg.orf.at/player/20200423/SGUM',
  292. 'only_matching': True,
  293. }
  294. class ORFTIRIE(ORFRadioIE):
  295. IE_NAME = 'orf:tirol'
  296. IE_DESC = 'Radio Tirol'
  297. _VALID_URL = r'https?://(?P<station>tirol)\.orf\.at/player/(?P<date>[0-9]+)/(?P<show>\w+)'
  298. _API_STATION = 'tir'
  299. _LOOP_STATION = 'oe2t'
  300. _TEST = {
  301. 'url': 'https://tirol.orf.at/player/20200423/TGUMO',
  302. 'only_matching': True,
  303. }
  304. class ORFVBGIE(ORFRadioIE):
  305. IE_NAME = 'orf:vorarlberg'
  306. IE_DESC = 'Radio Vorarlberg'
  307. _VALID_URL = r'https?://(?P<station>vorarlberg)\.orf\.at/player/(?P<date>[0-9]+)/(?P<show>\w+)'
  308. _API_STATION = 'vbg'
  309. _LOOP_STATION = 'oe2v'
  310. _TEST = {
  311. 'url': 'https://vorarlberg.orf.at/player/20200423/VGUM',
  312. 'only_matching': True,
  313. }
  314. class ORFOE3IE(ORFRadioIE):
  315. IE_NAME = 'orf:oe3'
  316. IE_DESC = 'Radio Österreich 3'
  317. _VALID_URL = r'https?://(?P<station>oe3)\.orf\.at/player/(?P<date>[0-9]+)/(?P<show>\w+)'
  318. _API_STATION = 'oe3'
  319. _LOOP_STATION = 'oe3'
  320. _TEST = {
  321. 'url': 'https://oe3.orf.at/player/20200424/3WEK',
  322. 'only_matching': True,
  323. }
  324. class ORFOE1IE(ORFRadioIE):
  325. IE_NAME = 'orf:oe1'
  326. IE_DESC = 'Radio Österreich 1'
  327. _VALID_URL = r'https?://(?P<station>oe1)\.orf\.at/player/(?P<date>[0-9]+)/(?P<show>\w+)'
  328. _API_STATION = 'oe1'
  329. _LOOP_STATION = 'oe1'
  330. _TEST = {
  331. 'url': 'http://oe1.orf.at/player/20170108/456544',
  332. 'md5': '34d8a6e67ea888293741c86a099b745b',
  333. 'info_dict': {
  334. 'id': '2017-01-08_0759_tl_51_7DaysSun6_256141',
  335. 'ext': 'mp3',
  336. 'title': 'Morgenjournal',
  337. 'duration': 609,
  338. 'timestamp': 1483858796,
  339. 'upload_date': '20170108',
  340. },
  341. 'skip': 'Shows from ORF radios are only available for 7 days.'
  342. }
  343. class ORFIPTVIE(InfoExtractor):
  344. IE_NAME = 'orf:iptv'
  345. IE_DESC = 'iptv.ORF.at'
  346. _VALID_URL = r'https?://iptv\.orf\.at/(?:#/)?stories/(?P<id>\d+)'
  347. _TEST = {
  348. 'url': 'http://iptv.orf.at/stories/2275236/',
  349. 'md5': 'c8b22af4718a4b4af58342529453e3e5',
  350. 'info_dict': {
  351. 'id': '350612',
  352. 'ext': 'flv',
  353. 'title': 'Weitere Evakuierungen um Vulkan Calbuco',
  354. 'description': 'md5:d689c959bdbcf04efeddedbf2299d633',
  355. 'duration': 68.197,
  356. 'thumbnail': r're:^https?://.*\.jpg$',
  357. 'upload_date': '20150425',
  358. },
  359. }
  360. def _real_extract(self, url):
  361. story_id = self._match_id(url)
  362. webpage = self._download_webpage(
  363. 'http://iptv.orf.at/stories/%s' % story_id, story_id)
  364. video_id = self._search_regex(
  365. r'data-video(?:id)?="(\d+)"', webpage, 'video id')
  366. data = self._download_json(
  367. 'http://bits.orf.at/filehandler/static-api/json/current/data.json?file=%s' % video_id,
  368. video_id)[0]
  369. duration = float_or_none(data['duration'], 1000)
  370. video = data['sources']['default']
  371. load_balancer_url = video['loadBalancerUrl']
  372. abr = int_or_none(video.get('audioBitrate'))
  373. vbr = int_or_none(video.get('bitrate'))
  374. fps = int_or_none(video.get('videoFps'))
  375. width = int_or_none(video.get('videoWidth'))
  376. height = int_or_none(video.get('videoHeight'))
  377. thumbnail = video.get('preview')
  378. rendition = self._download_json(
  379. load_balancer_url, video_id, transform_source=strip_jsonp)
  380. f = {
  381. 'abr': abr,
  382. 'vbr': vbr,
  383. 'fps': fps,
  384. 'width': width,
  385. 'height': height,
  386. }
  387. formats = []
  388. for format_id, format_url in rendition['redirect'].items():
  389. if format_id == 'rtmp':
  390. ff = f.copy()
  391. ff.update({
  392. 'url': format_url,
  393. 'format_id': format_id,
  394. })
  395. formats.append(ff)
  396. elif determine_ext(format_url) == 'f4m':
  397. formats.extend(self._extract_f4m_formats(
  398. format_url, video_id, f4m_id=format_id))
  399. elif determine_ext(format_url) == 'm3u8':
  400. formats.extend(self._extract_m3u8_formats(
  401. format_url, video_id, 'mp4', m3u8_id=format_id))
  402. else:
  403. continue
  404. self._sort_formats(formats)
  405. title = remove_end(self._og_search_title(webpage), ' - iptv.ORF.at')
  406. description = self._og_search_description(webpage)
  407. upload_date = unified_strdate(self._html_search_meta(
  408. 'dc.date', webpage, 'upload date'))
  409. return {
  410. 'id': video_id,
  411. 'title': title,
  412. 'description': description,
  413. 'duration': duration,
  414. 'thumbnail': thumbnail,
  415. 'upload_date': upload_date,
  416. 'formats': formats,
  417. }
  418. class ORFFM4StoryIE(InfoExtractor):
  419. IE_NAME = 'orf:fm4:story'
  420. IE_DESC = 'fm4.orf.at stories'
  421. _VALID_URL = r'https?://fm4\.orf\.at/stories/(?P<id>\d+)'
  422. _TEST = {
  423. 'url': 'http://fm4.orf.at/stories/2865738/',
  424. 'playlist': [{
  425. 'md5': 'e1c2c706c45c7b34cf478bbf409907ca',
  426. 'info_dict': {
  427. 'id': '547792',
  428. 'ext': 'flv',
  429. 'title': 'Manu Delago und Inner Tongue live',
  430. 'description': 'Manu Delago und Inner Tongue haben bei der FM4 Soundpark Session live alles gegeben. Hier gibt es Fotos und die gesamte Session als Video.',
  431. 'duration': 1748.52,
  432. 'thumbnail': r're:^https?://.*\.jpg$',
  433. 'upload_date': '20170913',
  434. },
  435. }, {
  436. 'md5': 'c6dd2179731f86f4f55a7b49899d515f',
  437. 'info_dict': {
  438. 'id': '547798',
  439. 'ext': 'flv',
  440. 'title': 'Manu Delago und Inner Tongue live (2)',
  441. 'duration': 1504.08,
  442. 'thumbnail': r're:^https?://.*\.jpg$',
  443. 'upload_date': '20170913',
  444. 'description': 'Manu Delago und Inner Tongue haben bei der FM4 Soundpark Session live alles gegeben. Hier gibt es Fotos und die gesamte Session als Video.',
  445. },
  446. }],
  447. }
  448. def _real_extract(self, url):
  449. story_id = self._match_id(url)
  450. webpage = self._download_webpage(url, story_id)
  451. entries = []
  452. all_ids = orderedSet(re.findall(r'data-video(?:id)?="(\d+)"', webpage))
  453. for idx, video_id in enumerate(all_ids):
  454. data = self._download_json(
  455. 'http://bits.orf.at/filehandler/static-api/json/current/data.json?file=%s' % video_id,
  456. video_id)[0]
  457. duration = float_or_none(data['duration'], 1000)
  458. video = data['sources']['q8c']
  459. load_balancer_url = video['loadBalancerUrl']
  460. abr = int_or_none(video.get('audioBitrate'))
  461. vbr = int_or_none(video.get('bitrate'))
  462. fps = int_or_none(video.get('videoFps'))
  463. width = int_or_none(video.get('videoWidth'))
  464. height = int_or_none(video.get('videoHeight'))
  465. thumbnail = video.get('preview')
  466. rendition = self._download_json(
  467. load_balancer_url, video_id, transform_source=strip_jsonp)
  468. f = {
  469. 'abr': abr,
  470. 'vbr': vbr,
  471. 'fps': fps,
  472. 'width': width,
  473. 'height': height,
  474. }
  475. formats = []
  476. for format_id, format_url in rendition['redirect'].items():
  477. if format_id == 'rtmp':
  478. ff = f.copy()
  479. ff.update({
  480. 'url': format_url,
  481. 'format_id': format_id,
  482. })
  483. formats.append(ff)
  484. elif determine_ext(format_url) == 'f4m':
  485. formats.extend(self._extract_f4m_formats(
  486. format_url, video_id, f4m_id=format_id))
  487. elif determine_ext(format_url) == 'm3u8':
  488. formats.extend(self._extract_m3u8_formats(
  489. format_url, video_id, 'mp4', m3u8_id=format_id))
  490. else:
  491. continue
  492. self._sort_formats(formats)
  493. title = remove_end(self._og_search_title(webpage), ' - fm4.ORF.at')
  494. if idx >= 1:
  495. # Titles are duplicates, make them unique
  496. title += ' (' + str(idx + 1) + ')'
  497. description = self._og_search_description(webpage)
  498. upload_date = unified_strdate(self._html_search_meta(
  499. 'dc.date', webpage, 'upload date'))
  500. entries.append({
  501. 'id': video_id,
  502. 'title': title,
  503. 'description': description,
  504. 'duration': duration,
  505. 'thumbnail': thumbnail,
  506. 'upload_date': upload_date,
  507. 'formats': formats,
  508. })
  509. return self.playlist_result(entries)