-
-
Save wiserfirst/3b034adfa06716b21fe4 to your computer and use it in GitHub Desktop.
Convert all m4a files in a directory into mp3
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/env 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.basename file_path, ".m4a" | |
mp3_path = "#{file_name}.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 "faad -o '#{wav_path}' '#{file_path}'" | |
system "lame --abr 64 -h --tt '#{title}' --ta '#{artist}' --tl '#{album}' --ty '#{year}' --tc '#{comment}' --tn '#{track_no}' --tg '#{genre}' '#{wav_path}' '#{mp3_path}'" | |
File.delete wav_path | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage:
Requirements:
This ruby script rely on ruby gem 'mp4info' and package faad2 and lame, which can be installed by the following commands on OS X with brew