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