logo

youtube-dl

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

orf.py (32195B)


  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import base64
  4. import functools
  5. import re
  6. from .common import InfoExtractor
  7. from .youtube import YoutubeIE
  8. from ..utils import (
  9. clean_html,
  10. determine_ext,
  11. ExtractorError,
  12. float_or_none,
  13. int_or_none,
  14. merge_dicts,
  15. mimetype2ext,
  16. parse_age_limit,
  17. parse_iso8601,
  18. strip_jsonp,
  19. txt_or_none,
  20. unified_strdate,
  21. update_url_query,
  22. url_or_none,
  23. )
  24. from ..traversal import T, traverse_obj
  25. k_float_or_none = functools.partial(float_or_none, scale=1000)
  26. class ORFRadioBase(InfoExtractor):
  27. STATION_INFO = {
  28. 'fm4': ('fm4', 'fm4', 'orffm4'),
  29. 'noe': ('noe', 'oe2n', 'orfnoe'),
  30. 'wien': ('wie', 'oe2w', 'orfwie'),
  31. 'burgenland': ('bgl', 'oe2b', 'orfbgl'),
  32. 'ooe': ('ooe', 'oe2o', 'orfooe'),
  33. 'steiermark': ('stm', 'oe2st', 'orfstm'),
  34. 'kaernten': ('ktn', 'oe2k', 'orfktn'),
  35. 'salzburg': ('sbg', 'oe2s', 'orfsbg'),
  36. 'tirol': ('tir', 'oe2t', 'orftir'),
  37. 'vorarlberg': ('vbg', 'oe2v', 'orfvbg'),
  38. 'oe3': ('oe3', 'oe3', 'orfoe3'),
  39. 'oe1': ('oe1', 'oe1', 'orfoe1'),
  40. }
  41. _ID_NAMES = ('id', 'guid', 'program')
  42. @classmethod
  43. def _get_item_id(cls, data):
  44. return traverse_obj(data, *cls._ID_NAMES, expected_type=txt_or_none)
  45. @classmethod
  46. def _get_api_payload(cls, data, expected_id, in_payload=False):
  47. if expected_id not in traverse_obj(data, ('payload',)[:1 if in_payload else 0] + (cls._ID_NAMES, T(txt_or_none))):
  48. raise ExtractorError('Unexpected API data result', video_id=expected_id)
  49. return data['payload']
  50. @staticmethod
  51. def _extract_podcast_upload(data):
  52. return traverse_obj(data, {
  53. 'url': ('enclosures', 0, 'url'),
  54. 'ext': ('enclosures', 0, 'type', T(mimetype2ext)),
  55. 'filesize': ('enclosures', 0, 'length', T(int_or_none)),
  56. 'title': ('title', T(txt_or_none)),
  57. 'description': ('description', T(clean_html)),
  58. 'timestamp': (('published', 'postDate'), T(parse_iso8601)),
  59. 'duration': ('duration', T(k_float_or_none)),
  60. 'series': ('podcast', 'title'),
  61. 'uploader': ((('podcast', 'author'), 'station'), T(txt_or_none)),
  62. 'uploader_id': ('podcast', 'channel', T(txt_or_none)),
  63. }, get_all=False)
  64. @classmethod
  65. def _entries(cls, data, station, item_type=None):
  66. if item_type in ('upload', 'podcast-episode'):
  67. yield merge_dicts({
  68. 'id': cls._get_item_id(data),
  69. 'ext': 'mp3',
  70. 'vcodec': 'none',
  71. }, cls._extract_podcast_upload(data), rev=True)
  72. return
  73. loop_station = cls.STATION_INFO[station][1]
  74. for info in traverse_obj(data, ((('streams', Ellipsis), 'stream'), T(lambda v: v if v['loopStreamId'] else None))):
  75. item_id = info['loopStreamId']
  76. host = info.get('host') or 'loopstream01.apa.at'
  77. yield merge_dicts({
  78. 'id': item_id.replace('.mp3', ''),
  79. 'ext': 'mp3',
  80. 'url': update_url_query('https://{0}/'.format(host), {
  81. 'channel': loop_station,
  82. 'id': item_id,
  83. }),
  84. 'vcodec': 'none',
  85. # '_old_archive_ids': [make_archive_id(old_ie, video_id)],
  86. }, traverse_obj(data, {
  87. 'title': ('title', T(txt_or_none)),
  88. 'description': ('subtitle', T(clean_html)),
  89. 'uploader': 'station',
  90. 'series': ('programTitle', T(txt_or_none)),
  91. }), traverse_obj(info, {
  92. 'duration': (('duration',
  93. (None, T(lambda x: x['end'] - x['start']))),
  94. T(k_float_or_none), any),
  95. 'timestamp': (('start', 'startISO'), T(parse_iso8601), any),
  96. }))
  97. class ORFRadioIE(ORFRadioBase):
  98. IE_NAME = 'orf:sound'
  99. _STATION_RE = '|'.join(map(re.escape, ORFRadioBase.STATION_INFO.keys()))
  100. _VALID_URL = (
  101. r'https?://sound\.orf\.at/radio/(?P<station>{0})/sendung/(?P<id>\d+)(?:/(?P<show>\w+))?'.format(_STATION_RE),
  102. r'https?://(?P<station>{0})\.orf\.at/player/(?P<date>\d{{8}})/(?P<id>\d+)'.format(_STATION_RE),
  103. )
  104. _TESTS = [{
  105. 'url': 'https://sound.orf.at/radio/ooe/sendung/37802/guten-morgen-oberoesterreich-am-feiertag',
  106. 'info_dict': {
  107. 'id': '37802',
  108. 'title': 'Guten Morgen Oberösterreich am Feiertag',
  109. 'description': 'Oberösterreichs meistgehörte regionale Frühsendung.\nRegionale Nachrichten zu jeder halben Stunde.\nModeration: Wolfgang Lehner\nNachrichten: Stephan Schnabl',
  110. },
  111. 'playlist': [{
  112. 'md5': 'f9ff8517dd681b642a2c900e2c9e6085',
  113. 'info_dict': {
  114. 'id': '2024-05-30_0559_tl_66_7DaysThu1_443862',
  115. 'ext': 'mp3',
  116. 'title': 'Guten Morgen Oberösterreich am Feiertag',
  117. 'description': 'Oberösterreichs meistgehörte regionale Frühsendung.\nRegionale Nachrichten zu jeder halben Stunde.\nModeration: Wolfgang Lehner\nNachrichten: Stephan Schnabl',
  118. 'timestamp': 1717041587,
  119. 'upload_date': '20240530',
  120. 'uploader': 'ooe',
  121. 'duration': 14413.0,
  122. }
  123. }],
  124. 'skip': 'Shows from ORF Sound are only available for 30 days.'
  125. }, {
  126. 'url': 'https://oe1.orf.at/player/20240531/758136',
  127. 'md5': '2397717aaf3ae9c22a4f090ee3b8d374',
  128. 'info_dict': {
  129. 'id': '2024-05-31_1905_tl_51_7DaysFri35_2413387',
  130. 'ext': 'mp3',
  131. 'title': '"Who Cares?"',
  132. 'description': 'Europas größte Netzkonferenz re:publica 2024',
  133. 'timestamp': 1717175100,
  134. 'upload_date': '20240531',
  135. 'uploader': 'oe1',
  136. 'duration': 1500,
  137. },
  138. 'skip': 'Shows from ORF Sound are only available for 30 days.'
  139. }]
  140. def _real_extract(self, url):
  141. m = self._match_valid_url(url)
  142. station, show_id = m.group('station', 'id')
  143. api_station, _, _ = self.STATION_INFO[station]
  144. if 'date' in m.groupdict():
  145. data = self._download_json(
  146. 'https://audioapi.orf.at/{0}/json/4.0/broadcast/{1}/{2}?_o={3}.orf.at'.format(
  147. api_station, show_id, m.group('date'), station), show_id)
  148. show_id = data['id']
  149. else:
  150. data = self._download_json(
  151. 'https://audioapi.orf.at/{0}/api/json/5.0/broadcast/{1}?_o=sound.orf.at'.format(
  152. api_station, show_id), show_id)
  153. data = self._get_api_payload(data, show_id, in_payload=True)
  154. # site sends ISO8601 GMT date-times with separate TZ offset, ignored
  155. # TODO: should `..._date` be calculated relative to TZ?
  156. return merge_dicts(
  157. {'_type': 'multi_video'},
  158. self.playlist_result(
  159. self._entries(data, station), show_id,
  160. txt_or_none(data.get('title')),
  161. clean_html(data.get('subtitle'))))
  162. class ORFRadioCollectionIE(ORFRadioBase):
  163. IE_NAME = 'orf:collection'
  164. _VALID_URL = r'https?://sound\.orf\.at/collection/(?P<coll_id>\d+)(?:/(?P<item_id>\d+))?'
  165. _TESTS = [{
  166. 'url': 'https://sound.orf.at/collection/4/61908/was-das-uberschreiten-des-15-limits-bedeutet',
  167. 'info_dict': {
  168. 'id': '2577582',
  169. },
  170. 'playlist': [{
  171. 'md5': '5789cec7d75575ff58d19c0428c80eb3',
  172. 'info_dict': {
  173. 'id': '2024-06-06_1659_tl_54_7DaysThu6_153926',
  174. 'ext': 'mp3',
  175. 'title': 'Klimakrise: Was das Überschreiten des 1,5°-Limits bedeutet',
  176. 'timestamp': 1717686674,
  177. 'upload_date': '20240606',
  178. 'uploader': 'fm4',
  179. },
  180. }],
  181. 'skip': 'Shows from ORF Sound are only available for 30 days.'
  182. }, {
  183. # persistent playlist (FM4 Highlights)
  184. 'url': 'https://sound.orf.at/collection/4/',
  185. 'info_dict': {
  186. 'id': '4',
  187. },
  188. 'playlist_mincount': 10,
  189. 'playlist_maxcount': 13,
  190. }]
  191. def _real_extract(self, url):
  192. coll_id, item_id = self._match_valid_url(url).group('coll_id', 'item_id')
  193. data = self._download_json(
  194. 'https://collector.orf.at/api/frontend/collections/{0}?_o=sound.orf.at'.format(
  195. coll_id), coll_id)
  196. data = self._get_api_payload(data, coll_id, in_payload=True)
  197. def yield_items():
  198. for item in traverse_obj(data, (
  199. 'content', 'items', lambda _, v: any(k in v['target']['params'] for k in self._ID_NAMES))):
  200. if item_id is None or item_id == txt_or_none(item.get('id')):
  201. target = item['target']
  202. typed_item_id = self._get_item_id(target['params'])
  203. station = target['params'].get('station')
  204. item_type = target.get('type')
  205. if typed_item_id and (station or item_type):
  206. yield station, typed_item_id, item_type
  207. if item_id is not None:
  208. break
  209. else:
  210. if item_id is not None:
  211. raise ExtractorError('Item not found in collection',
  212. video_id=coll_id, expected=True)
  213. def item_playlist(station, typed_item_id, item_type):
  214. if item_type == 'upload':
  215. item_data = self._download_json('https://audioapi.orf.at/radiothek/api/2.0/upload/{0}?_o=sound.orf.at'.format(
  216. typed_item_id), typed_item_id)
  217. elif item_type == 'podcast-episode':
  218. item_data = self._download_json('https://audioapi.orf.at/radiothek/api/2.0/episode/{0}?_o=sound.orf.at'.format(
  219. typed_item_id), typed_item_id)
  220. else:
  221. api_station, _, _ = self.STATION_INFO[station]
  222. item_data = self._download_json(
  223. 'https://audioapi.orf.at/{0}/api/json/5.0/{1}/{2}?_o=sound.orf.at'.format(
  224. api_station, item_type or 'broadcastitem', typed_item_id), typed_item_id)
  225. item_data = self._get_api_payload(item_data, typed_item_id, in_payload=True)
  226. return merge_dicts(
  227. {'_type': 'multi_video'},
  228. self.playlist_result(
  229. self._entries(item_data, station, item_type), typed_item_id,
  230. txt_or_none(data.get('title')),
  231. clean_html(data.get('subtitle'))))
  232. def yield_item_entries():
  233. for station, typed_id, item_type in yield_items():
  234. yield item_playlist(station, typed_id, item_type)
  235. if item_id is not None:
  236. # coll_id = '/'.join((coll_id, item_id))
  237. return next(yield_item_entries())
  238. return self.playlist_result(yield_item_entries(), coll_id, data.get('title'))
  239. class ORFPodcastIE(ORFRadioBase):
  240. IE_NAME = 'orf:podcast'
  241. _STATION_RE = '|'.join(map(re.escape, (x[0] for x in ORFRadioBase.STATION_INFO.values()))) + '|tv'
  242. _VALID_URL = r'https?://sound\.orf\.at/podcast/(?P<station>{0})/(?P<show>[\w-]+)/(?P<id>[\w-]+)'.format(_STATION_RE)
  243. _TESTS = [{
  244. 'url': 'https://sound.orf.at/podcast/stm/der-kraeutertipp-von-christine-lackner/rotklee',
  245. 'md5': '1f2bab2ba90c2ce0c2754196ea78b35f',
  246. 'info_dict': {
  247. 'id': 'der-kraeutertipp-von-christine-lackner/rotklee',
  248. 'ext': 'mp3',
  249. 'title': 'Rotklee',
  250. 'description': 'In der Natur weit verbreitet - in der Medizin längst anerkennt: Rotklee. Dieser Podcast begleitet die Sendung "Radio Steiermark am Vormittag", Radio Steiermark, 28. Mai 2024.',
  251. 'timestamp': 1716891761,
  252. 'upload_date': '20240528',
  253. 'uploader_id': 'stm_kraeutertipp',
  254. 'uploader': 'ORF Radio Steiermark',
  255. 'duration': 101,
  256. 'series': 'Der Kräutertipp von Christine Lackner',
  257. },
  258. 'skip': 'ORF podcasts are only available for a limited time'
  259. }]
  260. _ID_NAMES = ('slug', 'guid')
  261. def _real_extract(self, url):
  262. station, show, show_id = self._match_valid_url(url).group('station', 'show', 'id')
  263. data = self._download_json(
  264. 'https://audioapi.orf.at/radiothek/api/2.0/podcast/{0}/{1}/{2}'.format(
  265. station, show, show_id), show_id)
  266. data = self._get_api_payload(data, show_id, in_payload=True)
  267. return merge_dicts({
  268. 'id': '/'.join((show, show_id)),
  269. 'ext': 'mp3',
  270. 'vcodec': 'none',
  271. }, self._extract_podcast_upload(data), rev=True)
  272. class ORFIPTVBase(InfoExtractor):
  273. _TITLE_STRIP_RE = ''
  274. def _extract_video(self, video_id, webpage, fatal=False):
  275. data = self._download_json(
  276. 'http://bits.orf.at/filehandler/static-api/json/current/data.json?file=%s' % video_id,
  277. video_id)[0]
  278. video = traverse_obj(data, (
  279. 'sources', ('default', 'q8c'),
  280. T(lambda x: x if x['loadBalancerUrl'] else None),
  281. any))
  282. load_balancer_url = video['loadBalancerUrl']
  283. try:
  284. rendition = self._download_json(
  285. load_balancer_url, video_id, transform_source=strip_jsonp)
  286. except ExtractorError:
  287. rendition = None
  288. if not rendition:
  289. rendition = {
  290. 'redirect': {
  291. 'smil': re.sub(
  292. r'(/)jsonp(/.+\.)mp4$', r'\1dash\2smil/manifest.mpd',
  293. load_balancer_url),
  294. },
  295. }
  296. f = traverse_obj(video, {
  297. 'abr': ('audioBitrate', T(int_or_none)),
  298. 'vbr': ('bitrate', T(int_or_none)),
  299. 'fps': ('videoFps', T(int_or_none)),
  300. 'width': ('videoWidth', T(int_or_none)),
  301. 'height': ('videoHeight', T(int_or_none)),
  302. })
  303. formats = []
  304. for format_id, format_url in traverse_obj(rendition, (
  305. 'redirect', T(dict.items), Ellipsis)):
  306. if format_id == 'rtmp':
  307. ff = f.copy()
  308. ff.update({
  309. 'url': format_url,
  310. 'format_id': format_id,
  311. })
  312. formats.append(ff)
  313. elif determine_ext(format_url) == 'f4m':
  314. formats.extend(self._extract_f4m_formats(
  315. format_url, video_id, f4m_id=format_id))
  316. elif determine_ext(format_url) == 'm3u8':
  317. formats.extend(self._extract_m3u8_formats(
  318. format_url, video_id, 'mp4', m3u8_id=format_id,
  319. entry_protocol='m3u8_native'))
  320. elif determine_ext(format_url) == 'mpd':
  321. formats.extend(self._extract_mpd_formats(
  322. format_url, video_id, mpd_id=format_id))
  323. if formats or fatal:
  324. self._sort_formats(formats)
  325. else:
  326. return
  327. return merge_dicts({
  328. 'id': video_id,
  329. 'title': re.sub(self._TITLE_STRIP_RE, '', self._og_search_title(webpage)),
  330. 'description': self._og_search_description(webpage),
  331. 'upload_date': unified_strdate(self._html_search_meta(
  332. 'dc.date', webpage, 'upload date', fatal=False)),
  333. 'formats': formats,
  334. }, traverse_obj(data, {
  335. 'duration': ('duration', T(k_float_or_none)),
  336. 'thumbnail': ('sources', 'default', 'preview', T(url_or_none)),
  337. }), rev=True)
  338. class ORFIPTVIE(ORFIPTVBase):
  339. IE_NAME = 'orf:iptv'
  340. IE_DESC = 'iptv.ORF.at'
  341. _WORKING = False # URLs redirect to orf.at/
  342. _VALID_URL = r'https?://iptv\.orf\.at/(?:#/)?stories/(?P<id>\d+)'
  343. _TITLE_STRIP_RE = r'\s+-\s+iptv\.ORF\.at\S*$'
  344. _TEST = {
  345. 'url': 'http://iptv.orf.at/stories/2275236/',
  346. 'md5': 'c8b22af4718a4b4af58342529453e3e5',
  347. 'info_dict': {
  348. 'id': '350612',
  349. 'ext': 'flv',
  350. 'title': 'Weitere Evakuierungen um Vulkan Calbuco',
  351. 'description': 'md5:d689c959bdbcf04efeddedbf2299d633',
  352. 'duration': 68.197,
  353. 'thumbnail': r're:^https?://.*\.jpg$',
  354. 'upload_date': '20150425',
  355. },
  356. }
  357. def _real_extract(self, url):
  358. story_id = self._match_id(url)
  359. webpage = self._download_webpage(
  360. 'http://iptv.orf.at/stories/%s' % story_id, story_id)
  361. video_id = self._search_regex(
  362. r'data-video(?:id)?="(\d+)"', webpage, 'video id')
  363. return self._extract_video(video_id, webpage)
  364. class ORFFM4StoryIE(ORFIPTVBase):
  365. IE_NAME = 'orf:fm4:story'
  366. IE_DESC = 'fm4.orf.at stories'
  367. _VALID_URL = r'https?://fm4\.orf\.at/stories/(?P<id>\d+)'
  368. _TITLE_STRIP_RE = r'\s+-\s+fm4\.ORF\.at\s*$'
  369. _TESTS = [{
  370. 'url': 'https://fm4.orf.at/stories/3041554/',
  371. 'add_ie': ['Youtube'],
  372. 'info_dict': {
  373. 'id': '3041554',
  374. 'title': 'Is The EU Green Deal In Mortal Danger?',
  375. },
  376. 'playlist_count': 4,
  377. 'params': {
  378. 'format': 'bestvideo',
  379. },
  380. }, {
  381. 'url': 'http://fm4.orf.at/stories/2865738/',
  382. 'info_dict': {
  383. 'id': '2865738',
  384. 'title': 'Manu Delago und Inner Tongue live',
  385. },
  386. 'playlist': [{
  387. 'md5': 'e1c2c706c45c7b34cf478bbf409907ca',
  388. 'info_dict': {
  389. 'id': '547792',
  390. 'ext': 'flv',
  391. 'title': 'Manu Delago und Inner Tongue live',
  392. '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.',
  393. 'duration': 1748.52,
  394. 'thumbnail': r're:^https?://.*\.jpg$',
  395. 'upload_date': '20170913',
  396. },
  397. }, {
  398. 'md5': 'c6dd2179731f86f4f55a7b49899d515f',
  399. 'info_dict': {
  400. 'id': '547798',
  401. 'ext': 'flv',
  402. 'title': 'Manu Delago und Inner Tongue https://vod-ww.mdn.ors.at/cms-worldwide_episodes_nas/_definst_/nas/cms-worldwide_episodes/online/14228823_0005.smil/chunklist_b992000_vo.m3u8live (2)',
  403. 'duration': 1504.08,
  404. 'thumbnail': r're:^https?://.*\.jpg$',
  405. 'upload_date': '20170913',
  406. '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.',
  407. },
  408. }],
  409. 'skip': 'Videos gone',
  410. }]
  411. def _real_extract(self, url):
  412. story_id = self._match_id(url)
  413. webpage = self._download_webpage(url, story_id)
  414. entries = []
  415. seen_ids = set()
  416. for idx, video_id in enumerate(re.findall(r'data-video(?:id)?="(\d+)"', webpage)):
  417. if video_id in seen_ids:
  418. continue
  419. seen_ids.add(video_id)
  420. entry = self._extract_video(video_id, webpage, fatal=False)
  421. if not entry:
  422. continue
  423. if idx >= 1:
  424. # Titles are duplicates, make them unique
  425. entry['title'] = '%s (%d)' % (entry['title'], idx)
  426. entries.append(entry)
  427. seen_ids = set()
  428. for yt_id in re.findall(
  429. r'data-id\s*=\s*["\']([\w-]+)[^>]+\bclass\s*=\s*["\']youtube\b',
  430. webpage):
  431. if yt_id in seen_ids:
  432. continue
  433. seen_ids.add(yt_id)
  434. if YoutubeIE.suitable(yt_id):
  435. entries.append(self.url_result(yt_id, ie='Youtube', video_id=yt_id))
  436. return self.playlist_result(
  437. entries, story_id,
  438. re.sub(self._TITLE_STRIP_RE, '', self._og_search_title(webpage, default='') or None))
  439. class ORFONBase(InfoExtractor):
  440. _ENC_PFX = '3dSlfek03nsLKdj4Jsd'
  441. _API_PATH = 'episode'
  442. def _call_api(self, video_id, **kwargs):
  443. encrypted_id = base64.b64encode('{0}{1}'.format(
  444. self._ENC_PFX, video_id).encode('utf-8')).decode('ascii')
  445. return self._download_json(
  446. 'https://api-tvthek.orf.at/api/v4.3/public/{0}/encrypted/{1}'.format(
  447. self._API_PATH, encrypted_id),
  448. video_id, **kwargs)
  449. @classmethod
  450. def _parse_metadata(cls, api_json):
  451. return traverse_obj(api_json, {
  452. 'id': ('id', T(int), T(txt_or_none)),
  453. 'age_limit': ('age_classification', T(parse_age_limit)),
  454. 'duration': ((('exact_duration', T(k_float_or_none)),
  455. ('duration_second', T(float_or_none))),),
  456. 'title': (('title', 'headline'), T(txt_or_none)),
  457. 'description': (('description', 'teaser_text'), T(txt_or_none)),
  458. # 'media_type': ('video_type', T(txt_or_none)),
  459. 'thumbnail': ('_embedded', 'image', 'public_urls', 'highlight_teaser', 'url', T(url_or_none)),
  460. 'timestamp': (('date', 'episode_date'), T(parse_iso8601)),
  461. 'release_timestamp': ('release_date', T(parse_iso8601)),
  462. # 'modified_timestamp': ('updated_at', T(parse_iso8601)),
  463. }, get_all=False)
  464. def _extract_video(self, video_id, segment_id):
  465. # Not a segmented episode: return single video
  466. # Segmented episode without valid segment id: return entire playlist
  467. # Segmented episode with valid segment id and yes-playlist: return entire playlist
  468. # Segmented episode with valid segment id and no-playlist: return single video corresponding to segment id
  469. # If a multi_video playlist would be returned, but an unsegmented source exists, that source is chosen instead.
  470. api_json = self._call_api(video_id)
  471. if traverse_obj(api_json, 'is_drm_protected'):
  472. self.report_drm(video_id)
  473. # updates formats, subtitles
  474. def extract_sources(src_json, video_id):
  475. for manifest_type in traverse_obj(src_json, ('sources', T(dict.keys), Ellipsis)):
  476. for manifest_url in traverse_obj(src_json, ('sources', manifest_type, Ellipsis, 'src', T(url_or_none))):
  477. if manifest_type == 'hls':
  478. fmts, subs = self._extract_m3u8_formats(
  479. manifest_url, video_id, fatal=False, m3u8_id='hls',
  480. ext='mp4', entry_protocol='m3u8_native'), {}
  481. for f in fmts:
  482. if '_vo.' in f['url']:
  483. f['acodec'] = 'none'
  484. elif manifest_type == 'dash':
  485. fmts, subs = self._extract_mpd_formats_and_subtitles(
  486. manifest_url, video_id, fatal=False, mpd_id='dash')
  487. else:
  488. continue
  489. formats.extend(fmts)
  490. self._merge_subtitles(subs, target=subtitles)
  491. formats, subtitles = [], {}
  492. if segment_id is None:
  493. extract_sources(api_json, video_id)
  494. if not formats:
  495. segments = traverse_obj(api_json, (
  496. '_embedded', 'segments', lambda _, v: v['id']))
  497. if len(segments) > 1 and segment_id is not None:
  498. if not self._yes_playlist(video_id, segment_id, playlist_label='collection', video_label='segment'):
  499. segments = [next(s for s in segments if txt_or_none(s['id']) == segment_id)]
  500. entries = []
  501. for seg in segments:
  502. formats, subtitles = [], {}
  503. extract_sources(seg, segment_id)
  504. self._sort_formats(formats)
  505. entries.append(merge_dicts({
  506. 'formats': formats,
  507. 'subtitles': subtitles,
  508. }, self._parse_metadata(seg), rev=True))
  509. result = merge_dicts(
  510. {'_type': 'multi_video' if len(entries) > 1 else 'playlist'},
  511. self._parse_metadata(api_json),
  512. self.playlist_result(entries, video_id))
  513. # not yet processed in core for playlist/multi
  514. self._downloader._fill_common_fields(result)
  515. return result
  516. else:
  517. self._sort_formats(formats)
  518. for sub_url in traverse_obj(api_json, (
  519. '_embedded', 'subtitle',
  520. ('xml_url', 'sami_url', 'stl_url', 'ttml_url', 'srt_url', 'vtt_url'),
  521. T(url_or_none))):
  522. self._merge_subtitles({'de': [{'url': sub_url}]}, target=subtitles)
  523. return merge_dicts({
  524. 'id': video_id,
  525. 'formats': formats,
  526. 'subtitles': subtitles,
  527. # '_old_archive_ids': [self._downloader._make_archive_id({'ie_key': 'ORFTVthek', 'id': video_id})],
  528. }, self._parse_metadata(api_json), rev=True)
  529. def _real_extract(self, url):
  530. video_id, segment_id = self._match_valid_url(url).group('id', 'segment')
  531. webpage = self._download_webpage(url, video_id)
  532. # ORF doesn't like 410 or 404
  533. if self._search_regex(r'<div\b[^>]*>\s*(Nicht mehr verfügbar)\s*</div>', webpage, 'Availability', default=False):
  534. raise ExtractorError('Content is no longer available', expected=True, video_id=video_id)
  535. return merge_dicts({
  536. 'id': video_id,
  537. 'title': self._html_search_meta(['og:title', 'twitter:title'], webpage, default=None),
  538. 'description': self._html_search_meta(
  539. ['description', 'og:description', 'twitter:description'], webpage, default=None),
  540. }, self._search_json_ld(webpage, video_id, default={}),
  541. self._extract_video(video_id, segment_id),
  542. rev=True)
  543. class ORFONIE(ORFONBase):
  544. IE_NAME = 'orf:on'
  545. _VALID_URL = r'https?://on\.orf\.at/video/(?P<id>\d+)(?:/(?P<segment>\d+))?'
  546. _TESTS = [{
  547. 'url': 'https://on.orf.at/video/14210000/school-of-champions-48',
  548. 'info_dict': {
  549. 'id': '14210000',
  550. 'ext': 'mp4',
  551. 'duration': 2651.08,
  552. 'thumbnail': 'https://api-tvthek.orf.at/assets/segments/0167/98/thumb_16697671_segments_highlight_teaser.jpeg',
  553. 'title': 'School of Champions (4/8)',
  554. 'description': r're:(?s)Luca hat sein ganzes Leben in den Bergen Südtirols verbracht und ist bei seiner Mutter aufgewachsen, .{1029} Leo$',
  555. # 'media_type': 'episode',
  556. 'timestamp': 1706558922,
  557. 'upload_date': '20240129',
  558. 'release_timestamp': 1706472362,
  559. 'release_date': '20240128',
  560. # 'modified_timestamp': 1712756663,
  561. # 'modified_date': '20240410',
  562. # '_old_archive_ids': ['orftvthek 14210000'],
  563. },
  564. 'params': {
  565. 'format': 'bestvideo',
  566. },
  567. 'skip': 'Available until 2024-08-12',
  568. }, {
  569. 'url': 'https://on.orf.at/video/3220355',
  570. 'md5': '925a93b2b9a37da5c9b979d7cf71aa2e',
  571. 'info_dict': {
  572. 'id': '3220355',
  573. 'ext': 'mp4',
  574. 'duration': 445.04,
  575. 'thumbnail': 'https://api-tvthek.orf.at/assets/segments/0002/60/thumb_159573_segments_highlight_teaser.png',
  576. 'title': '50 Jahre Burgenland: Der Festumzug',
  577. 'description': r're:(?s)Aus allen Landesteilen zogen festlich geschmückte Wagen und Musikkapellen .{270} Jenakowitsch$',
  578. # 'media_type': 'episode',
  579. 'timestamp': 52916400,
  580. 'upload_date': '19710905',
  581. 'release_timestamp': 52916400,
  582. 'release_date': '19710905',
  583. # 'modified_timestamp': 1498536049,
  584. # 'modified_date': '20170627',
  585. # '_old_archive_ids': ['orftvthek 3220355'],
  586. },
  587. }, {
  588. # Video with multiple segments selecting the second segment
  589. 'url': 'https://on.orf.at/video/14226549/15639808/jugendbande-einbrueche-aus-langeweile',
  590. 'md5': 'fc151bba8c05ea77ab5693617e4a33d3',
  591. 'info_dict': {
  592. 'id': '15639808',
  593. 'ext': 'mp4',
  594. 'duration': 97.707,
  595. 'thumbnail': 'https://api-tvthek.orf.at/assets/segments/0175/43/thumb_17442704_segments_highlight_teaser.jpg',
  596. 'title': 'Jugendbande: Einbrüche aus Langeweile',
  597. 'description': r're:Jugendbande: Einbrüche aus Langeweile \| Neuer Kinder- und .{259} Wanda$',
  598. # 'media_type': 'segment',
  599. 'timestamp': 1715792400,
  600. 'upload_date': '20240515',
  601. # 'modified_timestamp': 1715794394,
  602. # 'modified_date': '20240515',
  603. # '_old_archive_ids': ['orftvthek 15639808'],
  604. },
  605. 'params': {
  606. 'noplaylist': True,
  607. 'format': 'bestvideo',
  608. },
  609. 'skip': 'Available until 2024-06-14',
  610. }, {
  611. # Video with multiple segments and no combined version
  612. 'url': 'https://on.orf.at/video/14227864/formel-1-grosser-preis-von-monaco-2024',
  613. 'info_dict': {
  614. '_type': 'multi_video',
  615. 'id': '14227864',
  616. 'duration': 18410.52,
  617. 'thumbnail': 'https://api-tvthek.orf.at/assets/segments/0176/04/thumb_17503881_segments_highlight_teaser.jpg',
  618. 'title': 'Formel 1: Großer Preis von Monaco 2024',
  619. 'description': 'md5:aeeb010710ccf70ce28ccb4482243d4f',
  620. # 'media_type': 'episode',
  621. 'timestamp': 1716721200,
  622. 'upload_date': '20240526',
  623. 'release_timestamp': 1716721802,
  624. 'release_date': '20240526',
  625. # 'modified_timestamp': 1716884702,
  626. # 'modified_date': '20240528',
  627. },
  628. 'playlist_count': 42,
  629. 'skip': 'Gone: Nicht mehr verfügbar',
  630. }, {
  631. # Video with multiple segments, but with combined version
  632. 'url': 'https://on.orf.at/video/14228172',
  633. 'info_dict': {
  634. 'id': '14228172',
  635. 'ext': 'mp4',
  636. 'duration': 3294.878,
  637. 'thumbnail': 'https://api-tvthek.orf.at/assets/segments/0176/29/thumb_17528242_segments_highlight_teaser.jpg',
  638. 'title': 'Willkommen Österreich mit Stermann & Grissemann',
  639. 'description': r're:Zum Saisonfinale freuen sich die urlaubsreifen Gastgeber Stermann und .{1863} Geschichten\.$',
  640. # 'media_type': 'episode',
  641. 'timestamp': 1716926584,
  642. 'upload_date': '20240528',
  643. 'release_timestamp': 1716919202,
  644. 'release_date': '20240528',
  645. # 'modified_timestamp': 1716968045,
  646. # 'modified_date': '20240529',
  647. # '_old_archive_ids': ['orftvthek 14228172'],
  648. },
  649. 'params': {
  650. 'format': 'bestvideo',
  651. },
  652. 'skip': 'Gone: Nicht mehr verfügbar',
  653. }]
  654. class ORFONLiveIE(ORFONBase):
  655. _ENC_PFX = '8876324jshjd7293ktd'
  656. _API_PATH = 'livestream'
  657. _VALID_URL = r'https?://on\.orf\.at/livestream/(?P<id>\d+)(?:/(?P<segment>\d+))?'
  658. _TESTS = [{
  659. 'url': 'https://on.orf.at/livestream/14320204/pressekonferenz-neos-zu-aktuellen-entwicklungen',
  660. 'info_dict': {
  661. 'id': '14320204',
  662. 'ext': 'mp4',
  663. 'title': 'Pressekonferenz: Neos zu aktuellen Entwicklungen',
  664. 'description': r're:(?s)Neos-Chefin Beate Meinl-Reisinger informi.{598}ng\."',
  665. 'timestamp': 1716886335,
  666. 'upload_date': '20240528',
  667. # 'modified_timestamp': 1712756663,
  668. # 'modified_date': '20240410',
  669. # '_old_archive_ids': ['orftvthek 14210000'],
  670. },
  671. 'params': {
  672. 'format': 'bestvideo',
  673. },
  674. }]
  675. @classmethod
  676. def _parse_metadata(cls, api_json):
  677. return merge_dicts(
  678. super(ORFONLiveIE, cls)._parse_metadata(api_json),
  679. traverse_obj(api_json, {
  680. 'timestamp': ('updated_at', T(parse_iso8601)),
  681. 'release_timestamp': ('start', T(parse_iso8601)),
  682. 'is_live': True,
  683. }))