Skip to content

Instantly share code, notes, and snippets.

@amankharwal

amankharwal/video to audio.py Secret

Created Dec 8, 2020
Embed
What would you like to do?
from pytube import YouTube
import pytube
import os
def main():
video_url = input('Enter YouTube video URL: ')
if os.name == 'nt':
path = os.getcwd() + '\\'
else:
path = os.getcwd() + '/'
name = pytube.extract.video_id(video_url)
YouTube(video_url).streams.filter(only_audio=True).first().download(filename=name)
location = path + name + '.mp4'
renametomp3 = path + name + '.mp3'
if os.name == 'nt':
os.system('ren {0} {1}'. format(location, renametomp3))
else:
os.system('mv {0} {1}'. format(location, renametomp3))
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment