Created
February 22, 2011 17:43
-
-
Save mkhl/839044 to your computer and use it in GitHub Desktop.
Convert media files to MP3 using ffmpeg and lame. With automatic tagging.
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/env ruby | |
require 'tempfile' | |
opts = Hash[*%w[--tt title | |
--ta artist | |
--tl album | |
--ty year | |
--tc comment | |
--tn track | |
--tg genre]] | |
ARGV.each do |file| | |
temp = Tempfile.new(File.basename($PROGRAM_NAME)) | |
dest = File.basename(file, File.extname(file)) + '.mp3' | |
info = {} | |
%x[ffprobe '#{file}' 2>&1].grep(/^ /) do |line| | |
key, val = line.split(/:/, 2) | |
info[key.strip.downcase] = val.strip | |
end | |
args = [] | |
opts.each do |opt, tag| | |
args << opt << info[tag] if info.has_key? tag | |
end | |
system('ffmpeg', '-i', file, '-f', 'wav', '-y', temp.path) | |
system('lame', '-v', temp.path, dest, *args) | |
temp.delete | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment