-2

this is the code:

import pytube
from pytube import YouTube
from pydub import AudioSegment

import os

def download_track(URL,query):

    try:
        yt=YouTube(URL)

        t=yt.streams.filter(only_audio=True).first()

        t.download(filename=f'{query}.mp3')

    except pytube.exceptions.LiveStreamError:

        print('Not available')

        return

    except pytube.exceptions.RegexMatchError:

        print("Invalid YouTube URL.")
        return

    path=os.path.join(os.getcwd(),f'{query}.mp3')
    audio_segment=AudioSegment.from_file(path)

This code was earlier able to download videos if it was given correct url (query is just the name of the audio file we want to download) but now this code is giving exception of RegexMatchError and printing Invalid Youtube URl eventhough the url is correct .Kindly help

John Gordon
  • 29,573
  • 7
  • 33
  • 58
  • 1
    Provide an example of problematic `URL` and `query`. – Benjamin Loison Aug 13 '23 at 18:11
  • Downvoted because: [Missing exception details](https://idownvotedbecau.se/noexceptiondetails/) and [No research](https://idownvotedbecau.se/noresearch/). I'd say [this question on SO](https://stackoverflow.com/questions/76892471/suddenly-the-pytube-library-stopped-working-with-nothing-and-began-to-issue-an-e#comment135553285_76892471) is very likely an exact duplicate of your problem. – Clasherkasten Aug 13 '23 at 18:19
  • The `download_track()` function is _defined_ but it is never _called_. This cannot be your real full code... – John Gordon Aug 13 '23 at 18:22
  • YouTube changes their metadata API quite often, which breaks modules like this. Any time you have a problem like this, you have to go back to the `pytube` site and see if they have an update. The `pip install` is not good enough. – Tim Roberts Aug 13 '23 at 18:33
  • so when can we expect an update on pytube I have a deadline to submit the project – Rudra Pathak Aug 13 '23 at 18:45
  • @RudraPathak a PR is already submitted, it just has to get merged.There also already exists a [fork](https://github.com/oncename/pytube) with the fix. – Clasherkasten Aug 13 '23 at 20:40

0 Answers0