Created
April 1, 2012 16:30
-
-
Save danhigham/2276810 to your computer and use it in GitHub Desktop.
Ruby script to convert .m4a files to mp3 (install lame and faad2 via homebrew first)
This file contains 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 | |
require 'rubygems' | |
require 'mp4info' | |
path = ARGV[0] | |
Dir.foreach(path) do |file| | |
file_path = File.join path, file | |
if File.file? file_path and File.extname(file_path) == ".m4a" | |
puts file_path | |
file_name = file_path.match(/([^\/]+)$/)[0] | |
mp3_path = "#{file_path}.mp3" | |
wav_path = "/tmp/#{file_name}.wav" | |
info = MP4Info.open file_path | |
info = info.instance_eval("@data_atoms") | |
album = info["ALB"] | |
apple_store_id = info["APID"] | |
artist = info["ART"] | |
comment = info["CMT"] | |
album_art = info["COVR"] | |
compilation = info["CPIL"] | |
copyright = info["CPRT"] | |
year = info["DAY"] | |
disk = info["DISK"] | |
genre = info["GNRE"] | |
grouping = info["GRP"] | |
title = info["NAM"] | |
rating = info["RTNG"] | |
tempo = info["TMPO"] | |
encoder = info["TOO"] | |
track_no = info["TRKN"] | |
author = info["WRT"] | |
system "/usr/local/Cellar/faad2/2.7/bin/faad -o '#{wav_path}' '#{file_path}'" | |
system "/usr/local/Cellar/lame/3.99.3/bin/lame -b 192 -h --tt '#{title}' --ta '#{artist}' --tl '#{album}' --ty '#{year}' --tc '#{comment}' --tn '#{track_no}' --tg '#{genre}' '#{wav_path}' '#{mp3_path}'" | |
File.delete file_path | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I tried it, and received the following error:
No clue where to begin with troubleshooting that one--just thought I’d mention my experience!