This one speaks for itself.
#!/usr/bin/env ruby
# mp3mv.rb -- fixing your dumb assed mp3s
#
# mp3s with for-shit filenames are a fucking epidemic:
#
# $ ls
# Scientist - Look Out - Behind You!.mp3
# Scientist - Malicious Intent.mp3
# Scientist - Man-Trap.mp3
# Scientist - Prince's Wrath.mp3
# Scientist - S.O.S..mp3
# Scientist - Space Invaders Re-Group.mp3
# Scientist - The Dark Secret Of The Box.mp3
# Scientist - Under Surveillance.mp3
# Scientist - Vampire Initiative.mp3
# Scientist - World Cup Squad Lick The Wound.mp3
# cover.jpg
#
# Given a target of retardedly-named files like the
# above, mp3mv will read the metadata and rename, like so:
#
# $ mp3mv *
# $ ls
# 01_under_surveillance.mp3
# 02_princes_wrath.mp3
# 03_space_invaders_re-group.mp3
# 04_world_cup_squad_lick_the_wound.mp3
# 05_vampire_initiative.mp3
# 06_malicious_intent.mp3
# 07_the_dark_secret_of_the_box.mp3
# 08_s.o.s..mp3
# 09_man-trap.mp3
# 10_look_out_-_behind_you!.mp3
# cover.jpg
#
# Of course, this all assumes that your dumb-assed mp3s have proper metadata . . .
# As always, no warranties. I.e., I'm not to blame if
# this opens up a black hole or kills your goldfish, or if
# it fails to do either.
%w[rubygems pp mp3info].each{|lib| require lib}
if ARGV.length == 0
puts "Usage: #{File.basename $0} <mp3>"
exit
end
ARGV.each do |arg|
file = File.basename arg
next if file.split('.')[-1] != "mp3"
Mp3Info.open(arg) do |mp3|
begin
tn = mp3.tag.tracknum
tn = (tn.to_s.length==1) ? "0#{tn}" : tn # TODO make this not suck
# remove other dumb shit like single-quotes, spaces, parentheses, ampersands
`mv -v "#{arg}" "#{tn}_#{mp3.tag.title.downcase.gsub(/\s/,'_').gsub(/'|\&|\(|\)/,'')}.mp3"`
rescue Mp3InfoError => e
end
end
end