mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2026-10-25 22:26:51 +09:00
[ie/youtube] Fix initial data extraction (#17703)
Closes #17656 Authored by: InvalidUsernameException
This commit is contained in:
1 parent
fe84bef396
commit
12ac9aca79
1 file changed
+5
@@ -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'<script\b(?!-)[^>]+(?<!-)\bid=["\']yt-initial-data["\'][^>]*>'
|
||||
_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
|
||||
|
||||
Reference in new issue
Block a user