Reputation: 21
I'm trying to download a youtube video using python. However, i'm getting thrown an error even though my code is right according to many up-to-date videos.
I am using Python 3.9.9
and Pytube 15.0.0
Here is my code:
from pytube import YouTube
video = YouTube('https://www.youtube.com/watch?v=AWXvSBHB210')
video.streams.get_highest_resolution().download()`
Full error:
Traceback (most recent call last):
File "C:\Users\Tobias\AppData\Roaming\Python\Python39\site-packages\pytube\__main__.py", line 181, in fmt_streams
extract.apply_signature(stream_manifest, self.vid_info, self.js)
File "C:\Users\Tobias\AppData\Roaming\Python\Python39\site-packages\pytube\extract.py", line 409, in apply_signature
cipher = Cipher(js=js)
File "C:\Users\Tobias\AppData\Roaming\Python\Python39\site-packages\pytube\cipher.py", line 43, in __init__
self.throttling_plan = get_throttling_plan(js)
File "C:\Users\Tobias\AppData\Roaming\Python\Python39\site-packages\pytube\cipher.py", line 405, in get_throttling_plan
raw_code = get_throttling_function_code(js)
File "C:\Users\Tobias\AppData\Roaming\Python\Python39\site-packages\pytube\cipher.py", line 311, in get_throttling_function_code
name = re.escape(get_throttling_function_name(js))
File "C:\Users\Tobias\AppData\Roaming\Python\Python39\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
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:\Users\Tobias\Desktop\Exal\test01.py", line 4, in <module>
video.streams.get_highest_resolution().download()
File "C:\Users\Tobias\AppData\Roaming\Python\Python39\site-packages\pytube\__main__.py", line 296, in streams
return StreamQuery(self.fmt_streams)
File "C:\Users\Tobias\AppData\Roaming\Python\Python39\site-packages\pytube\__main__.py", line 188, in fmt_streams
extract.apply_signature(stream_manifest, self.vid_info, self.js)
File "C:\Users\Tobias\AppData\Roaming\Python\Python39\site-packages\pytube\extract.py", line 409, in apply_signature
cipher = Cipher(js=js)
File "C:\Users\Tobias\AppData\Roaming\Python\Python39\site-packages\pytube\cipher.py", line 43, in __init__
self.throttling_plan = get_throttling_plan(js)
File "C:\Users\Tobias\AppData\Roaming\Python\Python39\site-packages\pytube\cipher.py", line 405, in get_throttling_plan
raw_code = get_throttling_function_code(js)
File "C:\Users\Tobias\AppData\Roaming\Python\Python39\site-packages\pytube\cipher.py", line 311, in get_throttling_function_code
name = re.escape(get_throttling_function_name(js))
File "C:\Users\Tobias\AppData\Roaming\Python\Python39\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
This is the error I get specifically: get_throttling_function_name: could not find match for multiple
Upvotes: 2
Views: 10692
Reputation: 14537
I just got the same error today. The solutions is here: https://github.com/pytube/pytube/issues/1954
You have to find and open the file ../site-packages/pytube/cipher.py
and add one more pattern into the function_patterns
list:
r'\([a-z]\s*=\s*([a-zA-Z0-9$]+)(\[\d+\])\([a-z]\)',
So my final list (at the line 264) look like this:
function_patterns = [
# https://github.com/ytdl-org/youtube-dl/issues/29326#issuecomment-865985377
# https://github.com/yt-dlp/yt-dlp/commit/48416bc4a8f1d5ff07d5977659cb8ece7640dcd8
# var Bpa = [iha];
# ...
# a.C && (b = a.get("n")) && (b = Bpa[0](b), a.set("n", b),
# Bpa.length || iha("")) }};
# In the above case, `iha` is the relevant function name
r'a\.[a-zA-Z]\s*&&\s*\([a-z]\s*=\s*a\.get\("n"\)\)\s*&&\s*'
r'\([a-z]\s*=\s*([a-zA-Z0-9$]+)(\[\d+\])?\([a-z]\)',
r'\([a-z]\s*=\s*([a-zA-Z0-9$]+)(\[\d+\])\([a-z]\)',
]
Python 3.11, pytube 15.0.0, macOS Monterey 12.2
Upvotes: 2
Reputation: 336
Actually it's a known bug and there is an issue opened for it , check at https://github.com/pytube/pytube/issues/1699
And also from the issue discussion we know that there is a pending PR with resolve , you can check ( and manually apply ) at https://github.com/pytube/pytube/pull/1691/files
Upvotes: 3