Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
May 17, 2021 12:18 pm GMT

Download Youtube video to mp3 with Python

I often need to download videos from Youtube in mp3 format. There are many websites where you can convert Youtube videos to mp3, but I am giving you a simple Python script that does the same job.

I am using youtube_dl. Command-line program to download videos from YouTube.com and other video sites. It requires the Python interpreter, version 2.6, 2.7, or 3.2+, and it is not platform-specific. It should work on your Unix box, on Windows, or on macOS.

Let's jump to the code:

import youtube_dldef run():    video_url = input("please enter youtube video url:")    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))if __name__=='__main__':    run()

Just enter the URL of the song and the script will download that song in mp3 format, cool isn't it?

Thank you all.


Original Link: https://dev.to/stokry/download-youtube-video-to-mp3-with-python-26p

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To