pytube / pytube

A lightweight, dependency-free Python library (and command-line utility) for downloading YouTube Videos.
https://pytube.io
The Unlicense
12.22k stars 2.52k forks source link

downloading video bug #1754

Open Luxkaiv opened 1 year ago

Luxkaiv commented 1 year ago

yesterday, pytube was working just fine for me but today all of a sudden when i run my yt to mp3 converter it stops recognizing the link and gives me the pytube.exceptions.RegexMatchError: init: could not find match for ^\w+\W. ive done as much debugging as i can, i printing out the link before this statement runs so i know that the link is correctly passed through. even asked chat gpt and it blamed pytube and not my code.

To Reproduce Please provide the following information: Ive tried several videos and none work so ill just give one https://www.youtube.com/watch?v=l_FWkOR4QvU the code where it isnt worknig is here: def download_vid(self, link): self.label2 = customtkinter.CTkLabel(self.mainframe,text="downloading...") self.label2.grid(row=3,column=0) name = self.Entry.get()

gui stuff ^^

    print(link)

printing to test if the link was correctly passed through ^^

    yt = YouTube(link)
    filename = yt.title + ".mp4"
    newname = name + ".mp4"
    stream = yt.streams.filter(only_audio=True,file_extension="mp4").first()
    Itag = stream.itag
    stream = yt.streams.get_by_itag(Itag)
    stream.download()

downlaods song^^

    os.rename(filename, newname)
    song = newname
    sound = AudioSegment.from_file(song)
    length = sound.duration_seconds
    sound = sound - 15
    sound.export(name + ".mp3", format="mp3", bitrate="320k")
    os.remove(newname)
    shutil.move(f"{name}.mp3", f"songs")

converts the mp4 to an mp3

    self.update_song_list()

updates the gui^^

    self.playsong("songs\\" + f"{name}.mp3",length)

runs the next function

Expected behavior What is supposed to happen is you input the link and the name you want to give the file and it will download it, rename it and make it an mp3, and then put it in a file then calls the next function which request if you would like to play the song

Output once again the error code: pytube.exceptions.RegexMatchError: init: could not find match for ^\w+\W

System information Please provide the following information:

github-actions[bot] commented 1 year ago

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

Ayman-ing commented 1 year ago

same error

amckee commented 1 year ago

Apply https://github.com/pytube/pytube/issues/1707#issuecomment-1672149709 if you haven't already, then change cipher.py line 30 to:

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

YMMV

Luxkaiv commented 1 year ago

seemed to work

Leonardo-DevStrom commented 1 year ago

@amckee Yeah, this fixes the bug. Congratulations to you.

Leonardo-DevStrom commented 1 year ago

@amckee I was testing line 30, but didn't find out that it was just "$", so, you've noticed it well and really fast.

paichiwo commented 1 year ago

works perfectly, thanks

AkshayShineKrishna commented 1 year ago

This worked for me , and the download speeds are better now.

r-silver1 commented 1 year ago

awesome thank you

actuallyrizzn commented 1 year ago

This did not solve the issue for me. It just started manifesting for me about noon central today. I've done the usual regex fixes mentioned here and on other related threads, and it's still having this error.

Luxkaiv commented 1 year ago

This did not solve the issue for me. It just started manifesting for me about noon central today. I've done the usual regex fixes mentioned here and on other related threads, and it's still having this error.

maybe try uninstalling pytube and reinstalling and then redoing this step?

actuallyrizzn commented 1 year ago

This did not solve the issue for me. It just started manifesting for me about noon central today. I've done the usual regex fixes mentioned here and on other related threads, and it's still having this error.

maybe try uninstalling pytube and reinstalling and then redoing this step?

that did the trick. shoulda turned it off and back on again.

boardkeystown commented 1 year ago

Apply #1707 (comment) if you haven't already, then change cipher.py line 30 to:

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

YMMV

GOAT thank you bro!

41v4 commented 1 year ago

I am experiencing the same issue. However, I recall encountering this problem last year as well. Why is it happening again? Does anyone have any ideas?

amckee commented 1 year ago

I am experiencing the same issue. However, I recall encountering this problem last year as well. Why is it happening again? Does anyone have any ideas?

When Youtube makes changes, as it does frequently, the parser needs updated accordingly.

anushnandyala commented 1 year ago

I am still having the same issue even after changing line 30. This is the error I am getting: Error downloading video: __init__: could not find match for ^\\w+\\W

oncename commented 1 year ago

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

Leonardo-DevStrom commented 1 year ago

@oncename Really?

amckee commented 1 year ago

@anushnandyala the regex is incorrect. ( "^\\" vs "^\$" )

@oncename the regex is incorrect. ( "^$*" vs "^\$" )

After making the change, of course, you will need to restart the script to reload the new code.

oncename commented 1 year ago

@anushnandyala the regex is incorrect. ( "^\\" vs "^\$" )

@oncename the regex is incorrect. ( "^$*" vs "^\$" )

After making the change, of course, you will need to restart the script to reload the new code.

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

amckee commented 1 year ago

@oncename That looks correct. The dollar sign needs to be escaped.

ImagineA1m commented 1 year ago

Apply #1707 (comment) if you haven't already, then change cipher.py line 30 to:

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

YMMV

You are a legend bro it works now tysm

strtech111 commented 1 year ago

i changed it on my local machine. var_regex = re.compile(r"^\$\w+\W") But what about on my server it not working

Leonardo-DevStrom commented 1 year ago

@saqlainniazi1 Screenshot_20230813-081820~2

CosmKiwi commented 1 year ago

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

The $'s not always there. So add ? after it to check for 0 or 1 occurrence:

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