[dl:ytdl] support custom headers when fetching HLS/DASH manifests

This commit is contained in:
Mike Fährmann
2025-05-26 17:17:37 +02:00
parent 456e93d489
commit e05b82253a

View File

@@ -78,7 +78,8 @@ class YoutubeDLDownloader(DownloaderBase):
if manifest:
info_dict = self._extract_manifest(
ytdl_instance, url, manifest,
kwdict.pop("_ytdl_manifest_data", None))
kwdict.pop("_ytdl_manifest_data", None),
kwdict.pop("_ytdl_manifest_headers", None))
else:
info_dict = self._extract_info(ytdl_instance, url)
except Exception as exc:
@@ -165,7 +166,8 @@ class YoutubeDLDownloader(DownloaderBase):
def _extract_info(self, ytdl, url):
return ytdl.extract_info(url, download=False)
def _extract_manifest(self, ytdl, url, manifest_type, manifest_data=None):
def _extract_manifest(self, ytdl, url, manifest_type, manifest_data=None,
headers=None):
extr = ytdl.get_info_extractor("Generic")
video_id = extr._generic_id(url)
@@ -173,9 +175,10 @@ class YoutubeDLDownloader(DownloaderBase):
if manifest_data is None:
try:
fmts, subs = extr._extract_m3u8_formats_and_subtitles(
url, video_id, "mp4")
url, video_id, "mp4", headers=headers)
except AttributeError:
fmts = extr._extract_m3u8_formats(url, video_id, "mp4")
fmts = extr._extract_m3u8_formats(
url, video_id, "mp4", headers=headers)
subs = None
else:
try:
@@ -189,9 +192,10 @@ class YoutubeDLDownloader(DownloaderBase):
if manifest_data is None:
try:
fmts, subs = extr._extract_mpd_formats_and_subtitles(
url, video_id)
url, video_id, headers=headers)
except AttributeError:
fmts = extr._extract_mpd_formats(url, video_id)
fmts = extr._extract_mpd_formats(
url, video_id, headers=headers)
subs = None
else:
if isinstance(manifest_data, str):