Created
February 28, 2009 04:47
-
-
Save tjstankus/71876 to your computer and use it in GitHub Desktop.
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
require 'rubygems' | |
require 'mp4info' | |
require 'fileutils' | |
def padded_track_num(num) | |
num <= 9 ? "0#{num}" : "#{num}" | |
end | |
print "Enter directory: " | |
dir = gets.chomp | |
full_path_dir = File.expand_path(dir) | |
Dir.foreach(full_path_dir) do |filename| | |
if File.extname(filename) == '.m4a' | |
full_path_filename = File.join(full_path_dir, filename) | |
File.open(full_path_filename) do |file| | |
mp4 = MP4Info.new(file) | |
filename_with_track = "#{padded_track_num(mp4.TRKN.first)} #{filename}" | |
full_path_filename_with_track = File.join(full_path_dir, filename_with_track) | |
FileUtils.mv(full_path_filename, full_path_filename_with_track) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment