Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] pytube.exceptions.RegexMatchError: get_throttling_function_name: could not find match for multiple #1299

Open
Apps8 opened this issue Apr 21, 2022 · 16 comments
Labels

Comments

@Apps8
Copy link

Apps8 commented Apr 21, 2022

Before creating an issue

Please confirm that you are on the latest version of pytube by installing from the source.
You can do this by running python -m pip install git+https://github.com/pytube/pytube.
Sometimes, the pypi library repository is not up to date, and your issue may have been fixed already!

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
Please provide the following information:

  • The video or playlist url that is causing the error.
  • The code where the problem is occurring.

Expected behavior
A clear and concise description of what you expected to happen.

Output
If pytube raises an exception, please provide the full traceback for the exception.

System information
Please provide the following information:

  • Python version (run python --version)
  • Pytube version (run print(pytube.__version__) in python)
  • Command used to install pytube
@Apps8 Apps8 added the bug label Apr 21, 2022
@github-actions
Copy link

Thank you for contributing to PyTube. Please remember to reference Contributing.md

@Apps8 Apps8 changed the title [BUG] [BUG] pytube.exceptions.RegexMatchError: get_throttling_function_name: could not find match for multiple Apr 21, 2022
@Apps8
Copy link
Author

Apps8 commented Apr 21, 2022

Hello,
I have problem with streams of YouTube video. I have tried everything I found on the net! I will be grateful for help!
pytube was working fine 2 or 3 weeks ago???

To Reproduce
The video url : https://www.youtube.com/watch?v=xfZCFME4Gsw
My Code
def download_video(self,video_url, video_file_name):
youtube=pytube.YouTube(video_url)

    video=youtube.streams.get_highest_resolution
    video.download(video_file_name)

My Error
File "C:\Users\jjpj1390\AppData\Local\Programs\Python\Python310\lib\site-packages\pytube_main_.py", line 181, in fmt_streams
extract.apply_signature(stream_manifest, self.vid_info, self.js)
File "C:\Users\jjpj1390\AppData\Local\Programs\Python\Python310\lib\site-packages\pytube\extract.py", line 409, in apply_signature
cipher = Cipher(js=js)
File "C:\Users\jjpj1390\AppData\Local\Programs\Python\Python310\lib\site-packages\pytube\cipher.py", line 43, in init
self.throttling_plan = get_throttling_plan(js)
File "C:\Users\jjpj1390\AppData\Local\Programs\Python\Python310\lib\site-packages\pytube\cipher.py", line 405, in get_throttling_plan
raw_code = get_throttling_function_code(js)
File "C:\Users\jjpj1390\AppData\Local\Programs\Python\Python310\lib\site-packages\pytube\cipher.py", line 311, in get_throttling_function_code
name = re.escape(get_throttling_function_name(js))
File "C:\Users\jjpj1390\AppData\Local\Programs\Python\Python310\lib\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
Python 3.10.4
pytube : 12.0.0
pip install git+https://github.com/pytube/pytube

@devkarim
Copy link

If you want a quick workaround, this fixed the issue.

@thatsyogeshjjr
Copy link

thatsyogeshjjr commented Apr 23, 2022

try this:
open the file C:\Users\jjpj1390\AppData\Local\Programs\Python\Python310\lib\site-packages\pytube\cipher.py
change line 272 ~ 273

r'a.[a-zA-Z]\s*&&\s*([a-z]\s*=\sa.get("n"))\s&&\s*'
r'([a-z]\s*=\s*([a-zA-Z0-9$]{2,3})([\d+])?([a-z])'

and change line 288
nfunc=re.escape(function_match.group(1))),

@o-i-z-y-s
Copy link

If you want a quick workaround, this fixed the issue.

Can confirm this fixed the issue on my end as well.

@krishyadav007
Copy link

I am facing the same error.

Can't try the fix as I am on colab

@thatsyogeshjjr @o-i-z-y-s

@rajeshp2408
Copy link

Hi there ,

Im still having issue with Pytube download:
Status As on 30/04/2022

System information:

print(pytube.version)
12.0.0

C:\Users\rajeshp>python
Python 3.9.7 (default, Sep 16 2021, 16:59:28) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32

Pytube version download:
python -m pip install git+https://github.com/pytube/pytube

Code:

from pytube import YouTube
video = YouTube('https://www.youtube.com/watch?v=G1eGGvrprS0')
video.streams.get_by_itag(251).download()

