Skip to content

Instantly share code, notes, and snippets.

@miguelvb
Created October 18, 2022 07:08
Show Gist options
  • Save miguelvb/b132b365c60fe7d22ac532045650e3a1 to your computer and use it in GitHub Desktop.
Save miguelvb/b132b365c60fe7d22ac532045650e3a1 to your computer and use it in GitHub Desktop.
Youtube download python
# TAKEN FROM https://dev.to/stokry/download-youtube-video-to-mp3-with-python-26p
# run first pip3 install youtube_dl in your env...
import youtube_dl
def 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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment