Skip to content

Commit 48416bc

Browse files
committed
[youtube] Fix n-sig for player e06dea74
1 parent 6a0546e commit 48416bc

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

test/test_youtube_signature.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@
8686
'https://www.youtube.com/s/player/8040e515/player_ias.vflset/en_US/base.js',
8787
'wvOFaY-yjgDuIEg5', 'HkfBFDHmgw4rsw',
8888
),
89+
(
90+
'https://www.youtube.com/s/player/e06dea74/player_ias.vflset/en_US/base.js',
91+
'AiuodmaDDYw8d3y4bf', 'ankd8eza2T6Qmw',
92+
),
8993
]
9094

9195

yt_dlp/extractor/youtube.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
int_or_none,
4343
is_html,
4444
join_nonempty,
45+
js_to_json,
4546
mimetype2ext,
4647
network_exceptions,
4748
NO_DEFAULT,
@@ -2420,9 +2421,14 @@ def _decrypt_nsig(self, s, video_id, player_url):
24202421
raise ExtractorError(traceback.format_exc(), cause=e, video_id=video_id)
24212422

24222423
def _extract_n_function_name(self, jscode):
2423-
return self._search_regex(
2424-
(r'\.get\("n"\)\)&&\(b=(?P<nfunc>[a-zA-Z0-9$]{3})\([a-zA-Z0-9]\)',),
2425-
jscode, 'Initial JS player n function name', group='nfunc')
2424+
nfunc, idx = self._search_regex(
2425+
r'\.get\("n"\)\)&&\(b=(?P<nfunc>[a-zA-Z0-9$]{3})(\[(?P<idx>\d+)\])?\([a-zA-Z0-9]\)',
2426+
jscode, 'Initial JS player n function name', group=('nfunc', 'idx'))
2427+
if not idx:
2428+
return nfunc
2429+
return json.loads(js_to_json(self._search_regex(
2430+
rf'var {nfunc}\s*=\s*(\[.+?\]);', jscode,
2431+
f'Initial JS player n function list ({nfunc}.{idx})')))[int(idx)]
24262432

24272433
def _extract_n_function(self, video_id, player_url):
24282434
player_id = self._extract_player_info(player_url)

0 commit comments

Comments
 (0)