Skip to content

Instantly share code, notes, and snippets.

@tcaddy
Created April 10, 2015 01:52
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 tcaddy/20973a68ff7c60ef6229 to your computer and use it in GitHub Desktop.
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.
#!/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