Response:
Traceback (most recent call last):
File "C:\Users\rajeshp\anaconda3\lib\site-packages\pytube_main_.py", line 181, in fmt_streams
extract.apply_signature(stream_manifest, self.vid_info, self.js)
File "C:\Users\rajeshp\anaconda3\lib\site-packages\pytube\extract.py", line 409, in apply_signature
cipher = Cipher(js=js)
File "C:\Users\rajeshp\anaconda3\lib\site-packages\pytube\cipher.py", line 43, in init
self.throttling_plan = get_throttling_plan(js)
File "C:\Users\rajeshp\anaconda3\lib\site-packages\pytube\cipher.py", line 405, in get_throttling_plan
raw_code = get_throttling_function_code(js)
File "C:\Users\rajeshp\anaconda3\lib\site-packages\pytube\cipher.py", line 311, in get_throttling_function_code
name = re.escape(get_throttling_function_name(js))
File "C:\Users\rajeshp\anaconda3\lib\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 "", line 1, in
File "C:\Users\rajeshp\anaconda3\lib\site-packages\pytube_main_.py", line 296, in streams
return StreamQuery(self.fmt_streams)
File "C:\Users\rajeshp\anaconda3\lib\site-packages\pytube_main_.py", line 188, in fmt_streams
extract.apply_signature(stream_manifest, self.vid_info, self.js)
File "C:\Users\rajeshp\anaconda3\lib\site-packages\pytube\extract.py", line 409, in apply_signature
cipher = Cipher(js=js)
File "C:\Users\rajeshp\anaconda3\lib\site-packages\pytube\cipher.py", line 43, in init
self.throttling_plan = get_throttling_plan(js)
File "C:\Users\rajeshp\anaconda3\lib\site-packages\pytube\cipher.py", line 405, in get_throttling_plan
raw_code = get_throttling_function_code(js)
File "C:\Users\rajeshp\anaconda3\lib\site-packages\pytube\cipher.py", line 311, in get_throttling_function_code
name = re.escape(get_throttling_function_name(js))
File "C:\Users\rajeshp\anaconda3\lib\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

cipher.py

verified following regex:
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 = Bpa0, 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*=\sa.get("n"))\s&&\s*'
r'([a-z]\s*=\s*([a-zA-Z0-9$]{3})([\d+])?([a-z])',
]

Can i know what has caused the following error? Is the bug fixed. Can i know the workaround or fix?

@rajeshp2408
Copy link

Hi there ,

Im still having issue with Pytube download: Status As on 30/04/2022

System information:

print(pytube.version)
12.0.0

C:\Users\rajeshp>python Python 3.9.7 (default, Sep 16 2021, 16:59:28) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32

Pytube version download: python -m pip install git+https://github.com/pytube/pytube

Code:

from pytube import YouTube
video = YouTube('https://www.youtube.com/watch?v=G1eGGvrprS0')
video.streams.get_by_itag(251).download()

Response: Traceback (most recent call last): File "C:\Users\rajeshp\anaconda3\lib\site-packages\pytube__main__.py", line 181, in fmt_streams extract.apply_signature(stream_manifest, self.vid_info, self.js) File "C:\Users\rajeshp\anaconda3\lib\site-packages\pytube\extract.py", line 409, in apply_signature cipher = Cipher(js=js) File "C:\Users\rajeshp\anaconda3\lib\site-packages\pytube\cipher.py", line 43, in init self.throttling_plan = get_throttling_plan(js) File "C:\Users\rajeshp\anaconda3\lib\site-packages\pytube\cipher.py", line 405, in get_throttling_plan raw_code = get_throttling_function_code(js) File "C:\Users\rajeshp\anaconda3\lib\site-packages\pytube\cipher.py", line 311, in get_throttling_function_code name = re.escape(get_throttling_function_name(js)) File "C:\Users\rajeshp\anaconda3\lib\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 "", line 1, in File "C:\Users\rajeshp\anaconda3\lib\site-packages\pytube__main__.py", line 296, in streams return StreamQuery(self.fmt_streams) File "C:\Users\rajeshp\anaconda3\lib\site-packages\pytube__main__.py", line 188, in fmt_streams extract.apply_signature(stream_manifest, self.vid_info, self.js) File "C:\Users\rajeshp\anaconda3\lib\site-packages\pytube\extract.py", line 409, in apply_signature cipher = Cipher(js=js) File "C:\Users\rajeshp\anaconda3\lib\site-packages\pytube\cipher.py", line 43, in init self.throttling_plan = get_throttling_plan(js) File "C:\Users\rajeshp\anaconda3\lib\site-packages\pytube\cipher.py", line 405, in get_throttling_plan raw_code = get_throttling_function_code(js) File "C:\Users\rajeshp\anaconda3\lib\site-packages\pytube\cipher.py", line 311, in get_throttling_function_code name = re.escape(get_throttling_function_name(js)) File "C:\Users\rajeshp\anaconda3\lib\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

cipher.py

verified following regex: 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 = Bpa0, 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$]{3})([\d+])?([a-z])', ]

Can i know what has caused the following error? Is the bug fixed. Can i know the workaround or fix?

Resolved based on article Ref.:
https://www.codegrepper.com/code-examples/python/pytube.exceptions.RegexMatchError%3A+get_throttling_function_name%3A+could+not+find+match+for+multiple

line: 272 ~ 273
r'a.[a-zA-Z]\s*&&\s*([a-z]\s*=\sa.get("n"))\s&&\s*'
r'([a-z]\s*=\s*([a-zA-Z0-9$]{2,3})([\d+])?([a-z])'

Difference found in current pytube 12 version:
image

@rcsmit
Copy link

rcsmit commented Apr 30, 2022

try this: open the file C:\Users\jjpj1390\AppData\Local\Programs\Python\Python310\lib\site-packages\pytube\cipher.py change line 272 ~ 273

r'a.[a-zA-Z]\s*&&\s*([a-z]\s*=\sa.get("n"))\s&&\s*'
r'([a-z]\s*=\s*([a-zA-Z0-9$]{2,3})([\d+])?([a-z])'

and change line 288 nfunc=re.escape(function_match.group(1))),

To make it work, 272-273 have to be

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$]{2,3})(\[\d+\])?\([a-z]\)'          

(edit: found it somewhere else)

@numbernumberone
Copy link

try this: open the file C:\Users\jjpj1390\AppData\Local\Programs\Python\Python310\lib\site-packages\pytube\cipher.py change line 272 ~ 273

r'a.[a-zA-Z]\s*&&\s*([a-z]\s*=\sa.get("n"))\s&&\s*'
r'([a-z]\s*=\s*([a-zA-Z0-9$]{2,3})([\d+])?([a-z])'

and change line 288 nfunc=re.escape(function_match.group(1))),

To make it work, 272-273 have to be

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$]{2,3})(\[\d+\])?\([a-z]\)'          

very nice !

@GuyARoss
Copy link

GuyARoss commented Apr 30, 2022

Just found this issue today, is there a PR with the fix?

@Praanshu98
Copy link

Replace the line 272-273 in cipher.py.

r'a.[a-zA-Z]\s*&&\s*([a-z]\s*=\sa.get("n"))\s&&\s*'
r'([a-z]\s*=\s*([a-zA-Z0-9$]{2,3})([\d+])?([a-z])'

@TinKurbatoff
Copy link

In the parallel branch, I have already answered.
Replace lines 272-273 in cipher.py in another way:

        r'a\.[a-zA-Z]\s*&&\s*\([a-z]\s*=\s*a\.get\("n"\)\)\s*&&\s*.*\|\|\s*(.*)\(',
        r'\([a-z]\s*=\s*([a-zA-Z0-9$]{3})(\[\d+\])?\([a-z]\)',    

@ghost
Copy link

ghost commented May 4, 2022

In the parallel branch, I have already answered. Replace lines 272-273 in cipher.py in another way:

        r'a\.[a-zA-Z]\s*&&\s*\([a-z]\s*=\s*a\.get\("n"\)\)\s*&&\s*.*\|\|\s*(.*)\(',
        r'\([a-z]\s*=\s*([a-zA-Z0-9$]{3})(\[\d+\])?\([a-z]\)',    

Thanks ☺️🥺🎉

It worked fine.
Screenshot_20220505-002332

@TinKurbatoff
Copy link

TinKurbatoff commented May 6, 2022

Fixed in the more correct way:
by Yu Jhin
lines 272-273 (cipher.py):

        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]\)',

@TXAVL
Copy link

TXAVL commented Jun 24, 2023

#1299 (comment)
It works great for me🥰🥰

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.