Chris Nguyen
Chris Nguyen

Reputation: 160

Python Youtube Audio Downloader using Website

So I am writing a simple script to extract links from a Youtube video, and then download the audio from each of the links. Extracting the links I got down using urllib, however, youtube_dl is being more problematic.

with youtube_dl.YoutubeDL(ydl_opts) as ydl:
        ydl.download(["https://www.youtube.com/watch?v=YQHsXMglC9A"])

I have the correct "ydl_opts" and everything, but it keeps rasing:

DownloadError: ERROR: ffprobe or avprobe not found. Please install one.

Even after Googling this, and installing ffprobe, I keep getting this error... and the weird thing is I can import ffprobe at the beginning of the program but youtube_dl doesn't detect it(?).

So I am trying another idea: Use a third party website like "youtube-mp3.org", get a template link like:

"""http://www.youtube-mp3.org/get?video_id={1}&ts_create=1451072960&r=MjQuMjEuMTc5LjU2&h2=12c386ccffa12ee7b16dd25078df2558&s=156489""".format(video_link_id)

... then formatting it with Youtubes unique video ID, and download it with urllib.urlopen(), but that download link generates unique arguments that can't be used with other videos. So is there a way to download from a website like that, and/or supply argument like changing the download URL algorithm? Or something to that effect?

Overall objective:

  1. Get Youtube video ID
  2. Download and convert to mp3 or similar format
  3. Play audio within Python

Bonus:

  1. Do it as efficiently and quickly as possible (i.e Not downloading entire video, or extra conversion steps)

Upvotes: 0

Views: 733

Answers (1)

Igor Pejic
Igor Pejic

Reputation: 3698

I can recommend you a package called pytube.

I have used it and am very pleased with the results. It downloads the video, and after that you can use a library to extract only the audio.

Hope it helps.

Upvotes: 0

Related Questions