-
-
Save mgaspari/bccbf650bf03faa6d5ba3460fa1d8165 to your computer and use it in GitHub Desktop.
youtube vids to mp3 files (ruby)
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
#!/usr/bin/ruby | |
#usage: youtube-to-mp3 <youtube-url> | |
#example: youtube-to-mp3 http://www.youtube.com/playlist?list=PL398CE05652474A1E | |
#desc: downloads a single youtube vid or a playlist, then converts to mp3. | |
# Requires youtube-dl and ffmpeg | |
url = ARGV[0] | |
system("youtube-dl -citA #{url}") | |
Dir.foreach(".") do |file| | |
filename = file[/(^\d{5}.*)[\-].*/,1] | |
if filename != nil | |
mp3_file = filename + ".mp3" | |
system("ffmpeg -i \"#{file}\" -vn -acodec libmp3lame -ar 44100 -ac 2 -ab 128000 \"#{mp3_file}\"") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment