logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

ard.py (28193B)


  1. import functools
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. OnDemandPagedList,
  6. bug_reports_message,
  7. determine_ext,
  8. int_or_none,
  9. join_nonempty,
  10. jwt_decode_hs256,
  11. make_archive_id,
  12. parse_duration,
  13. parse_iso8601,
  14. remove_start,
  15. str_or_none,
  16. unified_strdate,
  17. update_url_query,
  18. url_or_none,
  19. xpath_text,
  20. )
  21. from ..utils.traversal import traverse_obj
  22. class ARDMediathekBaseIE(InfoExtractor):
  23. _GEO_COUNTRIES = ['DE']
  24. def _extract_media_info(self, media_info_url, webpage, video_id):
  25. media_info = self._download_json(
  26. media_info_url, video_id, 'Downloading media JSON')
  27. return self._parse_media_info(media_info, video_id, '"fsk"' in webpage)
  28. def _parse_media_info(self, media_info, video_id, fsk):
  29. formats = self._extract_formats(media_info, video_id)
  30. if not formats:
  31. if fsk:
  32. self.raise_no_formats(
  33. 'This video is only available after 20:00', expected=True)
  34. elif media_info.get('_geoblocked'):
  35. self.raise_geo_restricted(
  36. 'This video is not available due to geoblocking',
  37. countries=self._GEO_COUNTRIES, metadata_available=True)
  38. subtitles = {}
  39. subtitle_url = media_info.get('_subtitleUrl')
  40. if subtitle_url:
  41. subtitles['de'] = [{
  42. 'ext': 'ttml',
  43. 'url': subtitle_url,
  44. }, {
  45. 'ext': 'vtt',
  46. 'url': subtitle_url.replace('/ebutt/', '/webvtt/') + '.vtt',
  47. }]
  48. return {
  49. 'id': video_id,
  50. 'duration': int_or_none(media_info.get('_duration')),
  51. 'thumbnail': media_info.get('_previewImage'),
  52. 'is_live': media_info.get('_isLive') is True,
  53. 'formats': formats,
  54. 'subtitles': subtitles,
  55. }
  56. def _extract_formats(self, media_info, video_id):
  57. type_ = media_info.get('_type')
  58. media_array = media_info.get('_mediaArray', [])
  59. formats = []
  60. for num, media in enumerate(media_array):
  61. for stream in media.get('_mediaStreamArray', []):
  62. stream_urls = stream.get('_stream')
  63. if not stream_urls:
  64. continue
  65. if not isinstance(stream_urls, list):
  66. stream_urls = [stream_urls]
  67. quality = stream.get('_quality')
  68. server = stream.get('_server')
  69. for stream_url in stream_urls:
  70. if not url_or_none(stream_url):
  71. continue
  72. ext = determine_ext(stream_url)
  73. if quality != 'auto' and ext in ('f4m', 'm3u8'):
  74. continue
  75. if ext == 'f4m':
  76. formats.extend(self._extract_f4m_formats(
  77. update_url_query(stream_url, {
  78. 'hdcore': '3.1.1',
  79. 'plugin': 'aasp-3.1.1.69.124',
  80. }), video_id, f4m_id='hds', fatal=False))
  81. elif ext == 'm3u8':
  82. formats.extend(self._extract_m3u8_formats(
  83. stream_url, video_id, 'mp4', 'm3u8_native',
  84. m3u8_id='hls', fatal=False))
  85. else:
  86. if server and server.startswith('rtmp'):
  87. f = {
  88. 'url': server,
  89. 'play_path': stream_url,
  90. 'format_id': f'a{num}-rtmp-{quality}',
  91. }
  92. else:
  93. f = {
  94. 'url': stream_url,
  95. 'format_id': f'a{num}-{ext}-{quality}',
  96. }
  97. m = re.search(
  98. r'_(?P<width>\d+)x(?P<height>\d+)\.mp4$',
  99. stream_url)
  100. if m:
  101. f.update({
  102. 'width': int(m.group('width')),
  103. 'height': int(m.group('height')),
  104. })
  105. if type_ == 'audio':
  106. f['vcodec'] = 'none'
  107. formats.append(f)
  108. return formats
  109. class ARDIE(InfoExtractor):
  110. _VALID_URL = r'(?P<mainurl>https?://(?:www\.)?daserste\.de/(?:[^/?#&]+/)+(?P<id>[^/?#&]+))\.html'
  111. _TESTS = [{
  112. # available till 7.12.2023
  113. 'url': 'https://www.daserste.de/information/talk/maischberger/videos/maischberger-video-424.html',
  114. 'md5': '94812e6438488fb923c361a44469614b',
  115. 'info_dict': {
  116. 'id': 'maischberger-video-424',
  117. 'display_id': 'maischberger-video-424',
  118. 'ext': 'mp4',
  119. 'duration': 4452.0,
  120. 'title': 'maischberger am 07.12.2022',
  121. 'upload_date': '20221207',
  122. 'thumbnail': r're:^https?://.*\.jpg$',
  123. },
  124. }, {
  125. 'url': 'https://www.daserste.de/information/politik-weltgeschehen/morgenmagazin/videosextern/dominik-kahun-aus-der-nhl-direkt-zur-weltmeisterschaft-100.html',
  126. 'only_matching': True,
  127. }, {
  128. 'url': 'https://www.daserste.de/information/nachrichten-wetter/tagesthemen/videosextern/tagesthemen-17736.html',
  129. 'only_matching': True,
  130. }, {
  131. 'url': 'https://www.daserste.de/unterhaltung/serie/in-aller-freundschaft-die-jungen-aerzte/videos/diversity-tag-sanam-afrashteh100.html',
  132. 'only_matching': True,
  133. }, {
  134. 'url': 'http://www.daserste.de/information/reportage-dokumentation/dokus/videos/die-story-im-ersten-mission-unter-falscher-flagge-100.html',
  135. 'only_matching': True,
  136. }, {
  137. 'url': 'https://www.daserste.de/unterhaltung/serie/in-aller-freundschaft-die-jungen-aerzte/Drehpause-100.html',
  138. 'only_matching': True,
  139. }, {
  140. 'url': 'https://www.daserste.de/unterhaltung/film/filmmittwoch-im-ersten/videos/making-ofwendezeit-video-100.html',
  141. 'only_matching': True,
  142. }]
  143. def _real_extract(self, url):
  144. mobj = self._match_valid_url(url)
  145. display_id = mobj.group('id')
  146. player_url = mobj.group('mainurl') + '~playerXml.xml'
  147. doc = self._download_xml(player_url, display_id)
  148. video_node = doc.find('./video')
  149. upload_date = unified_strdate(xpath_text(
  150. video_node, './broadcastDate'))
  151. thumbnail = xpath_text(video_node, './/teaserImage//variant/url')
  152. formats = []
  153. for a in video_node.findall('.//asset'):
  154. file_name = xpath_text(a, './fileName', default=None)
  155. if not file_name:
  156. continue
  157. format_type = a.attrib.get('type')
  158. format_url = url_or_none(file_name)
  159. if format_url:
  160. ext = determine_ext(file_name)
  161. if ext == 'm3u8':
  162. formats.extend(self._extract_m3u8_formats(
  163. format_url, display_id, 'mp4', entry_protocol='m3u8_native',
  164. m3u8_id=format_type or 'hls', fatal=False))
  165. continue
  166. elif ext == 'f4m':
  167. formats.extend(self._extract_f4m_formats(
  168. update_url_query(format_url, {'hdcore': '3.7.0'}),
  169. display_id, f4m_id=format_type or 'hds', fatal=False))
  170. continue
  171. f = {
  172. 'format_id': format_type,
  173. 'width': int_or_none(xpath_text(a, './frameWidth')),
  174. 'height': int_or_none(xpath_text(a, './frameHeight')),
  175. 'vbr': int_or_none(xpath_text(a, './bitrateVideo')),
  176. 'abr': int_or_none(xpath_text(a, './bitrateAudio')),
  177. 'vcodec': xpath_text(a, './codecVideo'),
  178. 'tbr': int_or_none(xpath_text(a, './totalBitrate')),
  179. }
  180. server_prefix = xpath_text(a, './serverPrefix', default=None)
  181. if server_prefix:
  182. f.update({
  183. 'url': server_prefix,
  184. 'playpath': file_name,
  185. })
  186. else:
  187. if not format_url:
  188. continue
  189. f['url'] = format_url
  190. formats.append(f)
  191. _SUB_FORMATS = (
  192. ('./dataTimedText', 'ttml'),
  193. ('./dataTimedTextNoOffset', 'ttml'),
  194. ('./dataTimedTextVtt', 'vtt'),
  195. )
  196. subtitles = {}
  197. for subsel, subext in _SUB_FORMATS:
  198. for node in video_node.findall(subsel):
  199. subtitles.setdefault('de', []).append({
  200. 'url': node.attrib['url'],
  201. 'ext': subext,
  202. })
  203. return {
  204. 'id': xpath_text(video_node, './videoId', default=display_id),
  205. 'formats': formats,
  206. 'subtitles': subtitles,
  207. 'display_id': display_id,
  208. 'title': video_node.find('./title').text,
  209. 'duration': parse_duration(video_node.find('./duration').text),
  210. 'upload_date': upload_date,
  211. 'thumbnail': thumbnail,
  212. }
  213. class ARDBetaMediathekIE(InfoExtractor):
  214. IE_NAME = 'ARDMediathek'
  215. _VALID_URL = r'''(?x)https?://
  216. (?:(?:beta|www)\.)?ardmediathek\.de/
  217. (?:[^/]+/)?
  218. (?:player|live|video)/
  219. (?:[^?#]+/)?
  220. (?P<id>[a-zA-Z0-9]+)
  221. /?(?:[?#]|$)'''
  222. _GEO_COUNTRIES = ['DE']
  223. _TOKEN_URL = 'https://sso.ardmediathek.de/sso/token'
  224. _TESTS = [{
  225. 'url': 'https://www.ardmediathek.de/video/filme-im-mdr/liebe-auf-vier-pfoten/mdr-fernsehen/Y3JpZDovL21kci5kZS9zZW5kdW5nLzI4MjA0MC80MjIwOTEtNDAyNTM0',
  226. 'md5': 'b6e8ab03f2bcc6e1f9e6cef25fcc03c4',
  227. 'info_dict': {
  228. 'display_id': 'Y3JpZDovL21kci5kZS9zZW5kdW5nLzI4MjA0MC80MjIwOTEtNDAyNTM0',
  229. 'id': '12939099',
  230. 'title': 'Liebe auf vier Pfoten',
  231. 'description': r're:^Claudia Schmitt, Anwältin in Salzburg',
  232. 'duration': 5222,
  233. 'thumbnail': 'https://api.ardmediathek.de/image-service/images/urn:ard:image:aee7cbf8f06de976?w=960&ch=ae4d0f2ee47d8b9b',
  234. 'timestamp': 1701343800,
  235. 'upload_date': '20231130',
  236. 'ext': 'mp4',
  237. 'episode': 'Liebe auf vier Pfoten',
  238. 'series': 'Filme im MDR',
  239. 'age_limit': 0,
  240. 'channel': 'MDR',
  241. '_old_archive_ids': ['ardbetamediathek Y3JpZDovL21kci5kZS9zZW5kdW5nLzI4MjA0MC80MjIwOTEtNDAyNTM0'],
  242. },
  243. }, {
  244. 'url': 'https://www.ardmediathek.de/mdr/video/die-robuste-roswita/Y3JpZDovL21kci5kZS9iZWl0cmFnL2Ntcy84MWMxN2MzZC0wMjkxLTRmMzUtODk4ZS0wYzhlOWQxODE2NGI/',
  245. 'md5': 'a1dc75a39c61601b980648f7c9f9f71d',
  246. 'info_dict': {
  247. 'display_id': 'die-robuste-roswita',
  248. 'id': '78566716',
  249. 'title': 'Die robuste Roswita',
  250. 'description': r're:^Der Mord.*totgeglaubte Ehefrau Roswita',
  251. 'duration': 5316,
  252. 'thumbnail': 'https://img.ardmediathek.de/standard/00/78/56/67/84/575672121/16x9/960?mandant=ard',
  253. 'timestamp': 1596658200,
  254. 'upload_date': '20200805',
  255. 'ext': 'mp4',
  256. },
  257. 'skip': 'Error',
  258. }, {
  259. 'url': 'https://www.ardmediathek.de/video/tagesschau-oder-tagesschau-20-00-uhr/das-erste/Y3JpZDovL2Rhc2Vyc3RlLmRlL3RhZ2Vzc2NoYXUvZmM4ZDUxMjgtOTE0ZC00Y2MzLTgzNzAtNDZkNGNiZWJkOTll',
  260. 'md5': '1e73ded21cb79bac065117e80c81dc88',
  261. 'info_dict': {
  262. 'id': '10049223',
  263. 'ext': 'mp4',
  264. 'title': 'tagesschau, 20:00 Uhr',
  265. 'timestamp': 1636398000,
  266. 'description': 'md5:39578c7b96c9fe50afdf5674ad985e6b',
  267. 'upload_date': '20211108',
  268. 'display_id': 'Y3JpZDovL2Rhc2Vyc3RlLmRlL3RhZ2Vzc2NoYXUvZmM4ZDUxMjgtOTE0ZC00Y2MzLTgzNzAtNDZkNGNiZWJkOTll',
  269. 'duration': 915,
  270. 'episode': 'tagesschau, 20:00 Uhr',
  271. 'series': 'tagesschau',
  272. 'thumbnail': 'https://api.ardmediathek.de/image-service/images/urn:ard:image:fbb21142783b0a49?w=960&ch=ee69108ae344f678',
  273. 'channel': 'ARD-Aktuell',
  274. '_old_archive_ids': ['ardbetamediathek Y3JpZDovL2Rhc2Vyc3RlLmRlL3RhZ2Vzc2NoYXUvZmM4ZDUxMjgtOTE0ZC00Y2MzLTgzNzAtNDZkNGNiZWJkOTll'],
  275. },
  276. }, {
  277. 'url': 'https://www.ardmediathek.de/video/7-tage/7-tage-unter-harten-jungs/hr-fernsehen/N2I2YmM5MzgtNWFlOS00ZGFlLTg2NzMtYzNjM2JlNjk4MDg3',
  278. 'md5': 'c428b9effff18ff624d4f903bda26315',
  279. 'info_dict': {
  280. 'id': '94834686',
  281. 'ext': 'mp4',
  282. 'duration': 2670,
  283. 'episode': '7 Tage ... unter harten Jungs',
  284. 'description': 'md5:0f215470dcd2b02f59f4bd10c963f072',
  285. 'upload_date': '20231005',
  286. 'timestamp': 1696491171,
  287. 'display_id': 'N2I2YmM5MzgtNWFlOS00ZGFlLTg2NzMtYzNjM2JlNjk4MDg3',
  288. 'series': '7 Tage ...',
  289. 'channel': 'HR',
  290. 'thumbnail': 'https://api.ardmediathek.de/image-service/images/urn:ard:image:430c86d233afa42d?w=960&ch=fa32ba69bc87989a',
  291. 'title': '7 Tage ... unter harten Jungs',
  292. '_old_archive_ids': ['ardbetamediathek N2I2YmM5MzgtNWFlOS00ZGFlLTg2NzMtYzNjM2JlNjk4MDg3'],
  293. },
  294. }, {
  295. 'url': 'https://www.ardmediathek.de/video/lokalzeit-aus-duesseldorf/lokalzeit-aus-duesseldorf-oder-31-10-2024/wdr-duesseldorf/Y3JpZDovL3dkci5kZS9CZWl0cmFnLXNvcGhvcmEtOWFkMTc0ZWMtMDA5ZS00ZDEwLWFjYjctMGNmNTdhNzVmNzUz',
  296. 'info_dict': {
  297. 'id': '13847165',
  298. 'chapters': 'count:8',
  299. 'ext': 'mp4',
  300. 'channel': 'WDR',
  301. 'display_id': 'Y3JpZDovL3dkci5kZS9CZWl0cmFnLXNvcGhvcmEtOWFkMTc0ZWMtMDA5ZS00ZDEwLWFjYjctMGNmNTdhNzVmNzUz',
  302. 'episode': 'Lokalzeit aus Düsseldorf | 31.10.2024',
  303. 'series': 'Lokalzeit aus Düsseldorf',
  304. 'thumbnail': 'https://api.ardmediathek.de/image-service/images/urn:ard:image:f02ec9bd9b7bd5f6?w=960&ch=612491dcd5e09b0c',
  305. 'title': 'Lokalzeit aus Düsseldorf | 31.10.2024',
  306. 'upload_date': '20241031',
  307. 'timestamp': 1730399400,
  308. 'description': 'md5:12db30b3b706314efe3778b8df1a7058',
  309. 'duration': 1759,
  310. '_old_archive_ids': ['ardbetamediathek Y3JpZDovL3dkci5kZS9CZWl0cmFnLXNvcGhvcmEtOWFkMTc0ZWMtMDA5ZS00ZDEwLWFjYjctMGNmNTdhNzVmNzUz'],
  311. },
  312. }, {
  313. 'url': 'https://beta.ardmediathek.de/ard/video/Y3JpZDovL2Rhc2Vyc3RlLmRlL3RhdG9ydC9mYmM4NGM1NC0xNzU4LTRmZGYtYWFhZS0wYzcyZTIxNGEyMDE',
  314. 'only_matching': True,
  315. }, {
  316. 'url': 'https://ardmediathek.de/ard/video/saartalk/saartalk-gesellschaftsgift-haltung-gegen-hass/sr-fernsehen/Y3JpZDovL3NyLW9ubGluZS5kZS9TVF84MTY4MA/',
  317. 'only_matching': True,
  318. }, {
  319. 'url': 'https://www.ardmediathek.de/ard/video/trailer/private-eyes-s01-e01/one/Y3JpZDovL3dkci5kZS9CZWl0cmFnLTE1MTgwYzczLWNiMTEtNGNkMS1iMjUyLTg5MGYzOWQxZmQ1YQ/',
  320. 'only_matching': True,
  321. }, {
  322. 'url': 'https://www.ardmediathek.de/ard/player/Y3JpZDovL3N3ci5kZS9hZXgvbzEwNzE5MTU/',
  323. 'only_matching': True,
  324. }, {
  325. 'url': 'https://www.ardmediathek.de/swr/live/Y3JpZDovL3N3ci5kZS8xMzQ4MTA0Mg',
  326. 'only_matching': True,
  327. }, {
  328. 'url': 'https://www.ardmediathek.de/video/coronavirus-update-ndr-info/astrazeneca-kurz-lockdown-und-pims-syndrom-81/ndr/Y3JpZDovL25kci5kZS84NzE0M2FjNi0wMWEwLTQ5ODEtOTE5NS1mOGZhNzdhOTFmOTI/',
  329. 'only_matching': True,
  330. }]
  331. def _extract_episode_info(self, title):
  332. patterns = [
  333. # Pattern for title like "Homo sapiens (S06/E07) - Originalversion"
  334. # from: https://www.ardmediathek.de/one/sendung/doctor-who/Y3JpZDovL3dkci5kZS9vbmUvZG9jdG9yIHdobw
  335. r'.*(?P<ep_info> \(S(?P<season_number>\d+)/E(?P<episode_number>\d+)\)).*',
  336. # E.g.: title="Fritjof aus Norwegen (2) (AD)"
  337. # from: https://www.ardmediathek.de/ard/sammlung/der-krieg-und-ich/68cMkqJdllm639Skj4c7sS/
  338. r'.*(?P<ep_info> \((?:Folge |Teil )?(?P<episode_number>\d+)(?:/\d+)?\)).*',
  339. r'.*(?P<ep_info>Folge (?P<episode_number>\d+)(?:\:| -|) )\"(?P<episode>.+)\".*',
  340. # E.g.: title="Folge 25/42: Symmetrie"
  341. # from: https://www.ardmediathek.de/ard/video/grips-mathe/folge-25-42-symmetrie/ard-alpha/Y3JpZDovL2JyLmRlL3ZpZGVvLzMyYzI0ZjczLWQ1N2MtNDAxNC05ZmZhLTFjYzRkZDA5NDU5OQ/
  342. # E.g.: title="Folge 1063 - Vertrauen"
  343. # from: https://www.ardmediathek.de/ard/sendung/die-fallers/Y3JpZDovL3N3ci5kZS8yMzAyMDQ4/
  344. r'.*(?P<ep_info>Folge (?P<episode_number>\d+)(?:/\d+)?(?:\:| -|) ).*',
  345. # As a fallback use the full title
  346. r'(?P<title>.*)',
  347. ]
  348. return traverse_obj(patterns, (..., {functools.partial(re.match, string=title)}, {
  349. 'season_number': ('season_number', {int_or_none}),
  350. 'episode_number': ('episode_number', {int_or_none}),
  351. 'episode': ((
  352. ('episode', {str_or_none}),
  353. ('ep_info', {lambda x: title.replace(x, '')}),
  354. ('title', {str}),
  355. ), {str.strip}),
  356. }), get_all=False)
  357. def _real_extract(self, url):
  358. display_id = self._match_id(url)
  359. query = {'embedded': 'false', 'mcV6': 'true'}
  360. headers = {}
  361. if self._get_cookies(self._TOKEN_URL).get('ams'):
  362. token = self._download_json(
  363. self._TOKEN_URL, display_id, 'Fetching token for age verification',
  364. 'Unable to fetch age verification token', fatal=False)
  365. id_token = traverse_obj(token, ('idToken', {str}))
  366. decoded_token = traverse_obj(id_token, ({jwt_decode_hs256}, {dict}))
  367. user_id = traverse_obj(decoded_token, (('user_id', 'sub'), {str}), get_all=False)
  368. if not user_id:
  369. self.report_warning('Unable to extract token, continuing without authentication')
  370. else:
  371. headers['x-authorization'] = f'Bearer {id_token}'
  372. query['userId'] = user_id
  373. if decoded_token.get('age_rating') != 18:
  374. self.report_warning('Account is not verified as 18+; video may be unavailable')
  375. page_data = self._download_json(
  376. f'https://api.ardmediathek.de/page-gateway/pages/ard/item/{display_id}',
  377. display_id, query=query, headers=headers)
  378. # For user convenience we use the old contentId instead of the longer crid
  379. # Ref: https://github.com/yt-dlp/yt-dlp/issues/8731#issuecomment-1874398283
  380. old_id = traverse_obj(page_data, ('tracking', 'atiCustomVars', 'contentId', {int}))
  381. if old_id is not None:
  382. video_id = str(old_id)
  383. archive_ids = [make_archive_id(ARDBetaMediathekIE, display_id)]
  384. else:
  385. self.report_warning(f'Could not extract contentId{bug_reports_message()}')
  386. video_id = display_id
  387. archive_ids = None
  388. player_data = traverse_obj(
  389. page_data, ('widgets', lambda _, v: v['type'] in ('player_ondemand', 'player_live'), {dict}), get_all=False)
  390. is_live = player_data.get('type') == 'player_live'
  391. media_data = traverse_obj(player_data, ('mediaCollection', 'embedded', {dict}))
  392. if player_data.get('blockedByFsk'):
  393. self.raise_login_required('This video is only available for age verified users or after 22:00')
  394. formats = []
  395. subtitles = {}
  396. for stream in traverse_obj(media_data, ('streams', ..., {dict})):
  397. kind = stream.get('kind')
  398. # Prioritize main stream over sign language and others
  399. preference = 1 if kind == 'main' else None
  400. for media in traverse_obj(stream, ('media', lambda _, v: url_or_none(v['url']))):
  401. media_url = media['url']
  402. audio_kind = traverse_obj(media, (
  403. 'audios', 0, 'kind', {str}), default='').replace('standard', '')
  404. lang_code = traverse_obj(media, ('audios', 0, 'languageCode', {str})) or 'deu'
  405. lang = join_nonempty(lang_code, audio_kind)
  406. language_preference = 10 if lang == 'deu' else -10
  407. if determine_ext(media_url) == 'm3u8':
  408. fmts, subs = self._extract_m3u8_formats_and_subtitles(
  409. media_url, video_id, m3u8_id=f'hls-{kind}', preference=preference, fatal=False, live=is_live)
  410. for f in fmts:
  411. f['language'] = lang
  412. f['language_preference'] = language_preference
  413. formats.extend(fmts)
  414. self._merge_subtitles(subs, target=subtitles)
  415. else:
  416. formats.append({
  417. 'url': media_url,
  418. 'format_id': f'http-{kind}',
  419. 'preference': preference,
  420. 'language': lang,
  421. 'language_preference': language_preference,
  422. **traverse_obj(media, {
  423. 'format_note': ('forcedLabel', {str}),
  424. 'width': ('maxHResolutionPx', {int_or_none}),
  425. 'height': ('maxVResolutionPx', {int_or_none}),
  426. 'vcodec': ('videoCodec', {str}),
  427. }),
  428. })
  429. for sub in traverse_obj(media_data, ('subtitles', ..., {dict})):
  430. for sources in traverse_obj(sub, ('sources', lambda _, v: url_or_none(v['url']))):
  431. subtitles.setdefault(sub.get('languageCode') or 'deu', []).append({
  432. 'url': sources['url'],
  433. 'ext': {'webvtt': 'vtt', 'ebutt': 'ttml'}.get(sources.get('kind')),
  434. })
  435. age_limit = traverse_obj(page_data, ('fskRating', {lambda x: remove_start(x, 'FSK')}, {int_or_none}))
  436. return {
  437. 'id': video_id,
  438. 'display_id': display_id,
  439. 'formats': formats,
  440. 'subtitles': subtitles,
  441. 'is_live': is_live,
  442. 'age_limit': age_limit,
  443. **traverse_obj(media_data, {
  444. 'chapters': ('pluginData', 'jumpmarks@all', 'chapterArray', lambda _, v: int_or_none(v['chapterTime']), {
  445. 'start_time': ('chapterTime', {int_or_none}),
  446. 'title': ('chapterTitle', {str}),
  447. }),
  448. }),
  449. **traverse_obj(media_data, ('meta', {
  450. 'title': 'title',
  451. 'description': 'synopsis',
  452. 'timestamp': ('broadcastedOnDateTime', {parse_iso8601}),
  453. 'series': 'seriesTitle',
  454. 'thumbnail': ('images', 0, 'url', {url_or_none}),
  455. 'duration': ('durationSeconds', {int_or_none}),
  456. 'channel': 'clipSourceName',
  457. })),
  458. **self._extract_episode_info(page_data.get('title')),
  459. '_old_archive_ids': archive_ids,
  460. }
  461. class ARDMediathekCollectionIE(InfoExtractor):
  462. _VALID_URL = r'''(?x)https?://
  463. (?:(?:beta|www)\.)?ardmediathek\.de/
  464. (?:[^/?#]+/)?
  465. (?P<playlist>sendung|serie|sammlung)/
  466. (?:(?P<display_id>[^?#]+?)/)?
  467. (?P<id>[a-zA-Z0-9]+)
  468. (?:/(?P<season>\d+)(?:/(?P<version>OV|AD))?)?/?(?:[?#]|$)'''
  469. _GEO_COUNTRIES = ['DE']
  470. _TESTS = [{
  471. 'url': 'https://www.ardmediathek.de/serie/quiz/staffel-1-originalversion/Y3JpZDovL3dkci5kZS9vbmUvcXVpeg/1/OV',
  472. 'info_dict': {
  473. 'id': 'Y3JpZDovL3dkci5kZS9vbmUvcXVpeg_1_OV',
  474. 'display_id': 'quiz/staffel-1-originalversion',
  475. 'title': 'Staffel 1 Originalversion',
  476. },
  477. 'playlist_count': 3,
  478. }, {
  479. 'url': 'https://www.ardmediathek.de/serie/babylon-berlin/staffel-4-mit-audiodeskription/Y3JpZDovL2Rhc2Vyc3RlLmRlL2JhYnlsb24tYmVybGlu/4/AD',
  480. 'info_dict': {
  481. 'id': 'Y3JpZDovL2Rhc2Vyc3RlLmRlL2JhYnlsb24tYmVybGlu_4_AD',
  482. 'display_id': 'babylon-berlin/staffel-4-mit-audiodeskription',
  483. 'title': 'Staffel 4 mit Audiodeskription',
  484. },
  485. 'playlist_count': 12,
  486. }, {
  487. 'url': 'https://www.ardmediathek.de/serie/babylon-berlin/staffel-1/Y3JpZDovL2Rhc2Vyc3RlLmRlL2JhYnlsb24tYmVybGlu/1/',
  488. 'info_dict': {
  489. 'id': 'Y3JpZDovL2Rhc2Vyc3RlLmRlL2JhYnlsb24tYmVybGlu_1',
  490. 'display_id': 'babylon-berlin/staffel-1',
  491. 'title': 'Staffel 1',
  492. },
  493. 'playlist_count': 8,
  494. }, {
  495. 'url': 'https://www.ardmediathek.de/sendung/tatort/Y3JpZDovL2Rhc2Vyc3RlLmRlL3RhdG9ydA',
  496. 'info_dict': {
  497. 'id': 'Y3JpZDovL2Rhc2Vyc3RlLmRlL3RhdG9ydA',
  498. 'display_id': 'tatort',
  499. 'title': 'Tatort',
  500. },
  501. 'playlist_mincount': 500,
  502. }, {
  503. 'url': 'https://www.ardmediathek.de/sammlung/die-kirche-bleibt-im-dorf/5eOHzt8XB2sqeFXbIoJlg2',
  504. 'info_dict': {
  505. 'id': '5eOHzt8XB2sqeFXbIoJlg2',
  506. 'display_id': 'die-kirche-bleibt-im-dorf',
  507. 'title': 'Die Kirche bleibt im Dorf',
  508. 'description': 'Die Kirche bleibt im Dorf',
  509. },
  510. 'playlist_count': 4,
  511. }, {
  512. # playlist of type 'sendung'
  513. 'url': 'https://www.ardmediathek.de/ard/sendung/doctor-who/Y3JpZDovL3dkci5kZS9vbmUvZG9jdG9yIHdobw/',
  514. 'only_matching': True,
  515. }, {
  516. # playlist of type 'serie'
  517. 'url': 'https://www.ardmediathek.de/serie/nachtstreife/staffel-1/Y3JpZDovL3N3ci5kZS9zZGIvc3RJZC8xMjQy/1',
  518. 'only_matching': True,
  519. }, {
  520. # playlist of type 'sammlung'
  521. 'url': 'https://www.ardmediathek.de/ard/sammlung/team-muenster/5JpTzLSbWUAK8184IOvEir/',
  522. 'only_matching': True,
  523. }]
  524. _PAGE_SIZE = 100
  525. def _real_extract(self, url):
  526. playlist_id, display_id, playlist_type, season_number, version = self._match_valid_url(url).group(
  527. 'id', 'display_id', 'playlist', 'season', 'version')
  528. def call_api(page_num):
  529. api_path = 'compilations/ard' if playlist_type == 'sammlung' else 'widgets/ard/asset'
  530. return self._download_json(
  531. f'https://api.ardmediathek.de/page-gateway/{api_path}/{playlist_id}', playlist_id,
  532. f'Downloading playlist page {page_num}', query={
  533. 'pageNumber': page_num,
  534. 'pageSize': self._PAGE_SIZE,
  535. **({
  536. 'seasoned': 'true',
  537. 'seasonNumber': season_number,
  538. 'withOriginalversion': 'true' if version == 'OV' else 'false',
  539. 'withAudiodescription': 'true' if version == 'AD' else 'false',
  540. } if season_number else {}),
  541. })
  542. def fetch_page(page_num):
  543. for item in traverse_obj(call_api(page_num), ('teasers', ..., {dict})):
  544. item_id = traverse_obj(item, ('links', 'target', ('urlId', 'id')), 'id', get_all=False)
  545. if not item_id or item_id == playlist_id:
  546. continue
  547. item_mode = 'sammlung' if item.get('type') == 'compilation' else 'video'
  548. yield self.url_result(
  549. f'https://www.ardmediathek.de/{item_mode}/{item_id}',
  550. ie=(ARDMediathekCollectionIE if item_mode == 'sammlung' else ARDBetaMediathekIE),
  551. **traverse_obj(item, {
  552. 'id': ('id', {str}),
  553. 'title': ('longTitle', {str}),
  554. 'duration': ('duration', {int_or_none}),
  555. 'timestamp': ('broadcastedOn', {parse_iso8601}),
  556. }))
  557. page_data = call_api(0)
  558. full_id = join_nonempty(playlist_id, season_number, version, delim='_')
  559. return self.playlist_result(
  560. OnDemandPagedList(fetch_page, self._PAGE_SIZE), full_id, display_id=display_id,
  561. title=page_data.get('title'), description=page_data.get('synopsis'))