Skip to content

Instantly share code, notes, and snippets.

@msoap
Forked from mxcl/flac2mp3.md
Created March 25, 2012 12:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msoap/2193212 to your computer and use it in GitHub Desktop.
Save msoap/2193212 to your computer and use it in GitHub Desktop.
Simplest functional FLAC to MP3 converter script you can make
#!/usr/bin/env ruby
# http://gist.github.com/gists/124242
# Deps: brew install flac lame
filename = ARGV[0]
abort "Usage: flac2mp3 FLACFILE" if filename.nil?
map = {"TITLE" => "--tt", "ARTIST" => "--ta", "ALBUM" => "--tl", "TRACKNUMBER" => "--tn", "GENRE" => "--tg", "DATE" => "--ty"}
args = ""
`metaflac --export-tags-to=- "#{filename}"`.each_line do |line|
key, value = line.strip.split('=', 2)
key.upcase!
args << %Q{#{map[key]} "#{value.gsub('"', '\"')}" } if map[key]
end
basename = File.basename(filename, File.extname(filename))
puts "Encoding #{basename}.mp3"
exec %Q[flac -sdc "#{filename}" | lame -V2 #{args} - "#{basename}.mp3"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment