From 12ac9aca79671420724227aca37bc888c604a6f8 Mon Sep 17 00:00:00 2001 From: InvalidUsernameException Date: Wed, 21 Oct 2026 17:01:35 +0200 Subject: [PATCH] [ie/youtube] Fix initial data extraction (#17703) Closes #17656 Authored by: InvalidUsernameException --- yt_dlp/extractor/youtube/_base.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/yt_dlp/extractor/youtube/_base.py b/yt_dlp/extractor/youtube/_base.py index 7dbaf02d56..755d5dac00 100644 --- a/yt_dlp/extractor/youtube/_base.py +++ b/yt_dlp/extractor/youtube/_base.py @@ -722,6 +722,7 @@ class YoutubeBaseInfoExtractor(InfoExtractor): f'Login details are needed to download this content. {self._youtube_login_hint}', method=None) _YT_INITIAL_DATA_RE = r'(?:window\s*\[\s*["\']ytInitialData["\']\s*\]|ytInitialData)\s*=' + _YT_INITIAL_DATA_ALT_RE = r']+(?]*>' _YT_INITIAL_PLAYER_RESPONSE_RE = r'ytInitialPlayerResponse\s*=' def _get_default_ytcfg(self, client='web'): @@ -865,6 +866,10 @@ class YoutubeBaseInfoExtractor(InfoExtractor): }, cndn=lambda _, v: v)) def extract_yt_initial_data(self, item_id, webpage, fatal=True): + if data := self._search_json(self._YT_INITIAL_DATA_ALT_RE, webpage, 'data', item_id, default=None): + self.write_debug('Parsed initial data from dedicated script element') + return data + return self._search_json(self._YT_INITIAL_DATA_RE, webpage, 'yt initial data', item_id, fatal=fatal) @staticmethod