2 from __future__ import unicode_literals
6 from .common import InfoExtractor
7 from ..compat import compat_str
26 class ZDFBaseIE(InfoExtractor):
27 _GEO_COUNTRIES = ['DE']
28 _QUALITIES = ('auto', 'low', 'med', 'high', 'veryhigh', 'hd')
30 def _call_api(self, url, video_id, item, api_token=None, referrer=None):
33 headers['Api-Auth'] = 'Bearer %s' % api_token
35 headers['Referer'] = referrer
36 return self._download_json(
37 url, video_id, 'Downloading JSON %s' % item, headers=headers)
40 def _extract_subtitles(src):
42 for caption in try_get(src, lambda x: x['captions'], list) or []:
43 subtitle_url = url_or_none(caption.get('uri'))
45 lang = caption.get('language', 'deu')
46 subtitles.setdefault(lang, []).append({
51 def _extract_format(self, video_id, formats, format_urls, meta):
52 format_url = url_or_none(meta.get('url'))
55 if format_url in format_urls:
57 format_urls.add(format_url)
58 mime_type = meta.get('mimeType')
59 ext = determine_ext(format_url)
60 if mime_type == 'application/x-mpegURL' or ext == 'm3u8':
61 formats.extend(self._extract_m3u8_formats(
62 format_url, video_id, 'mp4', m3u8_id='hls',
63 entry_protocol='m3u8_native', fatal=False))
64 elif mime_type == 'application/f4m+xml' or ext == 'f4m':
65 formats.extend(self._extract_f4m_formats(
66 update_url_query(format_url, {'hdcore': '3.7.0'}), video_id, f4m_id='hds', fatal=False))
68 f = parse_codecs(meta.get('mimeCodec'))
70 for p in (meta.get('type'), meta.get('quality')):
71 if p and isinstance(p, compat_str):
75 'format_id': '-'.join(format_id),
76 'format_note': meta.get('quality'),
77 'language': meta.get('language'),
78 'quality': qualities(self._QUALITIES)(meta.get('quality')),
83 def _extract_ptmd(self, ptmd_url, video_id, api_token, referrer):
84 ptmd = self._call_api(
85 ptmd_url, video_id, 'metadata', api_token, referrer)
87 content_id = ptmd.get('basename') or ptmd_url.split('/')[-1]
91 for p in ptmd['priorityList']:
92 formitaeten = p.get('formitaeten')
93 if not isinstance(formitaeten, list):
96 f_qualities = f.get('qualities')
97 if not isinstance(f_qualities, list):
99 for quality in f_qualities:
100 tracks = try_get(quality, lambda x: x['audio']['tracks'], list)
104 self._extract_format(
105 content_id, formats, track_uris, {
106 'url': track.get('uri'),
107 'type': f.get('type'),
108 'mimeType': f.get('mimeType'),
109 'quality': quality.get('quality'),
110 'language': track.get('language'),
112 self._sort_formats(formats)
114 duration = float_or_none(try_get(
115 ptmd, lambda x: x['attributes']['duration']['value']), scale=1000)
118 'extractor_key': ZDFIE.ie_key(),
120 'duration': duration,
122 'subtitles': self._extract_subtitles(ptmd),
125 def _extract_player(self, webpage, video_id, fatal=True):
126 return self._parse_json(
128 r'(?s)data-zdfplayer-jsb=(["\'])(?P<json>{.+?})\1', webpage,
129 'player JSON', default='{}' if not fatal else NO_DEFAULT,
134 class ZDFIE(ZDFBaseIE):
135 _VALID_URL = r'https?://www\.zdf\.de/(?:[^/]+/)*(?P<id>[^/?#&]+)\.html'
137 # Same as https://www.phoenix.de/sendungen/ereignisse/corona-nachgehakt/wohin-fuehrt-der-protest-in-der-pandemie-a-2050630.html
138 'url': 'https://www.zdf.de/politik/phoenix-sendungen/wohin-fuehrt-der-protest-in-der-pandemie-100.html',
139 'md5': '34ec321e7eb34231fd88616c65c92db0',
141 'id': '210222_phx_nachgehakt_corona_protest',
143 'title': 'Wohin führt der Protest in der Pandemie?',
144 'description': 'md5:7d643fe7f565e53a24aac036b2122fbd',
146 'timestamp': 1613948400,
147 'upload_date': '20210221',
149 'skip': 'No longer available: "Diese Seite wurde leider nicht gefunden"',
151 # Same as https://www.3sat.de/film/ab-18/10-wochen-sommer-108.html
152 'url': 'https://www.zdf.de/dokumentation/ab-18/10-wochen-sommer-102.html',
153 'md5': '0aff3e7bc72c8813f5e0fae333316a1d',
155 'id': '141007_ab18_10wochensommer_film',
157 'title': 'Ab 18! - 10 Wochen Sommer',
158 'description': 'md5:8253f41dc99ce2c3ff892dac2d65fe26',
160 'timestamp': 1608604200,
161 'upload_date': '20201222',
163 'skip': 'No longer available: "Diese Seite wurde leider nicht gefunden"',
165 'url': 'https://www.zdf.de/dokumentation/terra-x/die-magie-der-farben-von-koenigspurpur-und-jeansblau-100.html',
167 'id': '151025_magie_farben2_tex',
169 'title': 'Die Magie der Farben (2/2)',
170 'description': 'md5:a89da10c928c6235401066b60a6d5c1a',
172 'timestamp': 1465021200,
173 'upload_date': '20160604',
176 # Same as https://www.phoenix.de/sendungen/dokumentationen/gesten-der-maechtigen-i-a-89468.html?ref=suche
177 'url': 'https://www.zdf.de/politik/phoenix-sendungen/die-gesten-der-maechtigen-100.html',
178 'only_matching': True,
180 # Same as https://www.3sat.de/film/spielfilm/der-hauptmann-100.html
181 'url': 'https://www.zdf.de/filme/filme-sonstige/der-hauptmann-112.html',
182 'only_matching': True,
184 # Same as https://www.3sat.de/wissen/nano/nano-21-mai-2019-102.html, equal media ids
185 'url': 'https://www.zdf.de/wissen/nano/nano-21-mai-2019-102.html',
186 'only_matching': True,
188 'url': 'https://www.zdf.de/service-und-hilfe/die-neue-zdf-mediathek/zdfmediathek-trailer-100.html',
189 'only_matching': True,
191 'url': 'https://www.zdf.de/filme/taunuskrimi/die-lebenden-und-die-toten-1---ein-taunuskrimi-100.html',
192 'only_matching': True,
194 'url': 'https://www.zdf.de/dokumentation/planet-e/planet-e-uebersichtsseite-weitere-dokumentationen-von-planet-e-100.html',
195 'only_matching': True,
197 'url': 'https://www.zdf.de/arte/todliche-flucht/page-video-artede-toedliche-flucht-16-100.html',
199 'id': 'video_artede_083871-001-A',
201 'title': 'Tödliche Flucht (1/6)',
202 'description': 'md5:e34f96a9a5f8abd839ccfcebad3d5315',
204 'timestamp': 1641355200,
205 'upload_date': '20220105',
209 def _extract_entry(self, url, player, content, video_id):
210 title = content.get('title') or content['teaserHeadline']
212 t = content['mainVideoContent']['http://zdf.de/rels/target']
214 def get_ptmd_path(d):
216 d.get('http://zdf.de/rels/streams/ptmd')
217 or d.get('http://zdf.de/rels/streams/ptmd-template',
218 '').replace('{playerId}', 'ngplayer_2_4'))
220 ptmd_path = get_ptmd_path(try_get(t, lambda x: x['streams']['default'], dict) or {})
222 ptmd_path = get_ptmd_path(t)
225 raise ExtractorError('Could not extract ptmd_path')
227 info = self._extract_ptmd(
228 urljoin(url, ptmd_path), video_id, player['apiToken'], url)
232 content, lambda x: x['teaserImageRef']['layouts'], dict)
234 for layout_key, layout_url in layouts.items():
235 layout_url = url_or_none(layout_url)
240 'format_id': layout_key,
242 mobj = re.search(r'(?P<width>\d+)x(?P<height>\d+)', layout_key)
245 'width': int(mobj.group('width')),
246 'height': int(mobj.group('height')),
248 thumbnails.append(thumbnail)
250 return merge_dicts(info, {
252 'description': content.get('leadParagraph') or content.get('teasertext'),
253 'duration': int_or_none(t.get('duration')),
254 'timestamp': unified_timestamp(content.get('editorialDate')),
255 'thumbnails': thumbnails,
258 def _extract_regular(self, url, player, video_id):
259 content = self._call_api(
260 player['content'], video_id, 'content', player['apiToken'], url)
261 return self._extract_entry(player['content'], player, content, video_id)
263 def _extract_mobile(self, video_id):
264 video = self._download_json(
265 'https://zdf-cdn.live.cellular.de/mediathekV2/document/%s' % video_id,
268 document = video['document']
270 title = document['titel']
271 content_id = document['basename']
275 for f in document['formitaeten']:
276 self._extract_format(content_id, formats, format_urls, f)
277 self._sort_formats(formats)
280 teaser_bild = document.get('teaserBild')
281 if isinstance(teaser_bild, dict):
282 for thumbnail_key, thumbnail in teaser_bild.items():
283 thumbnail_url = try_get(
284 thumbnail, lambda x: x['url'], compat_str)
287 'url': thumbnail_url,
289 'width': int_or_none(thumbnail.get('width')),
290 'height': int_or_none(thumbnail.get('height')),
296 'description': document.get('beschreibung'),
297 'duration': int_or_none(document.get('length')),
298 'timestamp': unified_timestamp(document.get('date')) or unified_timestamp(
299 try_get(video, lambda x: x['meta']['editorialDate'], compat_str)),
300 'thumbnails': thumbnails,
301 'subtitles': self._extract_subtitles(document),
305 def _real_extract(self, url):
306 video_id = self._match_id(url)
308 webpage = self._download_webpage(url, video_id, fatal=False)
310 player = self._extract_player(webpage, url, fatal=False)
312 return self._extract_regular(url, player, video_id)
314 return self._extract_mobile(video_id)
317 class ZDFChannelIE(ZDFBaseIE):
318 _VALID_URL = r'https?://www\.zdf\.de/(?:[^/]+/)*(?P<id>[^/?#&]+)'
320 'url': 'https://www.zdf.de/sport/das-aktuelle-sportstudio',
322 'id': 'das-aktuelle-sportstudio',
323 'title': 'das aktuelle sportstudio | ZDF',
325 'playlist_mincount': 23,
327 'url': 'https://www.zdf.de/dokumentation/planet-e',
330 'title': 'planet e.',
332 'playlist_mincount': 50,
334 'url': 'https://www.zdf.de/filme/taunuskrimi/',
335 'only_matching': True,
339 def suitable(cls, url):
340 return False if ZDFIE.suitable(url) else super(ZDFChannelIE, cls).suitable(url)
342 def _real_extract(self, url):
343 channel_id = self._match_id(url)
345 webpage = self._download_webpage(url, channel_id)
348 self.url_result(item_url, ie=ZDFIE.ie_key())
349 for item_url in orderedSet(re.findall(
350 r'data-plusbar-url=["\'](http.+?\.html)', webpage))]
352 return self.playlist_result(
353 entries, channel_id, self._og_search_title(webpage, fatal=False))
356 player = self._extract_player(webpage, channel_id)
358 channel_id = self._search_regex(
359 r'docId\s*:\s*(["\'])(?P<id>(?!\1).+?)\1', webpage,
360 'channel id', group='id')
362 channel = self._call_api(
363 'https://api.zdf.de/content/documents/%s.json' % channel_id,
364 player, url, channel_id)
367 for module in channel['module']:
368 for teaser in try_get(module, lambda x: x['teaser'], list) or []:
370 teaser, lambda x: x['http://zdf.de/rels/target'], dict)
373 items.extend(try_get(
375 lambda x: x['resultsWithVideo']['http://zdf.de/rels/search/results'],
377 items.extend(try_get(
379 lambda x: x['filterRef']['resultsWithVideo']['http://zdf.de/rels/search/results'],
385 t = try_get(item, lambda x: x['http://zdf.de/rels/target'], dict)
388 sharing_url = t.get('http://zdf.de/rels/sharing-url')
389 if not sharing_url or not isinstance(sharing_url, compat_str):
391 if sharing_url in entry_urls:
393 entry_urls.add(sharing_url)
394 entries.append(self.url_result(
395 sharing_url, ie=ZDFIE.ie_key(), video_id=t.get('id')))
397 return self.playlist_result(entries, channel_id, channel.get('title'))