Created
August 17, 2014 05:27
-
-
Save Oshuma/4a672e327ae98da2c5e7 to your computer and use it in GitHub Desktop.
Convert .wma to .mp3
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/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