I would like to automate downloading mp3 versions of youtube video from this site:
CodePudding user response:
A slower but easier fix using the youtube_dl library.
Don't forget to pip install youtube_dl
import youtube_dl
video_url = 'https://www.youtube.com/watch?v=BQogzYUoQWU'
video_info = youtube_dl.YoutubeDL().extract_info(
url=video_url, download=False
)
filename = f"{video_info['title']}.mp3"
options = {
'format': 'bestaudio/best',
'keepvideo': False,
'outtmpl': filename,
}
with youtube_dl.YoutubeDL(options) as ydl:
ydl.download([video_info['webpage_url']])
print("Download complete... {}".format(filename))