pythonpytube

pytube.exceptions.RegexMatchError: __init__: could not find match for ^\w+\W


So my issue is I run this simple code to attempt to make a pytube stream object...

from pytube import YouTube

yt = YouTube('https://www.youtube.com/watch?v=aQNrG7ag2G4')
stream = yt.streams.filter(file_extension='mp4')

And end up with the error in the title.

Full error:

Traceback (most recent call last):
  File ".\test.py", line 4, in <module>
    stream = yt.streams.filter(file_extension='mp4')
  File "C:\Users\logan\AppData\Local\Programs\Python\Python38\lib\site-packages\pytube\__main__.py", line 292, in streams       
    return StreamQuery(self.fmt_streams)
  File "C:\Users\logan\AppData\Local\Programs\Python\Python38\lib\site-packages\pytube\__main__.py", line 184, in fmt_streams   
    extract.apply_signature(stream_manifest, self.vid_info, self.js)
  File "C:\Users\logan\AppData\Local\Programs\Python\Python38\lib\site-packages\pytube\extract.py", line 409, in apply_signature
    cipher = Cipher(js=js)
  File "C:\Users\logan\AppData\Local\Programs\Python\Python38\lib\site-packages\pytube\cipher.py", line 33, in __init__
    raise RegexMatchError(
pytube.exceptions.RegexMatchError: __init__: could not find match for ^\w+\W

Extra data:

python version: 3.8.10 pytube version: 11.0.2


Solution

  • As juanchosaravia suggested on https://github.com/pytube/pytube/issues/1199, in order to solve the problem, you should go in the cipher.py file and replace the line 30, which is:

    var_regex = re.compile(r"^\w+\W")
    

    With that line:

    var_regex = re.compile(r"^\$*\w+\W")
    

    After that, it worked again.