Skip to content

Instantly share code, notes, and snippets.

@reuniware
Created November 15, 2022 10:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reuniware/f2d789db8e95e134f7610c81714ac63c to your computer and use it in GitHub Desktop.
Save reuniware/f2d789db8e95e134f7610c81714ac63c to your computer and use it in GitHub Desktop.
Download Youtube Video as MP3
from pytube import YouTube
import os
yt = YouTube('https://www.youtube.com/watch?v=PEnwXYJcSZc')
#yt.streams.get_audio_only().download()
video = yt.streams.filter(only_audio=True).first()
destination = '.'
out_file = video.download(output_path=destination)
base, ext = os.path.splitext(out_file)
new_file = base + '.mp3'
os.rename(out_file, new_file)
# result of success
print(yt.title + " has been successfully downloaded.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment