-
-
Save jterk/762671 to your computer and use it in GitHub Desktop.
Modified to tolerate missing metadata.
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 | |
# http://gist.github.com/gists/124242 | |
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 | |
args = "" | |
if defined? TITLE | |
args += %Q[ --tt "#{TITLE}"] | |
end | |
if defined? ARTIST | |
args += %Q[ --ta "#{ARTIST}"] | |
end | |
if defined? ALBUM | |
args += %Q[ --tl "#{ALBUM}"] | |
end | |
if defined? TRACKNUMBER | |
args += %Q[ --tn "#{TRACKNUMBER}"] | |
end | |
if defined? GENRE | |
args += %Q[ --tg "#{GENRE}"] | |
end | |
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