From d6ee67725397807bbb5edcd0b2c94f5bca62d3f4 Mon Sep 17 00:00:00 2001 From: bashonly <88596187+bashonly@users.noreply.github.com> Date: Fri, 31 Oct 2025 15:48:14 -0500 Subject: [PATCH] [ie/youtube] Fix `web_embedded` client extraction (#14843) Closes #14826 Authored by: bashonly, seproDev Co-authored-by: sepro --- yt_dlp/extractor/youtube/_base.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/yt_dlp/extractor/youtube/_base.py b/yt_dlp/extractor/youtube/_base.py index 17e942465d..133b069f22 100644 --- a/yt_dlp/extractor/youtube/_base.py +++ b/yt_dlp/extractor/youtube/_base.py @@ -380,10 +380,13 @@ def short_client_name(client_name): return join_nonempty(main[:4], ''.join(x[0] for x in parts)).upper() -def build_innertube_clients(): - THIRD_PARTY = { +def _fix_embedded_ytcfg(ytcfg): + ytcfg['INNERTUBE_CONTEXT'].setdefault('thirdParty', {}).update({ 'embedUrl': 'https://www.youtube.com/', # Can be any valid URL - } + }) + + +def build_innertube_clients(): BASE_CLIENTS = ('ios', 'web', 'tv', 'mweb', 'android') priority = qualities(BASE_CLIENTS[::-1]) @@ -405,7 +408,7 @@ def build_innertube_clients(): ytcfg['priority'] = 10 * priority(base_client) if variant == 'embedded': - ytcfg['INNERTUBE_CONTEXT']['thirdParty'] = THIRD_PARTY + _fix_embedded_ytcfg(ytcfg) ytcfg['priority'] -= 2 elif variant: ytcfg['priority'] -= 3 @@ -991,6 +994,10 @@ class YoutubeBaseInfoExtractor(InfoExtractor): ytcfg = self.extract_ytcfg(video_id, webpage) or {} + # See https://github.com/yt-dlp/yt-dlp/issues/14826 + if _split_innertube_client(client)[2] == 'embedded': + _fix_embedded_ytcfg(ytcfg) + # Workaround for https://github.com/yt-dlp/yt-dlp/issues/12563 # But it's not effective when logged-in if client == 'tv' and not self.is_authenticated: