Skip to content

Instantly share code, notes, and snippets.

@Oshuma
Created August 17, 2014 05:27
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 Oshuma/4a672e327ae98da2c5e7 to your computer and use it in GitHub Desktop.
Save Oshuma/4a672e327ae98da2c5e7 to your computer and use it in GitHub Desktop.
Convert .wma to .mp3
#!/usr/bin/env ruby
class WmaToMp3
TEMP_WAV = 'audiodump.wav'
def self.convert!(path)
wma_files = Dir.glob(File.join(path, "**/*.wma"), File::FNM_CASEFOLD)
if wma_files.empty?
STDOUT.puts "No .wma files found at: #{path}"
exit
end
wma_files.each do |wma_file|
STDOUT.puts "-----------------------"
STDOUT.puts "Converting: #{wma_file}"
STDOUT.puts "-----------------------"
wma_ext = File.extname(wma_file)
mp3_file = File.join(File.dirname(wma_file), File.basename(wma_file, wma_ext) + '.mp3')
convert = [
%Q[mplayer -vo null -vc dummy -af resample=44100 -ao pcm -ao pcm:waveheader "#{wma_file}"],
%Q[lame -m s #{TEMP_WAV} -o "#{wma_file}".mp3],
%Q[rm -vf #{TEMP_WAV}],
].join(' && ')
STDOUT.puts %x[#{convert}]
end
STDOUT.print "\nRemove .wma files? (Y/N) "
if STDIN.gets.chomp == 'Y'
STDOUT.puts %x[rm -vf #{wma_files.map { |f| %Q["#{f}"] }.join(' ')}]
end
end
end
if __FILE__ == $0
if ARGV[0].nil?
STDERR.puts "Usage: #{$0} <path>"
exit(1)
end
WmaToMp3.convert!(ARGV[0])
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment