pytube: [BUG] get_throttling_function_name could not find match for multiple
Describe the bug
Having issues resolving video URLs for a give youtube video. I get the following error
pytube.exceptions.RegexMatchError: get_throttling_function_name: could not find match for multiple
To Reproduce Please provide the following information:
- The video or playlist url that is causing the error.
https://www.youtube.com/watch?v=Y4-GSFKZmEg
The code where the problem is occurring.
from pytube import YouTube
url = "https://www.youtube.com/watch?v=Y4-GSFKZmEg"
yt = YouTube(url)
thevid = yt.streams.filter(progressive=True, file_extension='mp4').order_by('resolution').desc().first()
vid = thevid
print("VID", vid)
Expected behavior the output should print the video asset URL where the video can be downloaded from
Output
Traceback (most recent call last):
File "/Users/par/Dev/mememaker-web/mememaker/scripts/pytube_test.py", line 5, in <module>
thevid = yt.streams.filter(progressive=True, file_extension='mp4').order_by('resolution').desc().first()
File "/Users/par/.virtualenvs/mememaker/lib/python3.9/site-packages/pytube/__main__.py", line 296, in streams
return StreamQuery(self.fmt_streams)
File "/Users/par/.virtualenvs/mememaker/lib/python3.9/site-packages/pytube/__main__.py", line 188, in fmt_streams
extract.apply_signature(stream_manifest, self.vid_info, self.js)
File "/Users/par/.virtualenvs/mememaker/lib/python3.9/site-packages/pytube/extract.py", line 409, in apply_signature
cipher = Cipher(js=js)
File "/Users/par/.virtualenvs/mememaker/lib/python3.9/site-packages/pytube/cipher.py", line 43, in __init__
self.throttling_plan = get_throttling_plan(js)
File "/Users/par/.virtualenvs/mememaker/lib/python3.9/site-packages/pytube/cipher.py", line 405, in get_throttling_plan
raw_code = get_throttling_function_code(js)
File "/Users/par/.virtualenvs/mememaker/lib/python3.9/site-packages/pytube/cipher.py", line 311, in get_throttling_function_code
name = re.escape(get_throttling_function_name(js))
File "/Users/par/.virtualenvs/mememaker/lib/python3.9/site-packages/pytube/cipher.py", line 296, in get_throttling_function_name
raise RegexMatchError(
pytube.exceptions.RegexMatchError: get_throttling_function_name: could not find match for multiple
System information Please provide the following information:
- Python 3.9.9
- print(pytube.version) 12.0.0
- python -m pip install git+https://github.com/pytube/pytube
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 26
- Comments: 44 (3 by maintainers)
Commits related to this issue
- Fixed bugs (kinda) script is still broken, but that's because YT changed stuff on their end. Fix: https://github.com/pytube/pytube/issues/1281 — committed to Clockknight/album-downloader by Clockknight 2 years ago
- Fix regex to find throttle function name (#1222) * Fix regex to find throttle function name The javascript now stores the throttling function name in an array. Fix https://github.com/pytube/pytub... — committed to pytube/pytube by glubsy 2 years ago
- Updated pytube to build from repo due to https://github.com/pytube/pytube/issues/1281 — committed to hallowslab/pytube-TKGUI by hallowslab 2 years ago
Apparently the JavaScript code containing details of the throttling function name is now of the form:
And the regex in
cipher.py
cannot match the same as it searches for variable names of a fixed length (3 in this case).Changing the regex in
function_patterns
incipher.py
to:and changing line 288 of
cipher.py
to:to escape the ‘$’ symbol now present in the ‘nfunc’ value seems to resolve the errors.
@manish-kumar-iisc Neither of the PRs containing the fixes for this problem have been merged as of yet, so you’ll have to either make the changes manually or install one of the forks containing the fix:
you guys on github are the best! saving us, lazy devs, so much work haha
@mpena22
Line 288 was changed from
to
Why it’s taking so much time to fix this critical bug?
I just started experiencing the same issue, while it was working fine up until a few hours ago. I confirmed the issue by making a basic script on a completely different system and attempting to download a video that was previously successful. It appears this is something that has happened from time to time when something changes on the YouTube side and the regex has to be updated in cipher.py for the get_throttling_function_name.
https://github.com/pytube/pytube/issues/1107
when is pytube gonna release this patch?
getting the same issue using v12.0.0
@kinshuk-h Thank you! Changing these two pieces of code saved my evening.
Thank you @kinshuk-h 😃