Home > Net >  How do i get my python code to click mp3 download button from this site
How do i get my python code to click mp3 download button from this site

Time:10-10

I would like to automate downloading mp3 versions of youtube video from this site: enter image description here

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))
  • Related