Skip to content

Instantly share code, notes, and snippets.

@danhigham
Created April 1, 2012 16:30
Show Gist options
  • Save danhigham/2276810 to your computer and use it in GitHub Desktop.
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)
#!/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
@SteveBenner
Copy link

I tried it, and received the following error:

dyld: lazy symbol binding failed: Symbol not found: _rb_ary_new_from_values
  Referenced from: /Users/me/.gem/ruby/2.1.3/gems/psych-2.0.8/lib/psych.bundle
  Expected in: flat namespace

dyld: Symbol not found: _rb_ary_new_from_values
  Referenced from: /Users/me/.gem/ruby/2.1.3/gems/psych-2.0.8/lib/psych.bundle
  Expected in: flat namespace

Trace/BPT trap: 5

No clue where to begin with troubleshooting that one--just thought I’d mention my experience!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment