Address review findings

This commit is contained in:
InvalidUsernameException 2024-12-15 16:23:52 +01:00
parent ec6db0a778
commit 3e6b1942f2

View file

@ -24,7 +24,7 @@ class ZDFBaseIE(InfoExtractor):
_GEO_COUNTRIES = ['DE'] _GEO_COUNTRIES = ['DE']
_QUALITIES = ('auto', 'low', 'med', 'high', 'veryhigh', 'hd', 'fhd', 'uhd') _QUALITIES = ('auto', 'low', 'med', 'high', 'veryhigh', 'hd', 'fhd', 'uhd')
def _download_mediathekv2_document(self, document_id): def _download_v2_doc(self, document_id):
return self._download_json( return self._download_json(
f'https://zdf-prod-futura.zdf.de/mediathekV2/document/{document_id}', f'https://zdf-prod-futura.zdf.de/mediathekV2/document/{document_id}',
document_id) document_id)
@ -324,7 +324,7 @@ class ZDFIE(ZDFBaseIE):
return self._extract_entry(player['content'], player, content, video_id) return self._extract_entry(player['content'], player, content, video_id)
def _extract_mobile(self, video_id): def _extract_mobile(self, video_id):
video = self._download_mediathekv2_document(video_id) video = self._download_v2_doc(video_id)
formats = [] formats = []
formitaeten = try_get(video, lambda x: x['document']['formitaeten'], list) formitaeten = try_get(video, lambda x: x['document']['formitaeten'], list)
@ -413,10 +413,6 @@ class ZDFChannelIE(ZDFBaseIE):
title = super()._og_search_title(webpage, fatal=fatal) title = super()._og_search_title(webpage, fatal=fatal)
return re.split(r'\s+[-|]\s+ZDF(?:mediathek)?$', title or '')[0] or None return re.split(r'\s+[-|]\s+ZDF(?:mediathek)?$', title or '')[0] or None
def _extract_document_id(self, webpage):
matches = re.search(r'docId\s*:\s*[\'"](?P<docid>[^\'"]+)[\'"]', webpage)
return matches and matches.group('docid')
def _get_playlist_description(self, page_data): def _get_playlist_description(self, page_data):
headline = traverse_obj(page_data, ('shortText', 'headline')) headline = traverse_obj(page_data, ('shortText', 'headline'))
text = traverse_obj(page_data, ('shortText', 'text')) text = traverse_obj(page_data, ('shortText', 'text'))
@ -425,56 +421,53 @@ class ZDFChannelIE(ZDFBaseIE):
return headline or text return headline or text
def _convert_thumbnails(self, thumbnails): def _convert_thumbnails(self, thumbnails):
return [{ return traverse_obj(thumbnails, (
'id': key, ..., {
'url': thumbnail_info['url'], 'url': ('url', {url_or_none}),
'width': int_or_none(thumbnail_info.get('width')), 'width': ('width', {int_or_none}),
'height': int_or_none(thumbnail_info.get('height')), 'height': ('height', {int_or_none}),
} for key, thumbnail_info in thumbnails.items() if url_or_none(thumbnail_info.get('url'))] }))
def _teaser_to_url_result(self, teaser): def _teaser_to_url_result(self, teaser):
return self.url_result( return self.url_result(
teaser['sharingUrl'], ie=ZDFIE.ie_key(), ie=ZDFIE.ie_key(),
id=teaser.get('id'), title=teaser.get('titel', ''), **traverse_obj(teaser, {
thumbnails=self._convert_thumbnails(teaser.get('teaserBild', {})), 'url': ('sharingUrl', {url_or_none}),
description=teaser.get('beschreibung'), 'id': ('id'),
duration=float_or_none(teaser.get('length')), 'title': ('titel'),
media_type=teaser.get('currentVideoType') or teaser.get('contentType'), 'thumbnails': ('teaserBild', {self._convert_thumbnails}),
season_number=int_or_none(teaser.get('seasonNumber')), 'description': ('beschreibung'),
episode_number=int_or_none(teaser.get('episodeNumber'))) 'duration': ('length', {float_or_none}),
'media_type': (('currentVideoType', 'contentType'), any),
'season_number': ('seasonNumber', {int_or_none}),
'episode_number': ('episodeNumber', {int_or_none}),
}))
def _real_extract(self, url): def _real_extract(self, url):
channel_id = self._match_id(url) channel_id = self._match_id(url)
webpage = self._download_webpage(url, channel_id) webpage = self._download_webpage(url, channel_id)
document_id = self._search_regex(
r'docId\s*:\s*(["\'])(?P<doc_id>(?:(?!\1).)+)\1', webpage, 'document id', group='doc_id')
main_video = None main_video = None
playlist_videos = [] playlist_videos = []
document_id = self._extract_document_id(webpage) data = self._download_v2_doc(document_id)
if document_id is not None:
data = self._download_mediathekv2_document(document_id)
for cluster in data['cluster']: main_video = traverse_obj(data, (
for teaser in cluster['teaser']: 'cluster', lambda _, cluster: cluster['type'] == 'teaserContent',
if cluster['type'] == 'teaserContent' and teaser['type'] == 'video': 'teaser', lambda _, teaser: teaser['type'] == 'video', any))
main_video = main_video or teaser
elif cluster['type'] == 'teaser' and teaser['type'] == 'video':
if teaser['brandId'] != document_id:
# These are unrelated 'You might also like' videos, filter them out
continue
playlist_videos.append(teaser)
if self._downloader.params.get('noplaylist', False): if not self._yes_playlist(channel_id, main_video and main_video['id']):
return self._teaser_to_url_result(main_video) if main_video else None return self._teaser_to_url_result(main_video)
self.to_screen(f'Downloading playlist {channel_id} - add --no-playlist to download just the main video') playlist_videos = traverse_obj(data, (
'cluster', lambda _, cluster: cluster['type'] == 'teaser',
# If 'brandId' differs, it is a 'You might also like' video. Filter these out.
'teaser', lambda _, teaser: teaser['type'] == 'video' and teaser['brandId'] == document_id))
thumbnails = ( thumbnails = traverse_obj(
traverse_obj(data, ('document', 'image')) data, ('document', 'image'), ('document', 'teaserBild'), ('stageHeader', 'image'))
or traverse_obj(data, ('document', 'teaserBild'))
or traverse_obj(data, ('stageHeader', 'image'))
or {})
return self.playlist_result( return self.playlist_result(
(self._teaser_to_url_result(video) for video in playlist_videos), (self._teaser_to_url_result(video) for video in playlist_videos),