orf.py 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762
  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. 'url': 'https://sound.orf.at/collection/4/',
  184. 'info_dict': {
  185. 'id': '4',
  186. },
  187. 'playlist_mincount': 10,
  188. 'playlist_maxcount': 13,
  189. }]
  190. def _real_extract(self, url):
  191. coll_id, item_id = self._match_valid_url(url).group('coll_id', 'item_id')
  192. data = self._download_json(
  193. 'https://collector.orf.at/api/frontend/collections/{0}?_o=sound.orf.at'.format(
  194. coll_id), coll_id)
  195. data = self._get_api_payload(data, coll_id, in_payload=True)
  196. def yield_items():
  197. for item in traverse_obj(data, (
  198. 'content', 'items', lambda _, v: any(k in v['target']['params'] for k in self._ID_NAMES))):
  199. if item_id is None or item_id == txt_or_none(item.get('id')):
  200. target = item['target']
  201. typed_item_id = self._get_item_id(target['params'])
  202. station = target['params'].get('station')
  203. item_type = target.get('type')
  204. if typed_item_id and (station or item_type):
  205. yield station, typed_item_id, item_type
  206. if item_id is not None:
  207. break
  208. else:
  209. if item_id is not None:
  210. raise ExtractorError('Item not found in collection',
  211. video_id=coll_id, expected=True)
  212. def item_playlist(station, typed_item_id, item_type):
  213. if item_type == 'upload':
  214. item_data = self._download_json('https://audioapi.orf.at/radiothek/api/2.0/upload/{0}?_o=sound.orf.at'.format(
  215. typed_item_id), typed_item_id)
  216. elif item_type == 'podcast-episode':
  217. item_data = self._download_json('https://audioapi.orf.at/radiothek/api/2.0/episode/{0}?_o=sound.orf.at'.format(
  218. typed_item_id), typed_item_id)
  219. else:
  220. api_station, _, _ = self.STATION_INFO[station]
  221. item_data = self._download_json(
  222. 'https://audioapi.orf.at/{0}/api/json/5.0/{1}/{2}?_o=sound.orf.at'.format(
  223. api_station, item_type or 'broadcastitem', typed_item_id), typed_item_id)
  224. item_data = self._get_api_payload(item_data, typed_item_id, in_payload=True)
  225. return merge_dicts(
  226. {'_type': 'multi_video'},
  227. self.playlist_result(
  228. self._entries(item_data, station, item_type), typed_item_id,
  229. txt_or_none(data.get('title')),
  230. clean_html(data.get('subtitle'))))
  231. def yield_item_entries():
  232. for station, typed_id, item_type in yield_items():
  233. yield item_playlist(station, typed_id, item_type)
  234. if item_id is not None:
  235. # coll_id = '/'.join((coll_id, item_id))
  236. return next(yield_item_entries())
  237. return self.playlist_result(yield_item_entries(), coll_id, data.get('title'))
  238. class ORFPodcastIE(ORFRadioBase):
  239. IE_NAME = 'orf:podcast'
  240. _STATION_RE = '|'.join(map(re.escape, (x[0] for x in ORFRadioBase.STATION_INFO.values()))) + '|tv'
  241. _VALID_URL = r'https?://sound\.orf\.at/podcast/(?P<station>{0})/(?P<show>[\w-]+)/(?P<id>[\w-]+)'.format(_STATION_RE)
  242. _TESTS = [{
  243. 'url': 'https://sound.orf.at/podcast/stm/der-kraeutertipp-von-christine-lackner/rotklee',
  244. 'md5': '1f2bab2ba90c2ce0c2754196ea78b35f',
  245. 'info_dict': {
  246. 'id': 'der-kraeutertipp-von-christine-lackner/rotklee',
  247. 'ext': 'mp3',
  248. 'title': 'Rotklee',
  249. '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.',
  250. 'timestamp': 1716891761,
  251. 'upload_date': '20240528',
  252. 'uploader_id': 'stm_kraeutertipp',
  253. 'uploader': 'ORF Radio Steiermark',
  254. 'duration': 101,
  255. 'series': 'Der Kräutertipp von Christine Lackner',
  256. },
  257. # 'skip': 'ORF podcasts are only available for a limited time'
  258. }]
  259. _ID_NAMES = ('slug', 'guid')
  260. def _real_extract(self, url):
  261. station, show, show_id = self._match_valid_url(url).group('station', 'show', 'id')
  262. data = self._download_json(
  263. 'https://audioapi.orf.at/radiothek/api/2.0/podcast/{0}/{1}/{2}'.format(
  264. station, show, show_id), show_id)
  265. data = self._get_api_payload(data, show_id, in_payload=True)
  266. return merge_dicts({
  267. 'id': '/'.join((show, show_id)),
  268. 'ext': 'mp3',
  269. 'vcodec': 'none',
  270. }, self._extract_podcast_upload(data), rev=True)
  271. class ORFIPTVBase(InfoExtractor):
  272. _TITLE_STRIP_RE = ''
  273. def _extract_video(self, video_id, webpage, fatal=False):
  274. data = self._download_json(
  275. 'http://bits.orf.at/filehandler/static-api/json/current/data.json?file=%s' % video_id,
  276. video_id)[0]
  277. video = traverse_obj(data, (
  278. 'sources', ('default', 'q8c'),
  279. T(lambda x: x if x['loadBalancerUrl'] else None),
  280. any))
  281. load_balancer_url = video['loadBalancerUrl']
  282. try:
  283. rendition = self._download_json(
  284. load_balancer_url, video_id, transform_source=strip_jsonp)
  285. except ExtractorError:
  286. rendition = None
  287. if not rendition:
  288. rendition = {
  289. 'redirect': {
  290. 'smil': re.sub(
  291. r'(/)jsonp(/.+\.)mp4$', r'\1dash\2smil/manifest.mpd',
  292. load_balancer_url),
  293. },
  294. }
  295. f = traverse_obj(video, {
  296. 'abr': ('audioBitrate', T(int_or_none)),
  297. 'vbr': ('bitrate', T(int_or_none)),
  298. 'fps': ('videoFps', T(int_or_none)),
  299. 'width': ('videoWidth', T(int_or_none)),
  300. 'height': ('videoHeight', T(int_or_none)),
  301. })
  302. formats = []
  303. for format_id, format_url in traverse_obj(rendition, (
  304. 'redirect', T(dict.items), Ellipsis)):
  305. if format_id == 'rtmp':
  306. ff = f.copy()
  307. ff.update({
  308. 'url': format_url,
  309. 'format_id': format_id,
  310. })
  311. formats.append(ff)
  312. elif determine_ext(format_url) == 'f4m':
  313. formats.extend(self._extract_f4m_formats(
  314. format_url, video_id, f4m_id=format_id))
  315. elif determine_ext(format_url) == 'm3u8':
  316. formats.extend(self._extract_m3u8_formats(
  317. format_url, video_id, 'mp4', m3u8_id=format_id,
  318. entry_protocol='m3u8_native'))
  319. elif determine_ext(format_url) == 'mpd':
  320. formats.extend(self._extract_mpd_formats(
  321. format_url, video_id, mpd_id=format_id))
  322. if formats or fatal:
  323. self._sort_formats(formats)
  324. else:
  325. return
  326. return merge_dicts({
  327. 'id': video_id,
  328. 'title': re.sub(self._TITLE_STRIP_RE, '', self._og_search_title(webpage)),
  329. 'description': self._og_search_description(webpage),
  330. 'upload_date': unified_strdate(self._html_search_meta(
  331. 'dc.date', webpage, 'upload date', fatal=False)),
  332. 'formats': formats,
  333. }, traverse_obj(data, {
  334. 'duration': ('duration', T(k_float_or_none)),
  335. 'thumbnail': ('sources', 'default', 'preview', T(url_or_none)),
  336. }), rev=True)
  337. class ORFIPTVIE(ORFIPTVBase):
  338. IE_NAME = 'orf:iptv'
  339. IE_DESC = 'iptv.ORF.at'
  340. _WORKING = False # URLs redirect to orf.at/
  341. _VALID_URL = r'https?://iptv\.orf\.at/(?:#/)?stories/(?P<id>\d+)'
  342. _TITLE_STRIP_RE = r'\s+-\s+iptv\.ORF\.at\S*$'
  343. _TEST = {
  344. 'url': 'http://iptv.orf.at/stories/2275236/',
  345. 'md5': 'c8b22af4718a4b4af58342529453e3e5',
  346. 'info_dict': {
  347. 'id': '350612',
  348. 'ext': 'flv',
  349. 'title': 'Weitere Evakuierungen um Vulkan Calbuco',
  350. 'description': 'md5:d689c959bdbcf04efeddedbf2299d633',
  351. 'duration': 68.197,
  352. 'thumbnail': r're:^https?://.*\.jpg$',
  353. 'upload_date': '20150425',
  354. },
  355. }
  356. def _real_extract(self, url):
  357. story_id = self._match_id(url)
  358. webpage = self._download_webpage(
  359. 'http://iptv.orf.at/stories/%s' % story_id, story_id)
  360. video_id = self._search_regex(
  361. r'data-video(?:id)?="(\d+)"', webpage, 'video id')
  362. return self._extract_video(video_id, webpage)
  363. class ORFFM4StoryIE(ORFIPTVBase):
  364. IE_NAME = 'orf:fm4:story'
  365. IE_DESC = 'fm4.orf.at stories'
  366. _VALID_URL = r'https?://fm4\.orf\.at/stories/(?P<id>\d+)'
  367. _TITLE_STRIP_RE = r'\s+-\s+fm4\.ORF\.at\s*$'
  368. _TESTS = [{
  369. 'url': 'https://fm4.orf.at/stories/3041554/',
  370. 'add_ie': ['Youtube'],
  371. 'info_dict': {
  372. 'id': '3041554',
  373. 'title': 'Is The EU Green Deal In Mortal Danger?',
  374. },
  375. 'playlist_count': 4,
  376. 'params': {
  377. 'format': 'bestvideo',
  378. },
  379. }, {
  380. 'url': 'http://fm4.orf.at/stories/2865738/',
  381. 'info_dict': {
  382. 'id': '2865738',
  383. 'title': 'Manu Delago und Inner Tongue live',
  384. },
  385. 'playlist': [{
  386. 'md5': 'e1c2c706c45c7b34cf478bbf409907ca',
  387. 'info_dict': {
  388. 'id': '547792',
  389. 'ext': 'flv',
  390. 'title': 'Manu Delago und Inner Tongue live',
  391. '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.',
  392. 'duration': 1748.52,
  393. 'thumbnail': r're:^https?://.*\.jpg$',
  394. 'upload_date': '20170913',
  395. },
  396. }, {
  397. 'md5': 'c6dd2179731f86f4f55a7b49899d515f',
  398. 'info_dict': {
  399. 'id': '547798',
  400. 'ext': 'flv',
  401. '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)',
  402. 'duration': 1504.08,
  403. 'thumbnail': r're:^https?://.*\.jpg$',
  404. 'upload_date': '20170913',
  405. '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.',
  406. },
  407. }],
  408. 'skip': 'Videos gone',
  409. }]
  410. def _real_extract(self, url):
  411. story_id = self._match_id(url)
  412. webpage = self._download_webpage(url, story_id)
  413. entries = []
  414. seen_ids = set()
  415. for idx, video_id in enumerate(re.findall(r'data-video(?:id)?="(\d+)"', webpage)):
  416. if video_id in seen_ids:
  417. continue
  418. seen_ids.add(video_id)
  419. entry = self._extract_video(video_id, webpage, fatal=False)
  420. if not entry:
  421. continue
  422. if idx >= 1:
  423. # Titles are duplicates, make them unique
  424. entry['title'] = '%s (%d)' % (entry['title'], idx)
  425. entries.append(entry)
  426. seen_ids = set()
  427. for yt_id in re.findall(
  428. r'data-id\s*=\s*["\']([\w-]+)[^>]+\bclass\s*=\s*["\']youtube\b',
  429. webpage):
  430. if yt_id in seen_ids:
  431. continue
  432. seen_ids.add(yt_id)
  433. if YoutubeIE.suitable(yt_id):
  434. entries.append(self.url_result(yt_id, ie='Youtube', video_id=yt_id))
  435. return self.playlist_result(
  436. entries, story_id,
  437. re.sub(self._TITLE_STRIP_RE, '', self._og_search_title(webpage, default='') or None))
  438. class ORFONBase(InfoExtractor):
  439. _ENC_PFX = '3dSlfek03nsLKdj4Jsd'
  440. _API_PATH = 'episode'
  441. def _call_api(self, video_id, **kwargs):
  442. encrypted_id = base64.b64encode('{0}{1}'.format(
  443. self._ENC_PFX, video_id).encode('utf-8')).decode('ascii')
  444. return self._download_json(
  445. 'https://api-tvthek.orf.at/api/v4.3/public/{0}/encrypted/{1}'.format(
  446. self._API_PATH, encrypted_id),
  447. video_id, **kwargs)
  448. @classmethod
  449. def _parse_metadata(cls, api_json):
  450. return traverse_obj(api_json, {
  451. 'id': ('id', T(int), T(txt_or_none)),
  452. 'age_limit': ('age_classification', T(parse_age_limit)),
  453. 'duration': ((('exact_duration', T(k_float_or_none)),
  454. ('duration_second', T(float_or_none))),),
  455. 'title': (('title', 'headline'), T(txt_or_none)),
  456. 'description': (('description', 'teaser_text'), T(txt_or_none)),
  457. # 'media_type': ('video_type', T(txt_or_none)),
  458. 'thumbnail': ('_embedded', 'image', 'public_urls', 'highlight_teaser', 'url', T(url_or_none)),
  459. 'timestamp': (('date', 'episode_date'), T(parse_iso8601)),
  460. 'release_timestamp': ('release_date', T(parse_iso8601)),
  461. # 'modified_timestamp': ('updated_at', T(parse_iso8601)),
  462. }, get_all=False)
  463. def _extract_video(self, video_id, segment_id):
  464. # Not a segmented episode: return single video
  465. # Segmented episode without valid segment id: return entire playlist
  466. # Segmented episode with valid segment id and yes-playlist: return entire playlist
  467. # Segmented episode with valid segment id and no-playlist: return single video corresponding to segment id
  468. # If a multi_video playlist would be returned, but an unsegmented source exists, that source is chosen instead.
  469. api_json = self._call_api(video_id)
  470. if traverse_obj(api_json, 'is_drm_protected'):
  471. self.report_drm(video_id)
  472. # updates formats, subtitles
  473. def extract_sources(src_json, video_id):
  474. for manifest_type in traverse_obj(src_json, ('sources', T(dict.keys), Ellipsis)):
  475. for manifest_url in traverse_obj(src_json, ('sources', manifest_type, Ellipsis, 'src', T(url_or_none))):
  476. if manifest_type == 'hls':
  477. fmts, subs = self._extract_m3u8_formats(
  478. manifest_url, video_id, fatal=False, m3u8_id='hls',
  479. ext='mp4', entry_protocol='m3u8_native'), {}
  480. for f in fmts:
  481. if '_vo.' in f['url']:
  482. f['acodec'] = 'none'
  483. elif manifest_type == 'dash':
  484. fmts, subs = self._extract_mpd_formats_and_subtitles(
  485. manifest_url, video_id, fatal=False, mpd_id='dash')
  486. else:
  487. continue
  488. formats.extend(fmts)
  489. self._merge_subtitles(subs, target=subtitles)
  490. formats, subtitles = [], {}
  491. if segment_id is None:
  492. extract_sources(api_json, video_id)
  493. if not formats:
  494. segments = traverse_obj(api_json, (
  495. '_embedded', 'segments', lambda _, v: v['id']))
  496. if len(segments) > 1 and segment_id is not None:
  497. if not self._yes_playlist(video_id, segment_id, playlist_label='collection', video_label='segment'):
  498. segments = [next(s for s in segments if txt_or_none(s['id']) == segment_id)]
  499. entries = []
  500. for seg in segments:
  501. formats, subtitles = [], {}
  502. extract_sources(seg, segment_id)
  503. self._sort_formats(formats)
  504. entries.append(merge_dicts({
  505. 'formats': formats,
  506. 'subtitles': subtitles,
  507. }, self._parse_metadata(seg), rev=True))
  508. result = merge_dicts(
  509. {'_type': 'multi_video' if len(entries) > 1 else 'playlist'},
  510. self._parse_metadata(api_json),
  511. self.playlist_result(entries, video_id))
  512. # not yet processed in core for playlist/multi
  513. self._downloader._fill_common_fields(result)
  514. return result
  515. else:
  516. self._sort_formats(formats)
  517. for sub_url in traverse_obj(api_json, (
  518. '_embedded', 'subtitle',
  519. ('xml_url', 'sami_url', 'stl_url', 'ttml_url', 'srt_url', 'vtt_url'),
  520. T(url_or_none))):
  521. self._merge_subtitles({'de': [{'url': sub_url}]}, target=subtitles)
  522. return merge_dicts({
  523. 'id': video_id,
  524. 'formats': formats,
  525. 'subtitles': subtitles,
  526. # '_old_archive_ids': [self._downloader._make_archive_id({'ie_key': 'ORFTVthek', 'id': video_id})],
  527. }, self._parse_metadata(api_json), rev=True)
  528. def _real_extract(self, url):
  529. video_id, segment_id = self._match_valid_url(url).group('id', 'segment')
  530. webpage = self._download_webpage(url, video_id)
  531. # ORF doesn't like 410 or 404
  532. if self._search_regex(r'<div\b[^>]*>\s*(Nicht mehr verfügbar)\s*</div>', webpage, 'Availability', default=False):
  533. raise ExtractorError('Content is no longer available', expected=True, video_id=video_id)
  534. return merge_dicts({
  535. 'id': video_id,
  536. 'title': self._html_search_meta(['og:title', 'twitter:title'], webpage, default=None),
  537. 'description': self._html_search_meta(
  538. ['description', 'og:description', 'twitter:description'], webpage, default=None),
  539. }, self._search_json_ld(webpage, video_id, default={}),
  540. self._extract_video(video_id, segment_id),
  541. rev=True)
  542. class ORFONIE(ORFONBase):
  543. IE_NAME = 'orf:on'
  544. _VALID_URL = r'https?://on\.orf\.at/video/(?P<id>\d+)(?:/(?P<segment>\d+))?'
  545. _TESTS = [{
  546. 'url': 'https://on.orf.at/video/14210000/school-of-champions-48',
  547. 'info_dict': {
  548. 'id': '14210000',
  549. 'ext': 'mp4',
  550. 'duration': 2651.08,
  551. 'thumbnail': 'https://api-tvthek.orf.at/assets/segments/0167/98/thumb_16697671_segments_highlight_teaser.jpeg',
  552. 'title': 'School of Champions (4/8)',
  553. 'description': r're:(?s)Luca hat sein ganzes Leben in den Bergen Südtirols verbracht und ist bei seiner Mutter aufgewachsen, .{1029} Leo$',
  554. # 'media_type': 'episode',
  555. 'timestamp': 1706558922,
  556. 'upload_date': '20240129',
  557. 'release_timestamp': 1706472362,
  558. 'release_date': '20240128',
  559. # 'modified_timestamp': 1712756663,
  560. # 'modified_date': '20240410',
  561. # '_old_archive_ids': ['orftvthek 14210000'],
  562. },
  563. 'params': {
  564. 'format': 'bestvideo',
  565. },
  566. }, {
  567. 'url': 'https://on.orf.at/video/3220355',
  568. 'md5': '925a93b2b9a37da5c9b979d7cf71aa2e',
  569. 'info_dict': {
  570. 'id': '3220355',
  571. 'ext': 'mp4',
  572. 'duration': 445.04,
  573. 'thumbnail': 'https://api-tvthek.orf.at/assets/segments/0002/60/thumb_159573_segments_highlight_teaser.png',
  574. 'title': '50 Jahre Burgenland: Der Festumzug',
  575. 'description': r're:(?s)Aus allen Landesteilen zogen festlich geschmückte Wagen und Musikkapellen .{270} Jenakowitsch$',
  576. # 'media_type': 'episode',
  577. 'timestamp': 52916400,
  578. 'upload_date': '19710905',
  579. 'release_timestamp': 52916400,
  580. 'release_date': '19710905',
  581. # 'modified_timestamp': 1498536049,
  582. # 'modified_date': '20170627',
  583. # '_old_archive_ids': ['orftvthek 3220355'],
  584. },
  585. }, {
  586. # Video with multiple segments selecting the second segment
  587. 'url': 'https://on.orf.at/video/14226549/15639808/jugendbande-einbrueche-aus-langeweile',
  588. 'md5': 'fc151bba8c05ea77ab5693617e4a33d3',
  589. 'info_dict': {
  590. 'id': '15639808',
  591. 'ext': 'mp4',
  592. 'duration': 97.707,
  593. 'thumbnail': 'https://api-tvthek.orf.at/assets/segments/0175/43/thumb_17442704_segments_highlight_teaser.jpg',
  594. 'title': 'Jugendbande: Einbrüche aus Langeweile',
  595. 'description': r're:Jugendbande: Einbrüche aus Langeweile \| Neuer Kinder- und .{259} Wanda$',
  596. # 'media_type': 'segment',
  597. 'timestamp': 1715792400,
  598. 'upload_date': '20240515',
  599. # 'modified_timestamp': 1715794394,
  600. # 'modified_date': '20240515',
  601. # '_old_archive_ids': ['orftvthek 15639808'],
  602. },
  603. 'params': {
  604. 'noplaylist': True,
  605. 'format': 'bestvideo',
  606. },
  607. }, {
  608. # Video with multiple segments and no combined version
  609. 'url': 'https://on.orf.at/video/14227864/formel-1-grosser-preis-von-monaco-2024',
  610. 'info_dict': {
  611. '_type': 'multi_video',
  612. 'id': '14227864',
  613. 'duration': 18410.52,
  614. 'thumbnail': 'https://api-tvthek.orf.at/assets/segments/0176/04/thumb_17503881_segments_highlight_teaser.jpg',
  615. 'title': 'Formel 1: Großer Preis von Monaco 2024',
  616. 'description': 'md5:aeeb010710ccf70ce28ccb4482243d4f',
  617. # 'media_type': 'episode',
  618. 'timestamp': 1716721200,
  619. 'upload_date': '20240526',
  620. 'release_timestamp': 1716721802,
  621. 'release_date': '20240526',
  622. # 'modified_timestamp': 1716884702,
  623. # 'modified_date': '20240528',
  624. },
  625. 'playlist_count': 42,
  626. 'skip': 'Gone: Nicht mehr verfügbar',
  627. }, {
  628. # Video with multiple segments, but with combined version
  629. 'url': 'https://on.orf.at/video/14228172',
  630. 'info_dict': {
  631. 'id': '14228172',
  632. 'ext': 'mp4',
  633. 'duration': 3294.878,
  634. 'thumbnail': 'https://api-tvthek.orf.at/assets/segments/0176/29/thumb_17528242_segments_highlight_teaser.jpg',
  635. 'title': 'Willkommen Österreich mit Stermann & Grissemann',
  636. 'description': r're:Zum Saisonfinale freuen sich die urlaubsreifen Gastgeber Stermann und .{1863} Geschichten\.$',
  637. # 'media_type': 'episode',
  638. 'timestamp': 1716926584,
  639. 'upload_date': '20240528',
  640. 'release_timestamp': 1716919202,
  641. 'release_date': '20240528',
  642. # 'modified_timestamp': 1716968045,
  643. # 'modified_date': '20240529',
  644. # '_old_archive_ids': ['orftvthek 14228172'],
  645. },
  646. 'params': {
  647. 'format': 'bestvideo',
  648. },
  649. 'skip': 'Gone: Nicht mehr verfügbar',
  650. }]
  651. class ORFONLiveIE(ORFONBase):
  652. _ENC_PFX = '8876324jshjd7293ktd'
  653. _API_PATH = 'livestream'
  654. _VALID_URL = r'https?://on\.orf\.at/livestream/(?P<id>\d+)(?:/(?P<segment>\d+))?'
  655. _TESTS = [{
  656. 'url': 'https://on.orf.at/livestream/14320204/pressekonferenz-neos-zu-aktuellen-entwicklungen',
  657. 'info_dict': {
  658. 'id': '14320204',
  659. 'ext': 'mp4',
  660. 'title': 'Pressekonferenz: Neos zu aktuellen Entwicklungen',
  661. 'description': r're:(?s)Neos-Chefin Beate Meinl-Reisinger informi.{598}ng\."',
  662. 'timestamp': 1716886335,
  663. 'upload_date': '20240528',
  664. # 'modified_timestamp': 1712756663,
  665. # 'modified_date': '20240410',
  666. # '_old_archive_ids': ['orftvthek 14210000'],
  667. },
  668. 'params': {
  669. 'format': 'bestvideo',
  670. },
  671. }]
  672. @classmethod
  673. def _parse_metadata(cls, api_json):
  674. return merge_dicts(
  675. super(ORFONLiveIE, cls)._parse_metadata(api_json),
  676. traverse_obj(api_json, {
  677. 'timestamp': ('updated_at', T(parse_iso8601)),
  678. 'release_timestamp': ('start', T(parse_iso8601)),
  679. 'is_live': True,
  680. }))