Skip to content

Instantly share code, notes, and snippets.

@jrk
Forked from mxcl/flac2mp3.md
Created November 10, 2009 01:21
Show Gist options
  • Save jrk/230533 to your computer and use it in GitHub Desktop.
Save jrk/230533 to your computer and use it in GitHub Desktop.
Simple flac2mp3 conversion script, supporting essential tags and batch processing with globs.
#!/usr/bin/ruby
# http://gist.github.com/230533
# forked from http://gist.github.com/124242
# TODO: add iteration over arguments
filename=ARGV[0]
abort "Usage: flac2mp3 FLACFILE" if filename.nil?
`metaflac --export-tags-to=- "#{filename}"`.each_line do |s|
v=s.strip.split '=', 2
v[0].upcase!
v[1].gsub! '"', '\"'
eval %Q[#{v[0]}="#{v[1]}"];
end
# TODO: this may explode if any of these values are not defined by the metaflac lines above
args=%Q[--tt "#{TITLE}" --ta "#{ARTIST}" --tl "#{ALBUM}" --tn "#{TRACKNUMBER}" --tg "#{GENRE}" --ty "#{DATE}" --add-id3v2]
basename=File.basename(filename, File.extname(filename))
puts "Encoding #{basename}.mp3"
exec %Q[flac -sdc "#{filename}" | lame --alt-preset standard #{args} - "#{basename}.mp3"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment