Repository: yt-dlp/yt-dlp
Issue category: Bug Report

[youtube] player `3bb1f723`: Signature extraction failed: Some formats may be missing
### DO NOT REMOVE OR SKIP THE ISSUE TEMPLATE

- [X] I understand that I will be **blocked** if I *intentionally* remove or skip any mandatory\* field

### Checklist

- [X] I'm reporting that yt-dlp is broken on a **supported** site
- [X] I've verified that I have **updated yt-dlp to nightly or master** ([update instructions](https://github.com/yt-dlp/yt-dlp#update-channels))
- [X] I've checked that all provided URLs are playable in a browser with the same IP and same login details
- [X] I've checked that all URLs and arguments with special characters are [properly quoted or escaped](https://github.com/yt-dlp/yt-dlp/wiki/FAQ#video-url-contains-an-ampersand--and-im-getting-some-strange-output-1-2839-or-v-is-not-recognized-as-an-internal-or-external-command)
- [X] I've searched [known issues](https://github.com/yt-dlp/yt-dlp/issues/3766) and the [bugtracker](https://github.com/yt-dlp/yt-dlp/issues?q=) for similar issues **including closed ones**. DO NOT post duplicates
- [X] I've read the [guidelines for opening an issue](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#opening-an-issue)
- [X] I've read about [sharing account credentials](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#are-you-willing-to-share-account-details-if-needed) and I'm willing to share it if required

### Region

USA

### Provide a description that is worded well enough to be understood

im using the nightly build with a system config file. that is it.

the config file contents are: 
```
$ cat /etc/yt-dlp.conf

--cookies /home/ubuntu/PycharmProjects/cookiesRefresher/cookies.txt
```

the cookie file is refreshed every 24 hours and uses a dummy google account.

this setup used to work less than a week ago but now is broken. i havent changed anything. 
today google asked me to verify this acoount. i verfied with a phone number and i was able to play videos on the same machine on a firefox browser.

yt-dlp version and debug info:
```
$  yt-dlp -vU
[debug] Command-line config: ['-vU']
[debug] System config "/etc/yt-dlp.conf": ['--cookies', '/home/ubuntu/PycharmProjects/cookiesRefresher/cookies.txt']
[debug] Encodings: locale UTF-8, fs utf-8, pref UTF-8, out utf-8, error utf-8, screen utf-8
[debug] yt-dlp version nightly@2024.12.04.232942 from yt-dlp/yt-dlp-nightly-builds [fca3eb5f8]
[debug] Python 3.12.3 (CPython aarch64 64bit) - Linux-6.8.0-1016-oracle-aarch64-with-glibc2.39 (OpenSSL 3.0.13 30 Jan 2024, glibc 2.39)
[debug] exe versions: ffmpeg 6.1.1 (setts), ffprobe 6.1.1
[debug] Optional libraries: Cryptodome-3.21.0, brotli-1.1.0, certifi-2024.08.30, mutagen-1.47.0, requests-2.32.3, sqlite3-3.45.1, urllib3-2.2.3, websockets-14.1
[debug] Proxy map: {}
[debug] Request Handlers: urllib, requests, websockets
[debug] Loaded 1837 extractors
[debug] Fetching release info: https://api.github.com/repos/yt-dlp/yt-dlp-nightly-builds/releases/latest
Latest version: nightly@2024.12.04.232942 from yt-dlp/yt-dlp-nightly-builds
yt-dlp is up to date (nightly@2024.12.04.232942 from yt-dlp/yt-dlp-nightly-builds)
```

when attempting to download a video:

