youtube-dl: Youtube Decode n-parameter failed

Checklist

  • I’m reporting a broken site support
  • I’ve verified that I’m running youtube-dl version 2021.12.17
  • I’ve checked that all provided URLs are alive and playable in a browser
  • I’ve checked that all URLs and arguments with special characters are properly quoted or escaped
  • I’ve searched the bugtracker for similar issues including closed ones
  • my code’s changeset is
Author: dirkf <fieldhouse@gmx.net>  2022-04-10 12:49:09
Committer: GitHub <noreply@github.com>  2022-04-10 12:49:09
Parent: 871645a4a4a0e12ec8f7bf78a3ad7bf75838ee5c ([RAI] Fix extraction of http formats)
Child:  0000000000000000000000000000000000000000 (Local uncommitted changes, not checked in to index)
Branches: master, remotes/origin/master
Follows: 2021.12.17
Precedes: 

    Disable blank issues

Verbose log

[youtube] f3vYFg1tM-0: Downloading webpage
[youtube] f3vYFg1tM-0: Downloading player fae06c11
WARNING: [youtube] Unable to decode n-parameter: download likely to be throttled (Unable to extract Initial JS player n function name; please report this issue on https://yt-dl.org/bug . Make sure you are using the latest version; see  https://yt-dl.org/update  on how to update. Be sure to call youtube-dl with the --verbose flag and include its complete output. Traceback (most recent call last):
  File "E:\work\01_youtubedl\rep\youtube-dl\youtube_dl\extractor\youtube.py", line 1514, in _n_descramble
    self._player_cache[player_id] = self._extract_n_function(video_id, player_url)
  File "E:\work\01_youtubedl\rep\youtube-dl\youtube_dl\extractor\youtube.py", line 1487, in _extract_n_function
    funcname = self._extract_n_function_name(jscode)
  File "E:\work\01_youtubedl\rep\youtube-dl\youtube_dl\extractor\youtube.py", line 1470, in _extract_n_function_name
    jscode, 'Initial JS player n function name')
  File "E:\work\01_youtubedl\rep\youtube-dl\youtube_dl\extractor\common.py", line 1012, in _search_regex
    raise RegexNotFoundError('Unable to extract %s' % _name)
youtube_dl.utils.RegexNotFoundError: Unable to extract Initial JS player n function name; please report this issue on https://yt-dl.org/bug . Make sure you are using the latest version; see  https://yt-dl.org/update  on how to update. Be sure to call youtube-dl with the --verbose flag and include its complete output.
)

Description

  1. test video link is https://www.youtube.com/watch?v=f3vYFg1tM-0
  2. following is ‘_n_descramble’ function’s parameters
n_param:'9nHkIgOzxZyYvA0FueY'
player_url:'https://www.youtube.com/s/player/fae06c11/player_ias.vflset/en_US/base.js'
video_id:'f3vYFg1tM-0'

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 15 (7 by maintainers)

Commits related to this issue

Most upvoted comments

Required patch that will be committed shortly:

--- old/youtube_dl/extractor/youtube.py
+++ new/youtube_dl/extractor/youtube.py
@@ -1464,15 +1464,15 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
     # 2. https://code.videolan.org/videolan/vlc/-/blob/4fb284e5af69aa9ac2100ccbdd3b88debec9987f/share/lua/playlist/youtube.lua#L116
     # 3. https://github.com/ytdl-org/youtube-dl/issues/30097#issuecomment-950157377
     def _extract_n_function_name(self, jscode):
-        target = r'(?P<nfunc>[a-zA-Z0-9$]{3})(?:\[(?P<idx>\d+)\])?'
+        target = r'(?P<nfunc>[a-zA-Z_$][\w$]*)(?:\[(?P<idx>\d+)\])?'
         nfunc_and_idx = self._search_regex(
-            r'\.get\("n"\)\)&&\(b=(%s)\([a-zA-Z0-9]\)' % (target, ),
+            r'\.get\("n"\)\)&&\(b=(%s)\([\w$]+\)' % (target, ),
             jscode, 'Initial JS player n function name')
         nfunc, idx = re.match(target, nfunc_and_idx).group('nfunc', 'idx')
         if not idx:
             return nfunc
         return self._parse_json(self._search_regex(
-            r'var %s\s*=\s*(\[.+?\]);' % (nfunc, ), jscode,
+            r'var %s\s*=\s*(\[.+?\]);' % (re.escape(nfunc), ), jscode,
             'Initial JS player n function list ({nfunc}[{idx}])'.format(**locals())), nfunc, transform_source=js_to_json)[int(idx)]
 
     def _extract_n_function(self, video_id, player_url):

There were two issues:

  • new player fae06c11 used a 2-character function name where previously it was always 3;
  • new player’s function name included $ which needed to be escaped when used in a regex.

In fixing these I’ve made the patterns match any valid JS identifier so as to avoid future surprises.

Sorry, first I misunderstood and thought I need to checkout another branch, I just had to pull the master, everything works as expected. Thank you. I reallly appreciate the lots of work you guys put in

$ python -m youtube_dl -v -F 'f3vYFg1tM-0'
[debug] System config: [u'--prefer-ffmpeg']
[debug] User config: []
[debug] Custom config: []
[debug] Command-line args: [u'-v', u'-F', u'f3vYFg1tM-0']
[debug] Encodings: locale UTF-8, fs UTF-8, out UTF-8, pref UTF-8
[debug] youtube-dl version 2021.12.17
[debug] Git HEAD: a0068bd6b
[debug] Python version 2.7.17 (CPython) - Linux-4.4.0-210-generic-i686-with-Ubuntu-16.04-xenial
[debug] exe versions: avconv 4.3, avprobe 4.3, ffmpeg 4.3, ffprobe 4.3
[debug] Proxy map: {}
[youtube] f3vYFg1tM-0: Downloading webpage
[debug] [youtube] Decrypted nsig orApSevMV853kIssLsu => 5GZaNVi0bl0s1w
[debug] [youtube] Decrypted nsig XmzDiqBGL0Egq5q8pIQ => JMUrpQ9VoFloOA
[info] Available formats for f3vYFg1tM-0:
format code  extension  resolution note
249          webm       audio only tiny   53k , webm_dash container, opus @ 53k (48000Hz), 24.67MiB
250          webm       audio only tiny   68k , webm_dash container, opus @ 68k (48000Hz), 31.60MiB
140          m4a        audio only tiny  129k , m4a_dash container, mp4a.40.2@129k (44100Hz), 60.01MiB
251          webm       audio only tiny  140k , webm_dash container, opus @140k (48000Hz), 65.27MiB
160          mp4        256x144    144p   52k , mp4_dash container, avc1.4d400c@  52k, 25fps, video only, 24.12MiB
278          webm       256x144    144p   67k , webm_dash container, vp9@  67k, 25fps, video only, 31.27MiB
242          webm       426x240    240p   72k , webm_dash container, vp9@  72k, 25fps, video only, 33.59MiB
133          mp4        426x240    240p  119k , mp4_dash container, avc1.4d4015@ 119k, 25fps, video only, 55.22MiB
243          webm       640x360    360p  114k , webm_dash container, vp9@ 114k, 25fps, video only, 53.17MiB
134          mp4        640x360    360p  226k , mp4_dash container, avc1.4d401e@ 226k, 25fps, video only, 104.75MiB
244          webm       854x480    480p  173k , webm_dash container, vp9@ 173k, 25fps, video only, 80.52MiB
135          mp4        854x480    480p  401k , mp4_dash container, avc1.4d401e@ 401k, 25fps, video only, 186.12MiB
247          webm       1280x720   720p  339k , webm_dash container, vp9@ 339k, 25fps, video only, 157.33MiB
136          mp4        1280x720   720p  826k , mp4_dash container, avc1.64001f@ 826k, 25fps, video only, 383.11MiB
18           mp4        640x360    360p  372k , avc1.42001E, 25fps, mp4a.40.2 (44100Hz), 172.76MiB
22           mp4        1280x720   720p  955k , avc1.64001F, 25fps, mp4a.40.2 (44100Hz) (best)
$