youtube-dl: youtube_dl.utils.ExtractorError: Could not find JS function 'na'

Checklist

  • I’m reporting a broken site support issue
  • I’ve verified that I’m running youtube-dl version 2021.06.06
  • 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 bug reports including closed ones
  • I’ve read bugs section in FAQ

Verbose log

$ youtube-dl --verbose https://youtu.be/nXPyDlvZ1oQ
[debug] System config: []
[debug] User config: ['--format', 'bestvideo+bestaudio[ext=m4a]/bestvideo+bestaudio/best', '--merge-output-format', 'mp4', '-o', '/data/data/com.termux/files/home/storage/dcim/Camera/%(extractor_key)s-%(uploader)s-%(title)s-%(id)s.%(ext)s', '--no-mtime']
[debug] Custom config: []
[debug] Command-line args: ['--verbose', 'https://youtu.be/nXPyDlvZ1oQ']
[debug] Encodings: locale UTF-8, fs utf-8, out utf-8, pref UTF-8
[debug] youtube-dl version 2021.06.06
[debug] Python version 3.9.1 (CPython) - Linux-4.14.190-22338387-abN975USQS7FUI6-aarch64-with-libc
[debug] exe versions: ffmpeg 4.3.1, ffprobe 4.3.1
[debug] Proxy map: {}
[youtube] nXPyDlvZ1oQ: Downloading webpage
[youtube] nXPyDlvZ1oQ: Downloading player 204bfffb
ERROR: Signature extraction failed: Traceback (most recent call last):
  File "/data/data/com.termux/files/usr/lib/python3.9/site-packages/youtube_dl/extractor/youtube.py", line 1348, in _decrypt_signature
    func = self._extract_signature_function(
  File "/data/data/com.termux/files/usr/lib/python3.9/site-packages/youtube_dl/extractor/youtube.py", line 1262, in _extract_signature_function
    res = self._parse_sig_js(code)
  File "/data/data/com.termux/files/usr/lib/python3.9/site-packages/youtube_dl/extractor/youtube.py", line 1331, in _parse_sig_js
    initial_function = jsi.extract_function(funcname)
  File "/data/data/com.termux/files/usr/lib/python3.9/site-packages/youtube_dl/jsinterp.py", line 245, in extract_function
    raise ExtractorError('Could not find JS function %r' % funcname)
youtube_dl.utils.ExtractorError: Could not find JS function 'na'; 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.
 (caused by ExtractorError("Could not find JS function 'na'; 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.")); 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 "/data/data/com.termux/files/usr/lib/python3.9/site-packages/youtube_dl/extractor/youtube.py", line 1348, in _decrypt_signature
    func = self._extract_signature_function(
  File "/data/data/com.termux/files/usr/lib/python3.9/site-packages/youtube_dl/extractor/youtube.py", line 1262, in _extract_signature_function
    res = self._parse_sig_js(code)
  File "/data/data/com.termux/files/usr/lib/python3.9/site-packages/youtube_dl/extractor/youtube.py", line 1331, in _parse_sig_js
    initial_function = jsi.extract_function(funcname)
  File "/data/data/com.termux/files/usr/lib/python3.9/site-packages/youtube_dl/jsinterp.py", line 245, in extract_function
    raise ExtractorError('Could not find JS function %r' % funcname)
youtube_dl.utils.ExtractorError: Could not find JS function 'na'; 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 "/data/data/com.termux/files/usr/lib/python3.9/site-packages/youtube_dl/extractor/youtube.py", line 1348, in _decrypt_signature
    func = self._extract_signature_function(
  File "/data/data/com.termux/files/usr/lib/python3.9/site-packages/youtube_dl/extractor/youtube.py", line 1262, in _extract_signature_function
    res = self._parse_sig_js(code)
  File "/data/data/com.termux/files/usr/lib/python3.9/site-packages/youtube_dl/extractor/youtube.py", line 1331, in _parse_sig_js
    initial_function = jsi.extract_function(funcname)
  File "/data/data/com.termux/files/usr/lib/python3.9/site-packages/youtube_dl/jsinterp.py", line 245, in extract_function
    raise ExtractorError('Could not find JS function %r' % funcname)
youtube_dl.utils.ExtractorError: Could not find JS function 'na'; 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.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/data/data/com.termux/files/usr/lib/python3.9/site-packages/youtube_dl/YoutubeDL.py", line 815, in wrapper
    return func(self, *args, **kwargs)
  File "/data/data/com.termux/files/usr/lib/python3.9/site-packages/youtube_dl/YoutubeDL.py", line 836, in __extract_info
    ie_result = ie.extract(url)
  File "/data/data/com.termux/files/usr/lib/python3.9/site-packages/youtube_dl/extractor/common.py", line 534, in extract
    ie_result = self._real_extract(url)
  File "/data/data/com.termux/files/usr/lib/python3.9/site-packages/youtube_dl/extractor/youtube.py", line 1623, in _real_extract
    signature = self._decrypt_signature(sc['s'][0], video_id, player_url)
  File "/data/data/com.termux/files/usr/lib/python3.9/site-packages/youtube_dl/extractor/youtube.py", line 1358, in _decrypt_signature
    raise ExtractorError(
youtube_dl.utils.ExtractorError: Signature extraction failed: Traceback (most recent call last):
  File "/data/data/com.termux/files/usr/lib/python3.9/site-packages/youtube_dl/extractor/youtube.py", line 1348, in _decrypt_signature
    func = self._extract_signature_function(
  File "/data/data/com.termux/files/usr/lib/python3.9/site-packages/youtube_dl/extractor/youtube.py", line 1262, in _extract_signature_function
    res = self._parse_sig_js(code)
  File "/data/data/com.termux/files/usr/lib/python3.9/site-packages/youtube_dl/extractor/youtube.py", line 1331, in _parse_sig_js
    initial_function = jsi.extract_function(funcname)
  File "/data/data/com.termux/files/usr/lib/python3.9/site-packages/youtube_dl/jsinterp.py", line 245, in extract_function
    raise ExtractorError('Could not find JS function %r' % funcname)
youtube_dl.utils.ExtractorError: Could not find JS function 'na'; 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.
 (caused by ExtractorError("Could not find JS function 'na'; 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.")); 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

Trying to download video with either url or just video code returns the indicated error

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 78
  • Comments: 89 (16 by maintainers)

Commits related to this issue

Most upvoted comments

I have submitted a PR (#30366) that resolves this issue. It looks like no PRs have been merged to master in quite some time now, so if you’re really in a pinch to resolve this quickly, consider making the changes yourself to extractor/youtube.py in your local environments according to the changes in #30366 , as it is a simple fix (if you are brazen enough to do so).

The problem lies in that Youtube has apparently made some change in their base.js such that the signature parser is taking issue with changes evident in the function signature format. Most are 2 characters (as the regex in the parser assumes) but it seems that 2 characters can no longer be assumed after their update for these signatures. Just needed to tweak the regex to account for that, and I haven’t been able to replicate any of these issues since. You can see this for yourself by reviewing base.js at this link: https://www.youtube.com/s/player/850eb2bc/player_ias.vflset/en_US/base.js

Note that this finding was originally made in this PR for yt-dlp and is not mine: yt-dlp/yt-dlp#641. This fix for yt-dlp was spotted by @coletdjnz (good spot) in his earlier comment to this thread.

Official YT-DL working! Big big thanks for developers. Love u

For those that are struggling and are here for an easy fix as @lanegramling did a PR in the original repo, and forked it as well: (EDITED with https://github.com/ytdl-org/youtube-dl/issues/30363#issuecomment-995121012)

  1. git clone --depth 1 --branch fix-function-sig-parser https://github.com/lanegramling/youtube-dl.git
  2. cd youtube_dl
  3. pip install -e .
  4. youtube-dl {youtube_url}

the link to @lanegramling PR is wrong, to see what @lanegramling has changed to reapply to local files see https://github.com/ytdl-org/youtube-dl/pull/30366/commits/1a091687c248b62c2f0a6070519bd78417828746

It’s quite easy, only 4 lines need changing, all at one place. You just need a few commas in regex.

Looks like youtube-dl needs to update the signature function regex.

There is no issue in yt-dlp, seems like this was avoided by https://github.com/yt-dlp/yt-dlp/pull/641.

Back-porting them from yt-dlp works. Relevant code: https://github.com/yt-dlp/yt-dlp/blob/0bb322b9c0aebb7e0a93a5de1dbede4acdd10ff5/yt_dlp/extractor/youtube.py#L1828-L1845

Edit: Given the above patch by https://github.com/yt-dlp/yt-dlp/pull/641, it may be possible that future player js versions may work again (but also break again at times for the same reason) with existing code.

Correction to this helpful comment:

git clone --depth 1 --branch fix-function-sig-parser https://github.com/lanegramling/youtube-dl.git

Yeah, I recommend to use yt-dlp or smthn like this, because there is no bug and creators support their creation and i use module in js (yt-dlp-exec) , which has no changes with old and good youtube-dl-exec.

See updated script below.

For the benefit of the impatient reader, here is how I applied the single file fix of PR #30366 to the lastest binary youtube-dl on Linux:

$ ./youtube-dl $VIDEO
# fails with something like: ExtractorError: Could not find JS function u'na';

$ ./youtube-dl -U
youtube-dl is up-to-date (2021.06.06)

$ mkdir -p youtube_dl/extractor
$ wget -O youtube_dl/extractor/youtube.py https://github.com/ytdl-org/youtube-dl/raw/1a091687c248b62c2f0a6070519bd78417828746/youtube_dl/extractor/youtube.py
$ tail +2 youtube-dl > youtube-dl.zip 
$ zip youtube-dl.zip youtube_dl/extractor/youtube.py 
updating: youtube_dl/extractor/youtube.py (deflated 77%)
$ { head -1 youtube-dl; cat youtube-dl.zip; } > youtube-dl.fixed
$ chmod +x youtube-dl.fixed

$ ./youtube-dl.fixed $VIDEO
# works

Notes:

Update

Here is a bash (yes, you need bash. Neither dash nor ksh probably grok this) script to create a youtube-dl.fixed from PR #30184 (which apparently already includes PR #30366, sorry for me getting this detail wrong above). After this I get full speed, too (as fast as my cable can do):

#!/bin/bash
#
# ./youtube-dl -U
# youtube-dl is up-to-date (2021.06.06)
#
# ./youtube-dl $VIDEO
# fails with something like: ExtractorError: Could not find JS function u'na';
# and even if it was working, it is slow
#
# Supports inplace-upgrade, too, if you dare:
# cp youtube-dl youtube-dl.orig; ln -s youtube-dl youtube-dl.fixed
#
# Sorry for the mess, the script was done in a hurry.

FIXES=(
https://github.com/ytdl-org/youtube-dl/raw/32f049b37a08cb092190f63a0276155ca54a5a44/youtube_dl/compat.py
https://github.com/ytdl-org/youtube-dl/raw/32f049b37a08cb092190f63a0276155ca54a5a44/youtube_dl/extractor/youtube.py
);

head="$(head -1 youtube-dl)";
tail +2 youtube-dl.orig > youtube-dl.zip;
mkdir -p youtube_dl/extractor;
for a in "${FIXES[@]}";
do
  wget -O "${a#*/raw/*/}" "$a";
  zip youtube-dl.zip "${a#*/raw/*/}" "$a";
done;
{ echo "$head"; cat youtube-dl.zip; } > youtube-dl.fixed;
chmod +x youtube-dl.fixed;

Thanks for this goes to all the contributers of youtube-dl!

Same issue, macOS Monterey

switch your dependency to yt-dlp (it’s youtube-dl but actively maintained).

This was a good advice. The fork works well.

(although I am usually not a fan of using someone’s repo to promote another, in this case I feel people are desperate for a quick solution that may never come.)

Looks like youtube-dl needs to update the signature function regex.

There is no issue in yt-dlp, seems like this was avoided by yt-dlp/yt-dlp#641.

Back-porting them from yt-dlp works. Relevant code: https://github.com/yt-dlp/yt-dlp/blob/0bb322b9c0aebb7e0a93a5de1dbede4acdd10ff5/yt_dlp/extractor/youtube.py#L1828-L1845

Edit: Given the above patch by yt-dlp/yt-dlp#641, it may be possible that future player js versions may work again (but also break again at times for the same reason) with existing code.

If I understand correctly, we just need to wait and our bot will work again in the future ?

Yes, possibly. But it is likely this will occur again.

Though tbh if you can I’d just switch your dependency to yt-dlp (it’s youtube-dl but actively maintained).

@dirkf Thanks for the hint and sorry for me getting it wrong at first. My bad English.

Updated my comment with a script which patches both files from the other PR.

To all others:

  • It is meant to be used with the Linux binary (zipped Python) for Linux (and probably Mac) version 2021.06.06 which must be named youtube-dl and must reside in the current directory
  • You need to run ./youtube-dl.fixed afterwards, as the script does not overwrite the precious youtube-dl original.
  • It’s a quick hack without proper error processing. So if something breaks, you are left alone, sorry.

If only there were some way to organise a hodgepodge of random patches into a derivative project.

As your yt-dl is in site-packages, it’s not a Fedora issue (if the distro had installed it, it would be in dist-packages).

You can apply the single file update over /usr/lib/python3.10/site-packages/youtube_dl/extractor/youtube.py.

I switched to yt-dlp. One unexpected benefit: download speed is much better (youtube-dl got slower and slower in the last few months. I thought this was google throttling me and shrugged)

yt-dlp has the same issue

I just installed the latest version from pip and it works. Make sure you’ve updated yt-dlp.

You’re up a creek without a paddle here, as we all are, to fend for ourselves. The master branch has not seen anything new in 6 months. So there is no existence of the one-step solution to reclaiming a binary you seek. You will have to follow the extra steps to create/collect one yourself if you want to use a binary version. He laid out a great step-by-step, unfortunately your only choices are A) follow it, B) wait indefinitely (likely months or never) for the miraculous return of someone that can pull it into master, or C) switch packages and update your codebases to support the migration. All of the options are bad options, unfortunately…

This brings up an issue in Github. Some of the better programs have dozens, even hundreds, of branches. A system of grading the variants would be useful, at least an icon in the listing to indicate no change/activity in the branch.

I need a solution for my Discord bot written in python please help me with this issue

yes the same issue here, please fix this asap or someone show me the way how can i fix this

Real shame. It is a tool I use daily. No it is unfunctional for (probably) a long time

Give us a hint about what kind of installation you have and how updating it failed.

Damn, this is a mess. I can’t find any comment for a fix of youtube-dl installed with brew on macOS. Could someone point me to it?

Fixed in PR #30366, single file signature+unthrottling update from PR #30184.

Can anyone create a new repo for youtube_dl with fixes so that I can download updated file

So, is there any solution or patch?

I have posted the solution in this thread above. For now you will have to implement it yourself in your local environment. It is a simple change. No PRs have been merged to master in months, so we can’t really expect a fix to be merged through the official channels in any reasonable amount of time.

Same issue on Fedora 35:

[debug] System config: ['--prefer-free-formats']
[debug] User config: []
[debug] Custom config: []
[debug] Command-line args: ['--verbose', 'https://www.youtube.com/watch?v=kHjzuqq3b44']
[debug] Encodings: locale UTF-8, fs utf-8, out utf-8, pref UTF-8
[debug] youtube-dl version 2021.06.06
[debug] Python version 3.10.0 (CPython) - Linux-5.15.6-200.fc35.x86_64-x86_64-with-glibc2.34
[debug] exe versions: ffmpeg 4.4.1, ffprobe 4.4.1
[debug] Proxy map: {}
[youtube] kHjzuqq3b44: Downloading webpage
[youtube] kHjzuqq3b44: Downloading player 204bfffb
ERROR: Signature extraction failed: Traceback (most recent call last):
  File "/usr/lib/python3.10/site-packages/youtube_dl/extractor/youtube.py", line 1348, in _decrypt_signature
    func = self._extract_signature_function(
  File "/usr/lib/python3.10/site-packages/youtube_dl/extractor/youtube.py", line 1262, in _extract_signature_function
    res = self._parse_sig_js(code)
  File "/usr/lib/python3.10/site-packages/youtube_dl/extractor/youtube.py", line 1331, in _parse_sig_js
    initial_function = jsi.extract_function(funcname)
  File "/usr/lib/python3.10/site-packages/youtube_dl/jsinterp.py", line 245, in extract_function
    raise ExtractorError('Could not find JS function %r' % funcname)
youtube_dl.utils.ExtractorError: Could not find JS function 'na'; 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.
 (caused by ExtractorError("Could not find JS function 'na'; 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.")); 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 "/usr/lib/python3.10/site-packages/youtube_dl/extractor/youtube.py", line 1348, in _decrypt_signature
    func = self._extract_signature_function(
  File "/usr/lib/python3.10/site-packages/youtube_dl/extractor/youtube.py", line 1262, in _extract_signature_function
    res = self._parse_sig_js(code)
  File "/usr/lib/python3.10/site-packages/youtube_dl/extractor/youtube.py", line 1331, in _parse_sig_js
    initial_function = jsi.extract_function(funcname)
  File "/usr/lib/python3.10/site-packages/youtube_dl/jsinterp.py", line 245, in extract_function
    raise ExtractorError('Could not find JS function %r' % funcname)
youtube_dl.utils.ExtractorError: Could not find JS function 'na'; 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 "/usr/lib/python3.10/site-packages/youtube_dl/extractor/youtube.py", line 1348, in _decrypt_signature
    func = self._extract_signature_function(
  File "/usr/lib/python3.10/site-packages/youtube_dl/extractor/youtube.py", line 1262, in _extract_signature_function
    res = self._parse_sig_js(code)
  File "/usr/lib/python3.10/site-packages/youtube_dl/extractor/youtube.py", line 1331, in _parse_sig_js
    initial_function = jsi.extract_function(funcname)
  File "/usr/lib/python3.10/site-packages/youtube_dl/jsinterp.py", line 245, in extract_function
    raise ExtractorError('Could not find JS function %r' % funcname)
youtube_dl.utils.ExtractorError: Could not find JS function 'na'; 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.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.10/site-packages/youtube_dl/YoutubeDL.py", line 814, in wrapper
    return func(self, *args, **kwargs)
  File "/usr/lib/python3.10/site-packages/youtube_dl/YoutubeDL.py", line 835, in __extract_info
    ie_result = ie.extract(url)
  File "/usr/lib/python3.10/site-packages/youtube_dl/extractor/common.py", line 534, in extract
    ie_result = self._real_extract(url)
  File "/usr/lib/python3.10/site-packages/youtube_dl/extractor/youtube.py", line 1623, in _real_extract
    signature = self._decrypt_signature(sc['s'][0], video_id, player_url)
  File "/usr/lib/python3.10/site-packages/youtube_dl/extractor/youtube.py", line 1358, in _decrypt_signature
    raise ExtractorError(
youtube_dl.utils.ExtractorError: Signature extraction failed: Traceback (most recent call last):
  File "/usr/lib/python3.10/site-packages/youtube_dl/extractor/youtube.py", line 1348, in _decrypt_signature
    func = self._extract_signature_function(
  File "/usr/lib/python3.10/site-packages/youtube_dl/extractor/youtube.py", line 1262, in _extract_signature_function
    res = self._parse_sig_js(code)
  File "/usr/lib/python3.10/site-packages/youtube_dl/extractor/youtube.py", line 1331, in _parse_sig_js
    initial_function = jsi.extract_function(funcname)
  File "/usr/lib/python3.10/site-packages/youtube_dl/jsinterp.py", line 245, in extract_function
    raise ExtractorError('Could not find JS function %r' % funcname)
youtube_dl.utils.ExtractorError: Could not find JS function 'na'; 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.
 (caused by ExtractorError("Could not find JS function 'na'; 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.")); 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.