```
yt-dlp https://www.youtube.com/watch?v=yaie5Uia4k8 -vU
[debug] Command-line config: ['https://www.youtube.com/watch?v=yaie5Uia4k8', '-vU']
[debug] System config "/etc/yt-dlp.conf": ['--cookies', '/home/ubuntu/PycharmProjects/cookiesRefresher/cookies.txt']
[debug] Encodings: locale UTF-8, fs utf-8, pref UTF-8, out utf-8, error utf-8, screen utf-8
[debug] yt-dlp version nightly@2024.12.04.232942 from yt-dlp/yt-dlp-nightly-builds [fca3eb5f8]
[debug] Python 3.12.3 (CPython aarch64 64bit) - Linux-6.8.0-1016-oracle-aarch64-with-glibc2.39 (OpenSSL 3.0.13 30 Jan 2024, glibc 2.39)
[debug] exe versions: ffmpeg 6.1.1 (setts), ffprobe 6.1.1
[debug] Optional libraries: Cryptodome-3.21.0, brotli-1.1.0, certifi-2024.08.30, mutagen-1.47.0, requests-2.32.3, sqlite3-3.45.1, urllib3-2.2.3, websockets-14.1
[debug] Proxy map: {}
[debug] Request Handlers: urllib, requests, websockets
[debug] Loaded 1837 extractors
[debug] Fetching release info: https://api.github.com/repos/yt-dlp/yt-dlp-nightly-builds/releases/latest
Latest version: nightly@2024.12.04.232942 from yt-dlp/yt-dlp-nightly-builds
yt-dlp is up to date (nightly@2024.12.04.232942 from yt-dlp/yt-dlp-nightly-builds)
[youtube] Extracting URL: https://www.youtube.com/watch?v=yaie5Uia4k8
[youtube] yaie5Uia4k8: Downloading webpage
[debug] [youtube] Extracted SAPISID cookie
[youtube] yaie5Uia4k8: Downloading web creator player API JSON
[youtube] yaie5Uia4k8: Downloading mweb player API JSON
[debug] [youtube] Extracting signature function js_3bb1f723_106
[youtube] yaie5Uia4k8: Downloading player 3bb1f723
WARNING: [youtube] yaie5Uia4k8: Signature extraction failed: Some formats may be missing
[debug] [youtube] Could not find JS function "decodeURIComponent"; please report this issue on  https://github.com/yt-dlp/yt-dlp/issues?q= , filling out the appropriate issue template. Confirm you are on the latest version using  yt-dlp -U
[debug] [youtube] Extracting signature function js_3bb1f723_110
WARNING: Only images are available for download. use --list-formats to see them
[debug] Sort order given by extractor: quality, res, fps, hdr:12, source, vcodec, channels, acodec, lang, proto
[debug] Formats sorted by: hasvid, ie_pref, quality, res, fps, hdr:12(7), source, vcodec, channels, acodec, lang, proto, size, br, asr, vext, aext, hasaud, id
[debug] Default format spec: bestvideo*+bestaudio/best
ERROR: [youtube] yaie5Uia4k8: Requested format is not available. Use --list-formats for a list of available formats
Traceback (most recent call last):
  File "/home/ubuntu/.local/pipx/venvs/yt-dlp/lib/python3.12/site-packages/yt_dlp/YoutubeDL.py", line 1624, in wrapper
    return func(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ubuntu/.local/pipx/venvs/yt-dlp/lib/python3.12/site-packages/yt_dlp/YoutubeDL.py", line 1780, in __extract_info
    return self.process_ie_result(ie_result, download, extra_info)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ubuntu/.local/pipx/venvs/yt-dlp/lib/python3.12/site-packages/yt_dlp/YoutubeDL.py", line 1839, in process_ie_result
    ie_result = self.process_video_result(ie_result, download=download)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ubuntu/.local/pipx/venvs/yt-dlp/lib/python3.12/site-packages/yt_dlp/YoutubeDL.py", line 2973, in process_video_result
    raise ExtractorError(
yt_dlp.utils.ExtractorError: [youtube] yaie5Uia4k8: Requested format is not available. Use --list-formats for a list of available formats

```


attempting to download the same video while ignoring the config fie:

