Skip to content

Instantly share code, notes, and snippets.

@ekratskih
Created October 1, 2011 07:15
Show Gist options
  • Save ekratskih/1255720 to your computer and use it in GitHub Desktop.
Save ekratskih/1255720 to your computer and use it in GitHub Desktop.
Convert flac files in current directory to mp3
ALBUMS_DIR = '/home/edil/Downloads/Muse Japan CD'
def convert_files(dir)
puts '--' + dir + '--'
Dir.entries(dir).each do |track|
if track == '.' or track == '..'
next
end
full_path = File.join(dir, track)
if File.extname(full_path) == '.flac'
mp3_name =File.join(dir, File.basename(track, '.flac') + '.mp3')
puts %x[ flac -d -F -c "#{full_path}" | lame -ms -q1 -V0 -B320 --resample 44.1 - "#{mp3_name}"; ]
File.unlink(full_path)
end
if File.directory?(full_path)
convert_files(full_path)
end
end
end
Dir.entries(ALBUMS_DIR).each do |d|
if d == '..' or d == '.' or File.file?(d)
next
end
album_dir = File.join(ALBUMS_DIR, d)
convert_files(album_dir)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment