4 from .common
import InfoExtractor
22 from ..utils
.traversal
import traverse_obj
25 class ARDMediathekBaseIE(InfoExtractor
):
26 _GEO_COUNTRIES
= ['DE']
28 def _extract_media_info(self
, media_info_url
, webpage
, video_id
):
29 media_info
= self
._download
_json
(
30 media_info_url
, video_id
, 'Downloading media JSON')
31 return self
._parse
_media
_info
(media_info
, video_id
, '"fsk"' in webpage
)
33 def _parse_media_info(self
, media_info
, video_id
, fsk
):
34 formats
= self
._extract
_formats
(media_info
, video_id
)
38 self
.raise_no_formats(
39 'This video is only available after 20:00', expected
=True)
40 elif media_info
.get('_geoblocked'):
41 self
.raise_geo_restricted(
42 'This video is not available due to geoblocking',
43 countries
=self
._GEO
_COUNTRIES
, metadata_available
=True)
46 subtitle_url
= media_info
.get('_subtitleUrl')
53 'url': subtitle_url
.replace('/ebutt/', '/webvtt/') + '.vtt',
58 'duration': int_or_none(media_info
.get('_duration')),
59 'thumbnail': media_info
.get('_previewImage'),
60 'is_live': media_info
.get('_isLive') is True,
62 'subtitles': subtitles
,
65 def _extract_formats(self
, media_info
, video_id
):
66 type_
= media_info
.get('_type')
67 media_array
= media_info
.get('_mediaArray', [])
69 for num
, media
in enumerate(media_array
):
70 for stream
in media
.get('_mediaStreamArray', []):
71 stream_urls
= stream
.get('_stream')
74 if not isinstance(stream_urls
, list):
75 stream_urls
= [stream_urls
]
76 quality
= stream
.get('_quality')
77 server
= stream
.get('_server')
78 for stream_url
in stream_urls
:
79 if not url_or_none(stream_url
):
81 ext
= determine_ext(stream_url
)
82 if quality
!= 'auto' and ext
in ('f4m', 'm3u8'):
85 formats
.extend(self
._extract
_f
4m
_formats
(
86 update_url_query(stream_url
, {
88 'plugin': 'aasp-3.1.1.69.124',
89 }), video_id
, f4m_id
='hds', fatal
=False))
91 formats
.extend(self
._extract
_m
3u8_formats
(
92 stream_url
, video_id
, 'mp4', 'm3u8_native',
93 m3u8_id
='hls', fatal
=False))
95 if server
and server
.startswith('rtmp'):
98 'play_path': stream_url
,
99 'format_id': f
'a{num}-rtmp-{quality}',
104 'format_id': f
'a{num}-{ext}-{quality}',
107 r
'_(?P<width>\d+)x(?P<height>\d+)\.mp4$',
111 'width': int(m
.group('width')),
112 'height': int(m
.group('height')),
120 class ARDIE(InfoExtractor
):
121 _VALID_URL
= r
'(?P<mainurl>https?://(?:www\.)?daserste\.de/(?:[^/?#&]+/)+(?P<id>[^/?#&]+))\.html'
123 # available till 7.12.2023
124 'url': 'https://www.daserste.de/information/talk/maischberger/videos/maischberger-video-424.html',
125 'md5': '94812e6438488fb923c361a44469614b',
127 'id': 'maischberger-video-424',
128 'display_id': 'maischberger-video-424',
131 'title': 'maischberger am 07.12.2022',
132 'upload_date': '20221207',
133 'thumbnail': r
're:^https?://.*\.jpg$',
136 'url': 'https://www.daserste.de/information/politik-weltgeschehen/morgenmagazin/videosextern/dominik-kahun-aus-der-nhl-direkt-zur-weltmeisterschaft-100.html',
137 'only_matching': True,
139 'url': 'https://www.daserste.de/information/nachrichten-wetter/tagesthemen/videosextern/tagesthemen-17736.html',
140 'only_matching': True,
142 'url': 'https://www.daserste.de/unterhaltung/serie/in-aller-freundschaft-die-jungen-aerzte/videos/diversity-tag-sanam-afrashteh100.html',
143 'only_matching': True,
145 'url': 'http://www.daserste.de/information/reportage-dokumentation/dokus/videos/die-story-im-ersten-mission-unter-falscher-flagge-100.html',
146 'only_matching': True,
148 'url': 'https://www.daserste.de/unterhaltung/serie/in-aller-freundschaft-die-jungen-aerzte/Drehpause-100.html',
149 'only_matching': True,
151 'url': 'https://www.daserste.de/unterhaltung/film/filmmittwoch-im-ersten/videos/making-ofwendezeit-video-100.html',
152 'only_matching': True,
155 def _real_extract(self
, url
):
156 mobj
= self
._match
_valid
_url
(url
)
157 display_id
= mobj
.group('id')
159 player_url
= mobj
.group('mainurl') + '~playerXml.xml'
160 doc
= self
._download
_xml
(player_url
, display_id
)
161 video_node
= doc
.find('./video')
162 upload_date
= unified_strdate(xpath_text(
163 video_node
, './broadcastDate'))
164 thumbnail
= xpath_text(video_node
, './/teaserImage//variant/url')
167 for a
in video_node
.findall('.//asset'):
168 file_name
= xpath_text(a
, './fileName', default
=None)
171 format_type
= a
.attrib
.get('type')
172 format_url
= url_or_none(file_name
)
174 ext
= determine_ext(file_name
)
176 formats
.extend(self
._extract
_m
3u8_formats
(
177 format_url
, display_id
, 'mp4', entry_protocol
='m3u8_native',
178 m3u8_id
=format_type
or 'hls', fatal
=False))
181 formats
.extend(self
._extract
_f
4m
_formats
(
182 update_url_query(format_url
, {'hdcore': '3.7.0'}),
183 display_id
, f4m_id
=format_type
or 'hds', fatal
=False))
186 'format_id': format_type
,
187 'width': int_or_none(xpath_text(a
, './frameWidth')),
188 'height': int_or_none(xpath_text(a
, './frameHeight')),
189 'vbr': int_or_none(xpath_text(a
, './bitrateVideo')),
190 'abr': int_or_none(xpath_text(a
, './bitrateAudio')),
191 'vcodec': xpath_text(a
, './codecVideo'),
192 'tbr': int_or_none(xpath_text(a
, './totalBitrate')),
194 server_prefix
= xpath_text(a
, './serverPrefix', default
=None)
197 'url': server_prefix
,
198 'playpath': file_name
,
203 f
['url'] = format_url
207 ('./dataTimedText', 'ttml'),
208 ('./dataTimedTextNoOffset', 'ttml'),
209 ('./dataTimedTextVtt', 'vtt'),
213 for subsel
, subext
in _SUB_FORMATS
:
214 for node
in video_node
.findall(subsel
):
215 subtitles
.setdefault('de', []).append({
216 'url': node
.attrib
['url'],
221 'id': xpath_text(video_node
, './videoId', default
=display_id
),
223 'subtitles': subtitles
,
224 'display_id': display_id
,
225 'title': video_node
.find('./title').text
,
226 'duration': parse_duration(video_node
.find('./duration').text
),
227 'upload_date': upload_date
,
228 'thumbnail': thumbnail
,
232 class ARDBetaMediathekIE(InfoExtractor
):
233 IE_NAME
= 'ARDMediathek'
234 _VALID_URL
= r
'''(?x)https?://
235 (?:(?:beta|www)\.)?ardmediathek\.de/
237 (?:player|live|video)/
241 _GEO_COUNTRIES
= ['DE']
242 _TOKEN_URL
= 'https://sso.ardmediathek.de/sso/token'
245 'url': 'https://www.ardmediathek.de/video/filme-im-mdr/liebe-auf-vier-pfoten/mdr-fernsehen/Y3JpZDovL21kci5kZS9zZW5kdW5nLzI4MjA0MC80MjIwOTEtNDAyNTM0',
246 'md5': 'b6e8ab03f2bcc6e1f9e6cef25fcc03c4',
248 'display_id': 'Y3JpZDovL21kci5kZS9zZW5kdW5nLzI4MjA0MC80MjIwOTEtNDAyNTM0',
250 'title': 'Liebe auf vier Pfoten',
251 'description': r
're:^Claudia Schmitt, Anwältin in Salzburg',
253 'thumbnail': 'https://api.ardmediathek.de/image-service/images/urn:ard:image:aee7cbf8f06de976?w=960&ch=ae4d0f2ee47d8b9b',
254 'timestamp': 1701343800,
255 'upload_date': '20231130',
257 'episode': 'Liebe auf vier Pfoten',
258 'series': 'Filme im MDR',
261 '_old_archive_ids': ['ardbetamediathek Y3JpZDovL21kci5kZS9zZW5kdW5nLzI4MjA0MC80MjIwOTEtNDAyNTM0'],
264 'url': 'https://www.ardmediathek.de/mdr/video/die-robuste-roswita/Y3JpZDovL21kci5kZS9iZWl0cmFnL2Ntcy84MWMxN2MzZC0wMjkxLTRmMzUtODk4ZS0wYzhlOWQxODE2NGI/',
265 'md5': 'a1dc75a39c61601b980648f7c9f9f71d',
267 'display_id': 'die-robuste-roswita',
269 'title': 'Die robuste Roswita',
270 'description': r
're:^Der Mord.*totgeglaubte Ehefrau Roswita',
272 'thumbnail': 'https://img.ardmediathek.de/standard/00/78/56/67/84/575672121/16x9/960?mandant=ard',
273 'timestamp': 1596658200,
274 'upload_date': '20200805',
279 'url': 'https://www.ardmediathek.de/video/tagesschau-oder-tagesschau-20-00-uhr/das-erste/Y3JpZDovL2Rhc2Vyc3RlLmRlL3RhZ2Vzc2NoYXUvZmM4ZDUxMjgtOTE0ZC00Y2MzLTgzNzAtNDZkNGNiZWJkOTll',
280 'md5': '1e73ded21cb79bac065117e80c81dc88',
284 'title': 'tagesschau, 20:00 Uhr',
285 'timestamp': 1636398000,
286 'description': 'md5:39578c7b96c9fe50afdf5674ad985e6b',
287 'upload_date': '20211108',
288 'display_id': 'Y3JpZDovL2Rhc2Vyc3RlLmRlL3RhZ2Vzc2NoYXUvZmM4ZDUxMjgtOTE0ZC00Y2MzLTgzNzAtNDZkNGNiZWJkOTll',
290 'episode': 'tagesschau, 20:00 Uhr',
291 'series': 'tagesschau',
292 'thumbnail': 'https://api.ardmediathek.de/image-service/images/urn:ard:image:fbb21142783b0a49?w=960&ch=ee69108ae344f678',
293 'channel': 'ARD-Aktuell',
294 '_old_archive_ids': ['ardbetamediathek Y3JpZDovL2Rhc2Vyc3RlLmRlL3RhZ2Vzc2NoYXUvZmM4ZDUxMjgtOTE0ZC00Y2MzLTgzNzAtNDZkNGNiZWJkOTll'],
297 'url': 'https://www.ardmediathek.de/video/7-tage/7-tage-unter-harten-jungs/hr-fernsehen/N2I2YmM5MzgtNWFlOS00ZGFlLTg2NzMtYzNjM2JlNjk4MDg3',
298 'md5': 'c428b9effff18ff624d4f903bda26315',
303 'episode': '7 Tage ... unter harten Jungs',
304 'description': 'md5:0f215470dcd2b02f59f4bd10c963f072',
305 'upload_date': '20231005',
306 'timestamp': 1696491171,
307 'display_id': 'N2I2YmM5MzgtNWFlOS00ZGFlLTg2NzMtYzNjM2JlNjk4MDg3',
308 'series': '7 Tage ...',
310 'thumbnail': 'https://api.ardmediathek.de/image-service/images/urn:ard:image:430c86d233afa42d?w=960&ch=fa32ba69bc87989a',
311 'title': '7 Tage ... unter harten Jungs',
312 '_old_archive_ids': ['ardbetamediathek N2I2YmM5MzgtNWFlOS00ZGFlLTg2NzMtYzNjM2JlNjk4MDg3'],
315 'url': 'https://www.ardmediathek.de/video/lokalzeit-aus-duesseldorf/lokalzeit-aus-duesseldorf-oder-31-10-2024/wdr-duesseldorf/Y3JpZDovL3dkci5kZS9CZWl0cmFnLXNvcGhvcmEtOWFkMTc0ZWMtMDA5ZS00ZDEwLWFjYjctMGNmNTdhNzVmNzUz',
318 'chapters': 'count:8',
321 'display_id': 'Y3JpZDovL3dkci5kZS9CZWl0cmFnLXNvcGhvcmEtOWFkMTc0ZWMtMDA5ZS00ZDEwLWFjYjctMGNmNTdhNzVmNzUz',
322 'episode': 'Lokalzeit aus Düsseldorf | 31.10.2024',
323 'series': 'Lokalzeit aus Düsseldorf',
324 'thumbnail': 'https://api.ardmediathek.de/image-service/images/urn:ard:image:f02ec9bd9b7bd5f6?w=960&ch=612491dcd5e09b0c',
325 'title': 'Lokalzeit aus Düsseldorf | 31.10.2024',
326 'upload_date': '20241031',
327 'timestamp': 1730399400,
328 'description': 'md5:12db30b3b706314efe3778b8df1a7058',
330 '_old_archive_ids': ['ardbetamediathek Y3JpZDovL3dkci5kZS9CZWl0cmFnLXNvcGhvcmEtOWFkMTc0ZWMtMDA5ZS00ZDEwLWFjYjctMGNmNTdhNzVmNzUz'],
333 'url': 'https://beta.ardmediathek.de/ard/video/Y3JpZDovL2Rhc2Vyc3RlLmRlL3RhdG9ydC9mYmM4NGM1NC0xNzU4LTRmZGYtYWFhZS0wYzcyZTIxNGEyMDE',
334 'only_matching': True,
336 'url': 'https://ardmediathek.de/ard/video/saartalk/saartalk-gesellschaftsgift-haltung-gegen-hass/sr-fernsehen/Y3JpZDovL3NyLW9ubGluZS5kZS9TVF84MTY4MA/',
337 'only_matching': True,
339 'url': 'https://www.ardmediathek.de/ard/video/trailer/private-eyes-s01-e01/one/Y3JpZDovL3dkci5kZS9CZWl0cmFnLTE1MTgwYzczLWNiMTEtNGNkMS1iMjUyLTg5MGYzOWQxZmQ1YQ/',
340 'only_matching': True,
342 'url': 'https://www.ardmediathek.de/ard/player/Y3JpZDovL3N3ci5kZS9hZXgvbzEwNzE5MTU/',
343 'only_matching': True,
345 'url': 'https://www.ardmediathek.de/swr/live/Y3JpZDovL3N3ci5kZS8xMzQ4MTA0Mg',
346 'only_matching': True,
348 'url': 'https://www.ardmediathek.de/video/coronavirus-update-ndr-info/astrazeneca-kurz-lockdown-und-pims-syndrom-81/ndr/Y3JpZDovL25kci5kZS84NzE0M2FjNi0wMWEwLTQ5ODEtOTE5NS1mOGZhNzdhOTFmOTI/',
349 'only_matching': True,
352 def _extract_episode_info(self
, title
):
354 # Pattern for title like "Homo sapiens (S06/E07) - Originalversion"
355 # from: https://www.ardmediathek.de/one/sendung/doctor-who/Y3JpZDovL3dkci5kZS9vbmUvZG9jdG9yIHdobw
356 r
'.*(?P<ep_info> \(S(?P<season_number>\d+)/E(?P<episode_number>\d+)\)).*',
357 # E.g.: title="Fritjof aus Norwegen (2) (AD)"
358 # from: https://www.ardmediathek.de/ard/sammlung/der-krieg-und-ich/68cMkqJdllm639Skj4c7sS/
359 r
'.*(?P<ep_info> \((?:Folge |Teil )?(?P<episode_number>\d+)(?:/\d+)?\)).*',
360 r
'.*(?P<ep_info>Folge (?P<episode_number>\d+)(?:\:| -|) )\"(?P<episode>.+)\".*',
361 # E.g.: title="Folge 25/42: Symmetrie"
362 # from: https://www.ardmediathek.de/ard/video/grips-mathe/folge-25-42-symmetrie/ard-alpha/Y3JpZDovL2JyLmRlL3ZpZGVvLzMyYzI0ZjczLWQ1N2MtNDAxNC05ZmZhLTFjYzRkZDA5NDU5OQ/
363 # E.g.: title="Folge 1063 - Vertrauen"
364 # from: https://www.ardmediathek.de/ard/sendung/die-fallers/Y3JpZDovL3N3ci5kZS8yMzAyMDQ4/
365 r
'.*(?P<ep_info>Folge (?P<episode_number>\d+)(?:/\d+)?(?:\:| -|) ).*',
366 # As a fallback use the full title
370 return traverse_obj(patterns
, (..., {functools
.partial(re
.match
, string
=title
)}, {
371 'season_number': ('season_number', {int_or_none}
),
372 'episode_number': ('episode_number', {int_or_none}
),
374 ('episode', {str_or_none}
),
375 ('ep_info', {lambda x
: title
.replace(x
, '')}),
380 def _real_extract(self
, url
):
381 display_id
= self
._match
_id
(url
)
382 query
= {'embedded': 'false', 'mcV6': 'true'}
385 if self
._get
_cookies
(self
._TOKEN
_URL
).get('ams'):
386 token
= self
._download
_json
(
387 self
._TOKEN
_URL
, display_id
, 'Fetching token for age verification',
388 'Unable to fetch age verification token', fatal
=False)
389 id_token
= traverse_obj(token
, ('idToken', {str}
))
390 decoded_token
= traverse_obj(id_token
, ({jwt_decode_hs256}
, {dict}
))
391 user_id
= traverse_obj(decoded_token
, (('user_id', 'sub'), {str}
), get_all
=False)
393 self
.report_warning('Unable to extract token, continuing without authentication')
395 headers
['x-authorization'] = f
'Bearer {id_token}'
396 query
['userId'] = user_id
397 if decoded_token
.get('age_rating') != 18:
398 self
.report_warning('Account is not verified as 18+; video may be unavailable')
400 page_data
= self
._download
_json
(
401 f
'https://api.ardmediathek.de/page-gateway/pages/ard/item/{display_id}',
402 display_id
, query
=query
, headers
=headers
)
404 # For user convenience we use the old contentId instead of the longer crid
405 # Ref: https://github.com/yt-dlp/yt-dlp/issues/8731#issuecomment-1874398283
406 old_id
= traverse_obj(page_data
, ('tracking', 'atiCustomVars', 'contentId', {int}
))
407 if old_id
is not None:
408 video_id
= str(old_id
)
409 archive_ids
= [make_archive_id(ARDBetaMediathekIE
, display_id
)]
411 self
.report_warning(f
'Could not extract contentId{bug_reports_message()}')
412 video_id
= display_id
415 player_data
= traverse_obj(
416 page_data
, ('widgets', lambda _
, v
: v
['type'] in ('player_ondemand', 'player_live'), {dict}
), get_all
=False)
417 is_live
= player_data
.get('type') == 'player_live'
418 media_data
= traverse_obj(player_data
, ('mediaCollection', 'embedded', {dict}
))
420 if player_data
.get('blockedByFsk'):
421 self
.raise_login_required('This video is only available for age verified users or after 22:00')
425 for stream
in traverse_obj(media_data
, ('streams', ..., {dict}
)):
426 kind
= stream
.get('kind')
427 # Prioritize main stream over sign language and others
428 preference
= 1 if kind
== 'main' else None
429 for media
in traverse_obj(stream
, ('media', lambda _
, v
: url_or_none(v
['url']))):
430 media_url
= media
['url']
432 audio_kind
= traverse_obj(media
, (
433 'audios', 0, 'kind', {str}
), default
='').replace('standard', '')
434 lang_code
= traverse_obj(media
, ('audios', 0, 'languageCode', {str}
)) or 'deu'
435 lang
= join_nonempty(lang_code
, audio_kind
)
436 language_preference
= 10 if lang
== 'deu' else -10
438 if determine_ext(media_url
) == 'm3u8':
439 fmts
, subs
= self
._extract
_m
3u8_formats
_and
_subtitles
(
440 media_url
, video_id
, m3u8_id
=f
'hls-{kind}', preference
=preference
, fatal
=False, live
=is_live
)
443 f
['language_preference'] = language_preference
445 self
._merge
_subtitles
(subs
, target
=subtitles
)
449 'format_id': f
'http-{kind}',
450 'preference': preference
,
452 'language_preference': language_preference
,
453 **traverse_obj(media
, {
454 'format_note': ('forcedLabel', {str}
),
455 'width': ('maxHResolutionPx', {int_or_none}
),
456 'height': ('maxVResolutionPx', {int_or_none}
),
457 'vcodec': ('videoCodec', {str}
),
461 for sub
in traverse_obj(media_data
, ('subtitles', ..., {dict}
)):
462 for sources
in traverse_obj(sub
, ('sources', lambda _
, v
: url_or_none(v
['url']))):
463 subtitles
.setdefault(sub
.get('languageCode') or 'deu', []).append({
464 'url': sources
['url'],
465 'ext': {'webvtt': 'vtt', 'ebutt': 'ttml'}.get(sources
.get('kind')),
468 age_limit
= traverse_obj(page_data
, ('fskRating', {lambda x
: remove_start(x
, 'FSK')}, {int_or_none}
))
471 'display_id': display_id
,
473 'subtitles': subtitles
,
475 'age_limit': age_limit
,
476 **traverse_obj(media_data
, {
477 'chapters': ('pluginData', 'jumpmarks@all', 'chapterArray', lambda _
, v
: int_or_none(v
['chapterTime']), {
478 'start_time': ('chapterTime', {int_or_none}
),
479 'title': ('chapterTitle', {str}
),
482 **traverse_obj(media_data
, ('meta', {
484 'description': 'synopsis',
485 'timestamp': ('broadcastedOnDateTime', {parse_iso8601}
),
486 'series': 'seriesTitle',
487 'thumbnail': ('images', 0, 'url', {url_or_none}
),
488 'duration': ('durationSeconds', {int_or_none}
),
489 'channel': 'clipSourceName',
491 **self
._extract
_episode
_info
(page_data
.get('title')),
492 '_old_archive_ids': archive_ids
,
496 class ARDMediathekCollectionIE(InfoExtractor
):
497 _VALID_URL
= r
'''(?x)https?://
498 (?:(?:beta|www)\.)?ardmediathek\.de/
500 (?P<playlist>sendung|serie|sammlung)/
501 (?:(?P<display_id>[^?#]+?)/)?
503 (?:/(?P<season>\d+)(?:/(?P<version>OV|AD))?)?/?(?:[?#]|$)'''
504 _GEO_COUNTRIES
= ['DE']
507 'url': 'https://www.ardmediathek.de/serie/quiz/staffel-1-originalversion/Y3JpZDovL3dkci5kZS9vbmUvcXVpeg/1/OV',
509 'id': 'Y3JpZDovL3dkci5kZS9vbmUvcXVpeg_1_OV',
510 'display_id': 'quiz/staffel-1-originalversion',
511 'title': 'Staffel 1 Originalversion',
515 'url': 'https://www.ardmediathek.de/serie/babylon-berlin/staffel-4-mit-audiodeskription/Y3JpZDovL2Rhc2Vyc3RlLmRlL2JhYnlsb24tYmVybGlu/4/AD',
517 'id': 'Y3JpZDovL2Rhc2Vyc3RlLmRlL2JhYnlsb24tYmVybGlu_4_AD',
518 'display_id': 'babylon-berlin/staffel-4-mit-audiodeskription',
519 'title': 'Staffel 4 mit Audiodeskription',
521 'playlist_count': 12,
523 'url': 'https://www.ardmediathek.de/serie/babylon-berlin/staffel-1/Y3JpZDovL2Rhc2Vyc3RlLmRlL2JhYnlsb24tYmVybGlu/1/',
525 'id': 'Y3JpZDovL2Rhc2Vyc3RlLmRlL2JhYnlsb24tYmVybGlu_1',
526 'display_id': 'babylon-berlin/staffel-1',
527 'title': 'Staffel 1',
531 'url': 'https://www.ardmediathek.de/sendung/tatort/Y3JpZDovL2Rhc2Vyc3RlLmRlL3RhdG9ydA',
533 'id': 'Y3JpZDovL2Rhc2Vyc3RlLmRlL3RhdG9ydA',
534 'display_id': 'tatort',
537 'playlist_mincount': 500,
539 'url': 'https://www.ardmediathek.de/sammlung/die-kirche-bleibt-im-dorf/5eOHzt8XB2sqeFXbIoJlg2',
541 'id': '5eOHzt8XB2sqeFXbIoJlg2',
542 'display_id': 'die-kirche-bleibt-im-dorf',
543 'title': 'Die Kirche bleibt im Dorf',
544 'description': 'Die Kirche bleibt im Dorf',
548 # playlist of type 'sendung'
549 'url': 'https://www.ardmediathek.de/ard/sendung/doctor-who/Y3JpZDovL3dkci5kZS9vbmUvZG9jdG9yIHdobw/',
550 'only_matching': True,
552 # playlist of type 'serie'
553 'url': 'https://www.ardmediathek.de/serie/nachtstreife/staffel-1/Y3JpZDovL3N3ci5kZS9zZGIvc3RJZC8xMjQy/1',
554 'only_matching': True,
556 # playlist of type 'sammlung'
557 'url': 'https://www.ardmediathek.de/ard/sammlung/team-muenster/5JpTzLSbWUAK8184IOvEir/',
558 'only_matching': True,
563 def _real_extract(self
, url
):
564 playlist_id
, display_id
, playlist_type
, season_number
, version
= self
._match
_valid
_url
(url
).group(
565 'id', 'display_id', 'playlist', 'season', 'version')
567 def call_api(page_num
):
568 api_path
= 'compilations/ard' if playlist_type
== 'sammlung' else 'widgets/ard/asset'
569 return self
._download
_json
(
570 f
'https://api.ardmediathek.de/page-gateway/{api_path}/{playlist_id}', playlist_id
,
571 f
'Downloading playlist page {page_num}', query
={
572 'pageNumber': page_num
,
573 'pageSize': self
._PAGE
_SIZE
,
576 'seasonNumber': season_number
,
577 'withOriginalversion': 'true' if version
== 'OV' else 'false',
578 'withAudiodescription': 'true' if version
== 'AD' else 'false',
579 } if season_number
else {}),
582 def fetch_page(page_num
):
583 for item
in traverse_obj(call_api(page_num
), ('teasers', ..., {dict}
)):
584 item_id
= traverse_obj(item
, ('links', 'target', ('urlId', 'id')), 'id', get_all
=False)
585 if not item_id
or item_id
== playlist_id
:
587 item_mode
= 'sammlung' if item
.get('type') == 'compilation' else 'video'
588 yield self
.url_result(
589 f
'https://www.ardmediathek.de/{item_mode}/{item_id}',
590 ie
=(ARDMediathekCollectionIE
if item_mode
== 'sammlung' else ARDBetaMediathekIE
),
591 **traverse_obj(item
, {
593 'title': ('longTitle', {str}
),
594 'duration': ('duration', {int_or_none}
),
595 'timestamp': ('broadcastedOn', {parse_iso8601}
),
598 page_data
= call_api(0)
599 full_id
= join_nonempty(playlist_id
, season_number
, version
, delim
='_')
601 return self
.playlist_result(
602 OnDemandPagedList(fetch_page
, self
._PAGE
_SIZE
), full_id
, display_id
=display_id
,
603 title
=page_data
.get('title'), description
=page_data
.get('synopsis'))