```
$ yt-dlp https://www.youtube.com/watch?v=e8i32DH5rhQ --ignore-config -vU
[debug] Command-line config: ['https://www.youtube.com/watch?v=e8i32DH5rhQ', '--ignore-config', '-vU']
[debug] Encodings: locale UTF-8, fs utf-8, pref UTF-8, out utf-8, error utf-8, screen utf-8
[debug] yt-dlp version nightly@2024.12.04.232942 from yt-dlp/yt-dlp-nightly-builds [fca3eb5f8]
[debug] Python 3.12.3 (CPython aarch64 64bit) - Linux-6.8.0-1016-oracle-aarch64-with-glibc2.39 (OpenSSL 3.0.13 30 Jan 2024, glibc 2.39)
[debug] exe versions: ffmpeg 6.1.1 (setts), ffprobe 6.1.1
[debug] Optional libraries: Cryptodome-3.21.0, brotli-1.1.0, certifi-2024.08.30, mutagen-1.47.0, requests-2.32.3, sqlite3-3.45.1, urllib3-2.2.3, websockets-14.1
[debug] Proxy map: {}
[debug] Request Handlers: urllib, requests, websockets
[debug] Loaded 1837 extractors
[debug] Fetching release info: https://api.github.com/repos/yt-dlp/yt-dlp-nightly-builds/releases/latest
Latest version: nightly@2024.12.04.232942 from yt-dlp/yt-dlp-nightly-builds
yt-dlp is up to date (nightly@2024.12.04.232942 from yt-dlp/yt-dlp-nightly-builds)
[youtube] Extracting URL: https://www.youtube.com/watch?v=e8i32DH5rhQ
[youtube] e8i32DH5rhQ: Downloading webpage
[youtube] e8i32DH5rhQ: Downloading ios player API JSON
[youtube] e8i32DH5rhQ: Downloading mweb player API JSON
ERROR: [youtube] e8i32DH5rhQ: Sign in to confirm you’re not a bot. Use --cookies-from-browser or --cookies for the authentication. See  https://github.com/yt-dlp/yt-dlp/wiki/FAQ#how-do-i-pass-cookies-to-yt-dlp  for how to manually pass cookies. Also see  https://github.com/yt-dlp/yt-dlp/wiki/Extractors#exporting-youtube-cookies  for tips on effectively exporting YouTube cookies
  File "/home/ubuntu/.local/pipx/venvs/yt-dlp/lib/python3.12/site-packages/yt_dlp/extractor/common.py", line 742, in extract
    ie_result = self._real_extract(url)
                ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ubuntu/.local/pipx/venvs/yt-dlp/lib/python3.12/site-packages/yt_dlp/extractor/youtube.py", line 4478, in _real_extract
    self.raise_no_formats(reason, expected=True)
  File "/home/ubuntu/.local/pipx/venvs/yt-dlp/lib/python3.12/site-packages/yt_dlp/extractor/common.py", line 1276, in raise_no_formats
    raise ExtractorError(msg, expected=expected, video_id=video_id)

```

### Provide verbose output that clearly demonstrates the problem

- [X] Run **your** yt-dlp command with **-vU** flag added (`yt-dlp -vU <your command line>`)
- [ ] If using API, add `'verbose': True` to `YoutubeDL` params instead
- [X] Copy the WHOLE output (starting with `[debug] Command-line config`) and insert it below

### Complete Verbose Output

```shell
yt-dlp https://www.youtube.com/watch?v=yaie5Uia4k8 -vU
[debug] Command-line config: ['https://www.youtube.com/watch?v=yaie5Uia4k8', '-vU']
[debug] System config "/etc/yt-dlp.conf": ['--cookies', '/home/ubuntu/PycharmProjects/cookiesRefresher/cookies.txt']
[debug] Encodings: locale UTF-8, fs utf-8, pref UTF-8, out utf-8, error utf-8, screen utf-8
[debug] yt-dlp version nightly@2024.12.04.232942 from yt-dlp/yt-dlp-nightly-builds [fca3eb5f8]
[debug] Python 3.12.3 (CPython aarch64 64bit) - Linux-6.8.0-1016-oracle-aarch64-with-glibc2.39 (OpenSSL 3.0.13 30 Jan 2024, glibc 2.39)
[debug] exe versions: ffmpeg 6.1.1 (setts), ffprobe 6.1.1
[debug] Optional libraries: Cryptodome-3.21.0, brotli-1.1.0, certifi-2024.08.30, mutagen-1.47.0, requests-2.32.3, sqlite3-3.45.1, urllib3-2.2.3, websockets-14.1
[debug] Proxy map: {}
[debug] Request Handlers: urllib, requests, websockets
[debug] Loaded 1837 extractors
[debug] Fetching release info: https://api.github.com/repos/yt-dlp/yt-dlp-nightly-builds/releases/latest
Latest version: nightly@2024.12.04.232942 from yt-dlp/yt-dlp-nightly-builds
yt-dlp is up to date (nightly@2024.12.04.232942 from yt-dlp/yt-dlp-nightly-builds)
[youtube] Extracting URL: https://www.youtube.com/watch?v=yaie5Uia4k8
[youtube] yaie5Uia4k8: Downloading webpage
[debug] [youtube] Extracted SAPISID cookie
[youtube] yaie5Uia4k8: Downloading web creator player API JSON
[youtube] yaie5Uia4k8: Downloading mweb player API JSON
[debug] [youtube] Extracting signature function js_3bb1f723_110
[youtube] yaie5Uia4k8: Downloading player 3bb1f723
WARNING: [youtube] yaie5Uia4k8: Signature extraction failed: Some formats may be missing
[debug] [youtube] Could not find JS function "decodeURIComponent"; please report this issue on  https://github.com/yt-dlp/yt-dlp/issues?q= , filling out the appropriate issue template. Confirm you are on the latest version using  yt-dlp -U
[debug] [youtube] Extracting signature function js_3bb1f723_106
WARNING: Only images are available for download. use --list-formats to see them
[debug] Sort order given by extractor: quality, res, fps, hdr:12, source, vcodec, channels, acodec, lang, proto
[debug] Formats sorted by: hasvid, ie_pref, quality, res, fps, hdr:12(7), source, vcodec, channels, acodec, lang, proto, size, br, asr, vext, aext, hasaud, id
[debug] Default format spec: bestvideo*+bestaudio/best
ERROR: [youtube] yaie5Uia4k8: Requested format is not available. Use --list-formats for a list of available formats
Traceback (most recent call last):
  File "/home/ubuntu/.local/pipx/venvs/yt-dlp/lib/python3.12/site-packages/yt_dlp/YoutubeDL.py", line 1624, in wrapper
    return func(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ubuntu/.local/pipx/venvs/yt-dlp/lib/python3.12/site-packages/yt_dlp/YoutubeDL.py", line 1780, in __extract_info
    return self.process_ie_result(ie_result, download, extra_info)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ubuntu/.local/pipx/venvs/yt-dlp/lib/python3.12/site-packages/yt_dlp/YoutubeDL.py", line 1839, in process_ie_result
    ie_result = self.process_video_result(ie_result, download=download)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ubuntu/.local/pipx/venvs/yt-dlp/lib/python3.12/site-packages/yt_dlp/YoutubeDL.py", line 2973, in process_video_result
    raise ExtractorError(
yt_dlp.utils.ExtractorError: [youtube] yaie5Uia4k8: Requested format is not available. Use --list-formats for a list of available formats
```



Functions to edit:
yt_dlp/extractor/youtube.py:YoutubeIE._parse_sig_js

Patch:
diff --git a/yt_dlp/extractor/youtube.py b/yt_dlp/extractor/youtube.py
index 83dde7d9c41f..c9b83161871d 100644
--- a/yt_dlp/extractor/youtube.py
+++ b/yt_dlp/extractor/youtube.py
@@ -3119,19 +3119,26 @@ def _genslice(start, end, step):
         self.to_screen('Extracted signature function:\n' + code)
 
     def _parse_sig_js(self, jscode):
+        # Examples where `sig` is funcname:
+        # sig=function(a){a=a.split(""); ... ;return a.join("")};
+        # ;c&&(c=sig(decodeURIComponent(c)),a.set(b,encodeURIComponent(c)));return a};
+        # {var l=f,m=h.sp,n=sig(decodeURIComponent(h.s));l.set(m,encodeURIComponent(n))}
+        # sig=function(J){J=J.split(""); ... ;return J.join("")};
+        # ;N&&(N=sig(decodeURIComponent(N)),J.set(R,encodeURIComponent(N)));return J};
+        # {var H=u,k=f.sp,v=sig(decodeURIComponent(f.s));H.set(k,encodeURIComponent(v))}
         funcname = self._search_regex(
-            (r'\b[cs]\s*&&\s*[adf]\.set\([^,]+\s*,\s*encodeURIComponent\s*\(\s*(?P<sig>[a-zA-Z0-9$]+)\(',
+            (r'\b(?P<var>[a-zA-Z0-9$]+)&&\((?P=var)=(?P<sig>[a-zA-Z0-9$]{2,})\(decodeURIComponent\((?P=var)\)\)',
+             r'(?P<sig>[a-zA-Z0-9$]+)\s*=\s*function\(\s*(?P<arg>[a-zA-Z0-9$]+)\s*\)\s*{\s*(?P=arg)\s*=\s*(?P=arg)\.split\(\s*""\s*\)\s*;\s*[^}]+;\s*return\s+(?P=arg)\.join\(\s*""\s*\)',
+             r'(?:\b|[^a-zA-Z0-9$])(?P<sig>[a-zA-Z0-9$]{2,})\s*=\s*function\(\s*a\s*\)\s*{\s*a\s*=\s*a\.split\(\s*""\s*\)(?:;[a-zA-Z0-9$]{2}\.[a-zA-Z0-9$]{2}\(a,\d+\))?',
+             # Old patterns
+             r'\b[cs]\s*&&\s*[adf]\.set\([^,]+\s*,\s*encodeURIComponent\s*\(\s*(?P<sig>[a-zA-Z0-9$]+)\(',
              r'\b[a-zA-Z0-9]+\s*&&\s*[a-zA-Z0-9]+\.set\([^,]+\s*,\s*encodeURIComponent\s*\(\s*(?P<sig>[a-zA-Z0-9$]+)\(',
              r'\bm=(?P<sig>[a-zA-Z0-9$]{2,})\(decodeURIComponent\(h\.s\)\)',
-             r'\bc&&\(c=(?P<sig>[a-zA-Z0-9$]{2,})\(decodeURIComponent\(c\)\)',
-             r'(?:\b|[^a-zA-Z0-9$])(?P<sig>[a-zA-Z0-9$]{2,})\s*=\s*function\(\s*a\s*\)\s*{\s*a\s*=\s*a\.split\(\s*""\s*\)(?:;[a-zA-Z0-9$]{2}\.[a-zA-Z0-9$]{2}\(a,\d+\))?',
-             r'(?P<sig>[a-zA-Z0-9$]+)\s*=\s*function\(\s*a\s*\)\s*{\s*a\s*=\s*a\.split\(\s*""\s*\)',
              # Obsolete patterns
              r'("|\')signature\1\s*,\s*(?P<sig>[a-zA-Z0-9$]+)\(',
              r'\.sig\|\|(?P<sig>[a-zA-Z0-9$]+)\(',
              r'yt\.akamaized\.net/\)\s*\|\|\s*.*?\s*[cs]\s*&&\s*[adf]\.set\([^,]+\s*,\s*(?:encodeURIComponent\s*\()?\s*(?P<sig>[a-zA-Z0-9$]+)\(',
              r'\b[cs]\s*&&\s*[adf]\.set\([^,]+\s*,\s*(?P<sig>[a-zA-Z0-9$]+)\(',
-             r'\b[a-zA-Z0-9]+\s*&&\s*[a-zA-Z0-9]+\.set\([^,]+\s*,\s*(?P<sig>[a-zA-Z0-9$]+)\(',
              r'\bc\s*&&\s*[a-zA-Z0-9]+\.set\([^,]+\s*,\s*\([^)]*\)\s*\(\s*(?P<sig>[a-zA-Z0-9$]+)\('),
             jscode, 'Initial JS player signature function name', group='sig')
 

Test patch: diff --git a/test/test_youtube_signature.py b/test/test_youtube_signature.py
index 0f7ae34f44f5..56db096caa77 100644
--- a/test/test_youtube_signature.py
+++ b/test/test_youtube_signature.py
@@ -68,6 +68,11 @@
         '2aq0aqSyOoJXtK73m-uME_jv7-pT15gOFC02RFkGMqWpzEICs69VdbwQ0LDp1v7j8xx92efCJlYFYb1sUkkBSPOlPmXgIARw8JQ0qOAOAA',
         'AOq0QJ8wRAIgXmPlOPSBkkUs1bYFYlJCfe29xx8j7v1pDL2QwbdV96sCIEzpWqMGkFR20CFOg51Tp-7vj_EMu-m37KtXJoOySqa0',
     ),
+    (
+        'https://www.youtube.com/s/player/3bb1f723/player_ias.vflset/en_US/base.js',
+        '2aq0aqSyOoJXtK73m-uME_jv7-pT15gOFC02RFkGMqWpzEICs69VdbwQ0LDp1v7j8xx92efCJlYFYb1sUkkBSPOlPmXgIARw8JQ0qOAOAA',
+        'MyOSJXtKI3m-uME_jv7-pT12gOFC02RFkGoqWpzE0Cs69VdbwQ0LDp1v7j8xx92efCJlYFYb1sUkkBSPOlPmXgIARw8JQ0qOAOAA',
+    ),
 ]
 
 _NSIG_TESTS = [