mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2026-04-29 20:15:53 +00:00
Compare commits
7 Commits
3bb3aa4672
...
6557fc538e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6557fc538e | ||
|
|
fa2e2f789e | ||
|
|
f1fe8dc8d2 | ||
|
|
59ba75dbfe | ||
|
|
bbf362df9c | ||
|
|
67c05c9c43 | ||
|
|
692a396be8 |
@ -27,7 +27,7 @@ class DreiSatIE(ZDFBaseIE):
|
||||
},
|
||||
}, {
|
||||
'url': 'https://www.3sat.de/film/ab-18/ab-18---mein-fremdes-ich-100.html',
|
||||
'md5': '66cb9013ce37f6e008dc99bfcf1356bc',
|
||||
'md5': 'f92638413a11d759bdae95c9d8ec165c',
|
||||
'info_dict': {
|
||||
'id': '221128_mein_fremdes_ich2_ab18',
|
||||
'ext': 'mp4',
|
||||
@ -42,7 +42,7 @@ class DreiSatIE(ZDFBaseIE):
|
||||
},
|
||||
}, {
|
||||
'url': 'https://www.3sat.de/gesellschaft/37-grad-leben/aus-dem-leben-gerissen-102.html',
|
||||
'md5': '69f276184c9a24147e4baae728fbc3c4',
|
||||
'md5': 'a903eaf8d1fd635bd3317cd2ad87ec84',
|
||||
'info_dict': {
|
||||
'id': '250323_0903_sendung_sgl',
|
||||
'ext': 'mp4',
|
||||
@ -58,7 +58,7 @@ class DreiSatIE(ZDFBaseIE):
|
||||
}, {
|
||||
# Video with chapters
|
||||
'url': 'https://www.3sat.de/kultur/buchmesse/dein-buch-das-beste-von-der-leipziger-buchmesse-2025-teil-1-100.html',
|
||||
'md5': '65e8f365799d2266c9110d83d748445e',
|
||||
'md5': '6b95790ce52e75f0d050adcdd2711ee6',
|
||||
'info_dict': {
|
||||
'id': '250330_dein_buch1_bum',
|
||||
'ext': 'mp4',
|
||||
@ -97,7 +97,9 @@ class DreiSatIE(ZDFBaseIE):
|
||||
(('streams', 'default'), None),
|
||||
('http://zdf.de/rels/streams/ptmd', 'http://zdf.de/rels/streams/ptmd-template'),
|
||||
{str}, any, {require('ptmd path')}))
|
||||
info = self._extract_ptmd(player_url, ptmd_path, video_id, api_token)
|
||||
ptmd_url = self._expand_ptmd_template(player_url, ptmd_path)
|
||||
aspect_ratio = self._parse_aspect_ratio(video_target.get('aspectRatio'))
|
||||
info = self._extract_ptmd_urls(ptmd_url, video_id, api_token, aspect_ratio)
|
||||
|
||||
return merge_dicts(info, {
|
||||
**traverse_obj(content, {
|
||||
|
||||
@ -13,7 +13,7 @@ class PhoenixIE(ZDFBaseIE):
|
||||
_VALID_URL = r'https?://(?:www\.)?phoenix\.de/(?:[^/?#]+/)*[^/?#&]*-a-(?P<id>\d+)\.html'
|
||||
_TESTS = [{
|
||||
'url': 'https://www.phoenix.de/sendungen/dokumentationen/spitzbergen-a-893349.html',
|
||||
'md5': '768bbcd67a51fbfb22263ecdbc49146d',
|
||||
'md5': 'a79e86d9774d0b3f2102aff988a0bd32',
|
||||
'info_dict': {
|
||||
'id': '221215_phx_spitzbergen',
|
||||
'ext': 'mp4',
|
||||
@ -70,9 +70,8 @@ class PhoenixIE(ZDFBaseIE):
|
||||
title = title or details['title']
|
||||
content_id = details['tracking']['nielsen']['content']['assetid']
|
||||
|
||||
info = self._extract_ptmd(
|
||||
'https://tmd.phoenix.de',
|
||||
f'tmd/2/{{playerId}}/vod/ptmd/phoenix/{content_id}',
|
||||
info = self._extract_ptmd_urls(
|
||||
f'https://tmd.phoenix.de/tmd/2/android_native_6/vod/ptmd/phoenix/{content_id}',
|
||||
content_id)
|
||||
|
||||
duration = int_or_none(try_get(
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
import functools
|
||||
import json
|
||||
import re
|
||||
import time
|
||||
@ -14,8 +15,6 @@ from ..utils import (
|
||||
parse_codecs,
|
||||
parse_iso8601,
|
||||
parse_qs,
|
||||
qualities,
|
||||
try_get,
|
||||
unified_timestamp,
|
||||
url_or_none,
|
||||
urljoin,
|
||||
@ -26,7 +25,6 @@ from ..utils.traversal import traverse_obj
|
||||
|
||||
class ZDFBaseIE(InfoExtractor):
|
||||
_GEO_COUNTRIES = ['DE']
|
||||
_QUALITIES = ('auto', 'low', 'med', 'high', 'veryhigh', 'hd', 'fhd', 'uhd')
|
||||
|
||||
def _call_api(self, url, video_id, item, api_token=None):
|
||||
headers = {'Api-Auth': api_token} if api_token else {}
|
||||
@ -34,6 +32,12 @@ class ZDFBaseIE(InfoExtractor):
|
||||
url, video_id, note=f'Downloading {item}',
|
||||
errnote=f'Failed to download {item}', headers=headers)
|
||||
|
||||
def _parse_aspect_ratio(self, aspect_ratio):
|
||||
if not aspect_ratio or not isinstance(aspect_ratio, str):
|
||||
return None
|
||||
mobj = re.match(r'(?P<width>\d+):(?P<height>\d+)', aspect_ratio)
|
||||
return int(mobj.group('width')) / int(mobj.group('height')) if mobj else None
|
||||
|
||||
def _extract_chapters(self, data):
|
||||
return traverse_obj(data, (lambda _, v: 'anchorOffset' in v, {
|
||||
'start_time': ('anchorOffset', {float_or_none}),
|
||||
@ -55,75 +59,66 @@ class ZDFBaseIE(InfoExtractor):
|
||||
})
|
||||
return subtitles
|
||||
|
||||
def _extract_format(self, video_id, formats, format_urls, meta):
|
||||
format_url = meta['url']
|
||||
if format_url in format_urls:
|
||||
return
|
||||
format_urls.add(format_url)
|
||||
ext = determine_ext(format_url)
|
||||
if ext == 'm3u8':
|
||||
fmts = self._extract_m3u8_formats(
|
||||
format_url, video_id, 'mp4', m3u8_id='hls', fatal=False)
|
||||
elif ext == 'mpd':
|
||||
fmts = self._extract_mpd_formats(
|
||||
format_url, video_id, mpd_id='dash', fatal=False)
|
||||
else:
|
||||
f = parse_codecs(meta.get('mimeCodec'))
|
||||
if not f and meta.get('type'):
|
||||
data = meta['type'].split('_')
|
||||
if len(data) >= 3 and data[2] == ext:
|
||||
f = {'vcodec': data[0], 'acodec': data[1]}
|
||||
f.update({
|
||||
'url': format_url,
|
||||
'height': int_or_none(meta.get('highestVerticalResolution')),
|
||||
'format_id': join_nonempty('http', meta.get('type'), meta.get('quality')),
|
||||
'tbr': int_or_none(self._search_regex(r'_(\d+)k_', format_url, 'tbr', default=None)),
|
||||
def _expand_ptmd_template(self, api_base_url, template):
|
||||
return urljoin(api_base_url, template.replace('{playerId}', 'android_native_6'))
|
||||
|
||||
def _extract_ptmd_urls(self, ptmd_urls, video_id, api_token=None, aspect_ratio=None):
|
||||
ptmd_urls = variadic(ptmd_urls)
|
||||
ptmd_info = []
|
||||
for url in ptmd_urls:
|
||||
ptmd_info.append({
|
||||
'url': url,
|
||||
'dgs': False,
|
||||
})
|
||||
fmts = [f]
|
||||
formats.extend(merge_dicts(f, {
|
||||
'format_note': join_nonempty(meta.get('quality'), meta.get('class'), delim=', '),
|
||||
'language': meta.get('language'),
|
||||
'language_preference': 10 if meta.get('class') == 'main' else -10 if meta.get('class') == 'ad' else -1,
|
||||
'quality': qualities(self._QUALITIES)(meta.get('quality')),
|
||||
}) for f in fmts)
|
||||
return self._extract_ptmd(ptmd_info, video_id, api_token, aspect_ratio)
|
||||
|
||||
def _extract_ptmd(self, api_base_url, templates, video_id, api_token=None):
|
||||
# TODO: If there are multiple PTMD templates,
|
||||
# usually one of them is a sign-language variant of the video.
|
||||
# The format order works out fine as is and prefers the "regular" video,
|
||||
# but this should probably be made more explicit.
|
||||
|
||||
# TODO: HTTPS formats are extracted without resolution information
|
||||
# However, we know vertical resolution and the caller often knows apsect ratio.
|
||||
# So we could calculate the correct resulution from those two data points.
|
||||
templates = variadic(templates)
|
||||
def _extract_ptmd(self, ptmd_info, video_id, api_token=None, aspect_ratio=None):
|
||||
ptmd_info = variadic(ptmd_info)
|
||||
src_captions = []
|
||||
|
||||
content_id = None
|
||||
duration = None
|
||||
formats = []
|
||||
track_uris = set()
|
||||
for template in templates:
|
||||
ptmd_url = urljoin(api_base_url, template.replace(
|
||||
'{playerId}', 'android_native_6'))
|
||||
ptmd = self._call_api(ptmd_url, video_id, 'PTMD data', api_token)
|
||||
# As per above TODO on sign language videos variants,
|
||||
# prefer content_id from the last entry to get the "regular" ID.
|
||||
content_id = ptmd.get('basename') or ptmd_url.split('/')[-2]
|
||||
for info in ptmd_info:
|
||||
ptmd = self._call_api(info['url'], video_id, 'PTMD data', api_token)
|
||||
basename = ptmd.get('basename') or info['url'].split('/')[-2]
|
||||
if not content_id and not info['dgs']:
|
||||
content_id = basename
|
||||
duration = (duration or traverse_obj(ptmd, ('attributes', 'duration', 'value', {float_or_none(scale=1000)})))
|
||||
src_captions += ptmd.get('captions') or []
|
||||
for stream in traverse_obj(ptmd, ('priorityList', ..., 'formitaeten', ..., {dict})):
|
||||
for quality in traverse_obj(stream, ('qualities', ..., {dict})):
|
||||
for variant in traverse_obj(quality, ('audio', 'tracks', lambda _, v: url_or_none(v['uri']))):
|
||||
self._extract_format(
|
||||
content_id, formats, track_uris, {
|
||||
'url': variant.get('uri'),
|
||||
'type': stream.get('type'),
|
||||
'mimeCodec': quality.get('mimeCodec'),
|
||||
'quality': quality.get('quality'),
|
||||
'class': variant.get('class'),
|
||||
'language': variant.get('language'),
|
||||
})
|
||||
format_url = variant['uri']
|
||||
if format_url in track_uris:
|
||||
continue
|
||||
track_uris.add(format_url)
|
||||
ext = determine_ext(format_url)
|
||||
if ext == 'm3u8':
|
||||
fmts = self._extract_m3u8_formats(
|
||||
format_url, basename, 'mp4', m3u8_id='hls', fatal=False)
|
||||
elif ext == 'mpd':
|
||||
fmts = self._extract_mpd_formats(
|
||||
format_url, basename, mpd_id='dash', fatal=False)
|
||||
else:
|
||||
height = int_or_none(quality.get('highestVerticalResolution'))
|
||||
width = round(aspect_ratio * height) if aspect_ratio and height else None
|
||||
fmts = [{
|
||||
'url': format_url,
|
||||
**parse_codecs(quality.get('mimeCodec')),
|
||||
'height': height,
|
||||
'width': width,
|
||||
'format_id': join_nonempty('http', stream.get('type')),
|
||||
'tbr': int_or_none(self._search_regex(r'_(\d+)k_', format_url, 'tbr', default=None)),
|
||||
}]
|
||||
formats.extend(merge_dicts(f, {
|
||||
'format_note': join_nonempty(
|
||||
variant.get('class'), 'dgs' if info['dgs'] else '', delim=', '),
|
||||
'language': variant.get('language'),
|
||||
'preference': -2 if info['dgs'] else -1,
|
||||
'language_preference': 10 if variant.get('class') == 'main' else -10 if variant.get('class') == 'ad' else -1,
|
||||
}) for f in fmts)
|
||||
|
||||
return {
|
||||
'extractor_key': ZDFIE.ie_key(),
|
||||
@ -131,7 +126,6 @@ class ZDFBaseIE(InfoExtractor):
|
||||
'duration': duration,
|
||||
'formats': formats,
|
||||
'subtitles': self._extract_subtitles(src_captions),
|
||||
'_format_sort_fields': ('tbr', 'res', 'quality', 'language_preference'),
|
||||
}
|
||||
|
||||
def _get_api_token(self, video_id):
|
||||
@ -303,7 +297,7 @@ class ZDFIE(ZDFBaseIE):
|
||||
# Video with chapters
|
||||
# Also: video with sign-language variant
|
||||
'url': 'https://www.zdf.de/video/magazine/heute-journal-104/heute-journal-vom-19-12-2021-100',
|
||||
'md5': '1175003f28507bd27b266181c4de9f56',
|
||||
'md5': '6ada39465497a84fb98d48ffff69e7b7',
|
||||
'info_dict': {
|
||||
'id': 'heute-journal-vom-19-12-2021-100',
|
||||
'ext': 'mp4',
|
||||
@ -326,7 +320,7 @@ class ZDFIE(ZDFBaseIE):
|
||||
}, {
|
||||
# Video that requires fallback extraction
|
||||
'url': 'https://www.zdf.de/nachrichten/politik/deutschland/koalitionsverhandlungen-spd-cdu-csu-dobrindt-100.html',
|
||||
'md5': '95903ecbd37f2881b4462d074b8f8c44',
|
||||
'md5': 'c3a78514dd993a5781aa3afe50db51e2',
|
||||
'info_dict': {
|
||||
'id': 'koalitionsverhandlungen-spd-cdu-csu-dobrindt-100',
|
||||
'ext': 'mp4',
|
||||
@ -381,7 +375,7 @@ class ZDFIE(ZDFBaseIE):
|
||||
'url': 'https://www.zdf.de/serien/northern-lights/begegnung-auf-der-bruecke-100.html',
|
||||
'info_dict': {
|
||||
'id': 'begegnung-auf-der-bruecke-100',
|
||||
'ext': 'mp4',
|
||||
'ext': 'webm',
|
||||
'title': 'Begegnung auf der Brücke',
|
||||
'description': 'md5:e53a555da87447f7f1207f10353f8e45',
|
||||
'duration': 3083.0,
|
||||
@ -483,6 +477,16 @@ query VideoByCanonical($canonical: String!) {
|
||||
}
|
||||
'''
|
||||
|
||||
def _extract_ptmd(self, ptmd_info, video_id, api_token=None, aspect_ratio=None):
|
||||
ptmd_data = super()._extract_ptmd(ptmd_info, video_id, api_token, aspect_ratio)
|
||||
# We can't use the ID from PTMD extraction as the video ID
|
||||
# because it is not available during playlist extraction.
|
||||
# We fix it here manually instead of inside the base class
|
||||
# because other extractors do rely on using it as their ID.
|
||||
ptmd_data['_old_archive_ids'] = [make_archive_id(ZDFIE, ptmd_data['id'])]
|
||||
del ptmd_data['id']
|
||||
return ptmd_data
|
||||
|
||||
# This fallback should generally only happen for pages under `zdf.de/nachrichten`.
|
||||
# They are on a separate website for which GraphQL often doesn't return results.
|
||||
# The API used here is no longer in use by official clients and likely deprecated.
|
||||
@ -495,11 +499,10 @@ query VideoByCanonical($canonical: String!) {
|
||||
errnote='Failed to download fallback metadata')
|
||||
document = video['document']
|
||||
|
||||
content_id = document.get('basename')
|
||||
formats = []
|
||||
format_urls = set()
|
||||
for f in traverse_obj(document, ('formitaeten', ..., {dict})):
|
||||
self._extract_format(document_id, formats, format_urls, f)
|
||||
ptmd_url = traverse_obj(document, (
|
||||
('streamApiUrlAndroid', ('streams', 0, 'streamApiUrlAndroid')),
|
||||
{url_or_none}, any))
|
||||
ptmd_data = self._extract_ptmd_urls(ptmd_url, document_id, self._get_api_token(document_id))
|
||||
|
||||
thumbnails = []
|
||||
for thumbnail_key, thumbnail in traverse_obj(document, ('teaserBild', {dict.items})):
|
||||
@ -515,15 +518,16 @@ query VideoByCanonical($canonical: String!) {
|
||||
|
||||
return {
|
||||
'id': document_id,
|
||||
'title': document.get('titel'),
|
||||
'description': document.get('beschreibung'),
|
||||
'duration': int_or_none(document.get('length')),
|
||||
'timestamp': unified_timestamp(document.get('date')) or unified_timestamp(
|
||||
try_get(video, lambda x: x['meta']['editorialDate'], str)),
|
||||
'thumbnails': thumbnails,
|
||||
'subtitles': self._extract_subtitles(document.get('captions') or []),
|
||||
'formats': formats,
|
||||
'_old_archive_ids': [make_archive_id(ZDFIE, content_id)] if content_id else [],
|
||||
**ptmd_data,
|
||||
**traverse_obj(video, {
|
||||
'title': ('document', 'titel', {str}),
|
||||
'description': ('document', 'beschreibung', {str}),
|
||||
'timestamp': (
|
||||
(('document', 'date'), ('meta', 'editorialDate')),
|
||||
{unified_timestamp}, any),
|
||||
'subtitles': ('document', 'captions', {self._extract_subtitles}),
|
||||
}),
|
||||
}
|
||||
|
||||
def _real_extract(self, url):
|
||||
@ -536,22 +540,20 @@ query VideoByCanonical($canonical: String!) {
|
||||
|
||||
if not video_data:
|
||||
return self._extract_fallback(video_id)
|
||||
|
||||
ptmd_templates = traverse_obj(
|
||||
video_data, ('currentMedia', 'nodes', ..., 'ptmdTemplate'))
|
||||
ptmd_data = self._extract_ptmd(
|
||||
'https://api.zdf.de', ptmd_templates, video_id,
|
||||
self._get_api_token(video_id))
|
||||
# We can't use the ID from PTMD extraction as the video ID
|
||||
# because it is not available during playlist extraction.
|
||||
# We fix it here manually instead of inside the method
|
||||
# because other extractors do rely on using it as their ID.
|
||||
ptmd_data['_old_archive_ids'] = [make_archive_id(ZDFIE, ptmd_data['id'])]
|
||||
del ptmd_data['id']
|
||||
ptmd_nodes = traverse_obj(video_data, ('currentMedia', 'nodes'))
|
||||
ptmd_info = traverse_obj(ptmd_nodes, (..., {
|
||||
'url': ('ptmdTemplate', {functools.partial(self._expand_ptmd_template, 'https://api.zdf.de')}),
|
||||
# Sign-language variant (DGS = *D*eutsche *G*ebärden*s*prache')
|
||||
'dgs': ('vodMediaType', {lambda x: x == 'DGS'}),
|
||||
}))
|
||||
aspect_ratio = traverse_obj(ptmd_nodes, (
|
||||
..., 'aspectRatio', {self._parse_aspect_ratio}, any))
|
||||
ptmd_result = self._extract_ptmd(
|
||||
ptmd_info, video_id, self._get_api_token(video_id), aspect_ratio)
|
||||
|
||||
return {
|
||||
'id': video_id,
|
||||
**ptmd_data,
|
||||
**ptmd_result,
|
||||
**traverse_obj(video_data, {
|
||||
'title': ('title', {str}),
|
||||
'description': (('leadParagraph', ('teaser', 'description')), any, {str}),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user