Skip to content

Instantly share code, notes, and snippets.

@tshddx
Created January 24, 2012 08:34
Show Gist options
  • Save tshddx/1668883 to your computer and use it in GitHub Desktop.
Save tshddx/1668883 to your computer and use it in GitHub Desktop.
Sick of messing with crappy MP3 renaming/tagging/reorganizing tools for such a simple task.
require 'find'
require 'mp3info'
class ArtistsHash < Hash
def initialize
super
self.default_proc = proc do |h, artist_name|
h[artist_name] = AlbumsHash.new
end
end
def inspect
"ArtistsHash: #{super.inspect}"
end
end
class AlbumsHash < Hash
def initialize
super
self.default_proc = proc do |h, album_name|
h[album_name] = Album.new
end
end
def inspect
"AlbumsHash: #{super.inspect}"
end
end
class Album < Array
def inspect
"Album: #{super.inspect}"
end
end
class Mp3
DIRECTORY = ARGV.first #"/mnt/hgfs/R/music/2012-01-12 what.cd free leech mostly bluegrass"
def self.do
artists = ArtistsHash.new
skipped_files = []
count = 0
Find.find(DIRECTORY) do |file|
unless file =~ /\.mp3$/
skipped_files << file
next
end
next if file =~ /NEW COPY/
begin
Mp3Info.open(file) do |m|
artist = m.tag.artist
album = m.tag.album
track_title = m.tag.title
next if album =~ /Anthology of American Folk Music/
if artist && album && track_title
p [artist, album] if artists[artist][album].empty?
artists[artist][album] << track_title
count += 1
else
skipped_files << file
end
if count % 100 == 0
puts "===== DONE #{count.to_s.rjust 5}, skipped #{skipped_files.size.to_s.rjust 5}"
end
end
rescue
puts " ! !! EXCEPTION: #{file[DIRECTORY.size..-1]}"
end
end
return artists, skipped_files
end
end
if __FILE__ == $PROGRAM_NAME
Mp3.do
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment