Skip to content

Instantly share code, notes, and snippets.

@stefan-lz
Created June 13, 2012 14:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save stefan-lz/2924457 to your computer and use it in GitHub Desktop.
Save stefan-lz/2924457 to your computer and use it in GitHub Desktop.
youtube vids to mp3 files (ruby)
#!/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