Created
January 23, 2017 06:40
-
-
Save arafeek/8f986067e06c25690357a5c00bc1a8cd to your computer and use it in GitHub Desktop.
Quick and dirty script for downloading and converting youtube videos to mp3. Requires pytube.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from pytube import YouTube | |
| from sys import argv | |
| from os import system | |
| DOWLOAD_LOCATION = 'videos/' | |
| MP3_LOCATION = 'mp3/' | |
| src = argv[1] | |
| if not(src): | |
| print "Error: Need to supply video source." | |
| yt = YouTube(src) | |
| target = yt.filter('mp4')[-1] | |
| print 'Now downloading: ' + target.filename | |
| target.download(DOWLOAD_LOCATION) | |
| print 'Download complete.\n' | |
| # start converting | |
| originMP4 = DOWLOAD_LOCATION + target.filename + '.mp4' | |
| newMP3Name = MP3_LOCATION + target.filename + '.mp3' | |
| print 'Now Converting to: ' + newMP3Name | |
| command = 'ffmpeg -i ' + '"' + originMP4 + '"' + ' -ab 128k ' + '"' + newMP3Name + '"' | |
| system(command) | |
| print 'Done Converting.\n' | |
| print 'Removing video.' | |
| system('rm ' + '"' + originMP4 + '"') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment