Skip to content

Instantly share code, notes, and snippets.

@tjstankus
Created February 28, 2009 04:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tjstankus/71876 to your computer and use it in GitHub Desktop.
Save tjstankus/71876 to your computer and use it in GitHub Desktop.
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