Skip to content

Instantly share code, notes, and snippets.

@amankharwal
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()
@weeblip
Copy link

weeblip commented May 17, 2021

I am facing an error. I followed everything precisely and when i enter the url in the 'Enter YouTube video URL' tab it shows 'The syntax of the command is incorrect.' as an error. any solutions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment