From 48416bc4a8f1d5ff07d5977659cb8ece7640dcd8 Mon Sep 17 00:00:00 2001 From: pukkandan Date: Tue, 1 Feb 2022 08:10:19 +0530 Subject: [PATCH] [youtube] Fix n-sig for player e06dea74 --- test/test_youtube_signature.py | 4 ++++ yt_dlp/extractor/youtube.py | 12 +++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/test/test_youtube_signature.py b/test/test_youtube_signature.py index 5f8114a1c..537eb8ba2 100644 --- a/test/test_youtube_signature.py +++ b/test/test_youtube_signature.py @@ -86,6 +86,10 @@ _NSIG_TESTS = [ 'https://www.youtube.com/s/player/8040e515/player_ias.vflset/en_US/base.js', 'wvOFaY-yjgDuIEg5', 'HkfBFDHmgw4rsw', ), + ( + 'https://www.youtube.com/s/player/e06dea74/player_ias.vflset/en_US/base.js', + 'AiuodmaDDYw8d3y4bf', 'ankd8eza2T6Qmw', + ), ] diff --git a/yt_dlp/extractor/youtube.py b/yt_dlp/extractor/youtube.py index 98f02331c..1600b6515 100644 --- a/yt_dlp/extractor/youtube.py +++ b/yt_dlp/extractor/youtube.py @@ -42,6 +42,7 @@ from ..utils import ( int_or_none, is_html, join_nonempty, + js_to_json, mimetype2ext, network_exceptions, NO_DEFAULT, @@ -2420,9 +2421,14 @@ class YoutubeIE(YoutubeBaseInfoExtractor): raise ExtractorError(traceback.format_exc(), cause=e, video_id=video_id) def _extract_n_function_name(self, jscode): - return self._search_regex( - (r'\.get\("n"\)\)&&\(b=(?P[a-zA-Z0-9$]{3})\([a-zA-Z0-9]\)',), - jscode, 'Initial JS player n function name', group='nfunc') + nfunc, idx = self._search_regex( + r'\.get\("n"\)\)&&\(b=(?P[a-zA-Z0-9$]{3})(\[(?P\d+)\])?\([a-zA-Z0-9]\)', + jscode, 'Initial JS player n function name', group=('nfunc', 'idx')) + if not idx: + return nfunc + return json.loads(js_to_json(self._search_regex( + rf'var {nfunc}\s*=\s*(\[.+?\]);', jscode, + f'Initial JS player n function list ({nfunc}.{idx})')))[int(idx)] def _extract_n_function(self, video_id, player_url): player_id = self._extract_player_info(player_url)