Search code examples
pythonpytube

pytube.exceptions.RegexMatchError in python


I can try to find youtube videos in different formats. using pytube streams filter but it gives an error pytube.exceptions.RegexMatchError.

from pytube import YouTube

url = input('Enter url :')

link = YouTube(url)

print(link.title)

obj = link.streams.filter(progressive="True")
print(obj)

This error given :

Traceback (most recent call last):
  File "/home/jay/PycharmProjects/videoinfo/venv/lib/python3.7/site-packages/pytube/__main__.py", line 170, in fmt_streams
    extract.apply_signature(stream_manifest, self.vid_info, self.js)
  File "/home/jay/PycharmProjects/videoinfo/venv/lib/python3.7/site-packages/pytube/extract.py", line 409, in apply_signature
    cipher = Cipher(js=js)
  File "/home/jay/PycharmProjects/videoinfo/venv/lib/python3.7/site-packages/pytube/cipher.py", line 43, in __init__
    self.throttling_plan = get_throttling_plan(js)
  File "/home/jay/PycharmProjects/videoinfo/venv/lib/python3.7/site-packages/pytube/cipher.py", line 387, in get_throttling_plan
    raw_code = get_throttling_function_code(js)
  File "/home/jay/PycharmProjects/videoinfo/venv/lib/python3.7/site-packages/pytube/cipher.py", line 293, in get_throttling_function_code
    name = re.escape(get_throttling_function_name(js))
  File "/home/jay/PycharmProjects/videoinfo/venv/lib/python3.7/site-packages/pytube/cipher.py", line 279, in get_throttling_function_name
    caller="get_throttling_function_name", pattern="multiple"
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 "main.py", line 44, in <module>
    yt = myVideo.streams.filter(type='mp4')
  File "/home/jay/PycharmProjects/videoinfo/venv/lib/python3.7/site-packages/pytube/__main__.py", line 285, in streams
    return StreamQuery(self.fmt_streams)
  File "/home/jay/PycharmProjects/videoinfo/venv/lib/python3.7/site-packages/pytube/__main__.py", line 177, in fmt_streams
    extract.apply_signature(stream_manifest, self.vid_info, self.js)
  File "/home/jay/PycharmProjects/videoinfo/venv/lib/python3.7/site-packages/pytube/extract.py", line 409, in apply_signature
    cipher = Cipher(js=js)
  File "/home/jay/PycharmProjects/videoinfo/venv/lib/python3.7/site-packages/pytube/cipher.py", line 43, in __init__
    self.throttling_plan = get_throttling_plan(js)
  File "/home/jay/PycharmProjects/videoinfo/venv/lib/python3.7/site-packages/pytube/cipher.py", line 387, in get_throttling_plan
    raw_code = get_throttling_function_code(js)
  File "/home/jay/PycharmProjects/videoinfo/venv/lib/python3.7/site-packages/pytube/cipher.py", line 293, in get_throttling_function_code
    name = re.escape(get_throttling_function_name(js))
  File "/home/jay/PycharmProjects/videoinfo/venv/lib/python3.7/site-packages/pytube/cipher.py", line 279, in get_throttling_function_name
    caller="get_throttling_function_name", pattern="multiple"
pytube.exceptions.RegexMatchError: get_throttling_function_name: could not find match for multiple

I can also reinstall pytube using "pip install git+https://github.com/nficano/pytube.git" and also "pip install pytube". but the error is still now.


Solution

  • you can install :

    pip install pytube==11.0.1 or pip install --upgrade pytube
    

    or you can change in pytube/cipher.py :

    edit line:r'a\.[A-Z]&&\(b=a\.[sg]et\("n"\)\)&&\(b=([^(]+)\(b\),a\.[sg]et\("n",b\)\)}};' 
    

    to

    r'a\.C&&\(b=a\.get\("n"\)\)&&\(b=([^(]+)\(b\),a\.set\("n",b\)\)}};',
    

    in the def get_throttling_function_name(js: str) -> str: function.