Created
April 10, 2015 01:52
-
-
Save tcaddy/20973a68ff7c60ef6229 to your computer and use it in GitHub Desktop.
Rename mp3 files for my Toyota radio to maintain song order. Copy this file to folder of mp3 files for an album and run it.
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 | |
# coding: utf-8 | |
require 'rubygems' | |
require "mp3info" | |
dir = File.expand_path(File.dirname(__FILE__)) | |
Dir["#{dir}/*mp3"].each do |filename| | |
Mp3Info.open(filename) do |mp3| | |
disk_num = mp3.tag2["disc_number"] | |
track_num = "%02d" % mp3.tag2["TRCK"].split("/")[0].to_i | |
new_filename = "#{disk_num}_#{track_num}_#{File.basename(filename)}" | |
File.rename filename,"#{dir}/#{new_filename}" | |
puts "renamed #{File.basename(filename)} to #{new_filename}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment