Skip to content

Instantly share code, notes, and snippets.

@amankharwal
Created December 8, 2020 05:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amankharwal/da88638e6f9c213b2d1a7a842d55f6c2 to your computer and use it in GitHub Desktop.
Save amankharwal/da88638e6f9c213b2d1a7a842d55f6c2 to your computer and use it in GitHub Desktop.
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