prateekralhan / Python-based-Youtube-downloader

A simple GUI for downloading youtube videos built using Python
MIT License
44 stars 18 forks source link

The program doesn't download videos, and throws an exception #2

Closed a2ys closed 2 years ago

a2ys commented 2 years ago

Whenever I try to download a video, say this one Morbius Trailer, it throws the following error:

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Users\Lenovo\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\Lenovo\AppData\Local\Programs\Python\Python310\lib\site-packages\pytube\extract.py", line 409, in apply_signature
    cipher = Cipher(js=js)
  File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python310\lib\site-packages\pytube\cipher.py", line 33, in __init__
    raise RegexMatchError(
pytube.exceptions.RegexMatchError: __init__: could not find match for ^\w+\W

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python310\lib\tkinter\__init__.py", line 1921, in __call__
    return self.func(*args)
  File "D:\Downloads\new\Python-based-Youtube-downloader\python_youtube_downloader.py", line 12, in entry_fields
    YouTube(e1.get()).streams.first().download(download_location)
  File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python310\lib\site-packages\pytube\__main__.py", line 296, in streams
    return StreamQuery(self.fmt_streams)
  File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python310\lib\site-packages\pytube\__main__.py", line 188, in fmt_streams
    extract.apply_signature(stream_manifest, self.vid_info, self.js)
  File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python310\lib\site-packages\pytube\extract.py", line 409, in apply_signature
    cipher = Cipher(js=js)
  File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python310\lib\site-packages\pytube\cipher.py", line 33, in __init__
    raise RegexMatchError(
pytube.exceptions.RegexMatchError: __init__: could not find match for ^\w+\W

I can't find any solution for it, hope you can help!

a2ys commented 2 years ago

Sorry to bother but I found a solution myself. It is a bug from the library itself. You need to follow the following steps:

  1. First go to C:\Users\\AppData\Local\Programs\Python\Python310\Lib\site-packages\pytube on Windows or pip find pytube and go to the location on Linux or Mac.
  2. Open the file cipher.py and edit Line 30 as:
    var_regex = re.compile(r"^\$*\w+\W")

Now there will be no issues!

Akhil928 commented 11 months ago

Defaulting to user installation because normal site-packages is not writeable Requirement already satisfied: pytube in c:\users\akhil\appdata\local\packages\pythonsoftwarefoundation.python.3.12_qbz5n2kfra8p0\localcache\local-packages\python312\site-packages `(15.0.0)```

IT WAS SHOWING LIKE THIS I HOPE U CAN HELP WITH THIS I'M NOT GETTING RUN THE CODE

prateekralhan commented 11 months ago

You seem to have Python 3.12 in your system and pytube ( underlying dependency for this app ) doesn't support Python 3.12. See this