module Rob::Gordon

Constants

INTRO

Public Class Methods

filename(track, title) click to toggle source
# File lib/rob.rb, line 85
def self.filename(track, title)
        if track.to_i < 10
                "0#{ track }. #{ title }.mp3"
        else
                "#{ track }. #{ title }.mp3"
        end
end
import!(indir, libdir=" click to toggle source
# File lib/rob.rb, line 37
def self.import!(indir, libdir="#{ ENV['HOME']}/Music")
        puts "Imporing all mp3s in: #{ indir }"
        puts "Now importing to #{ libdir }"
        Dir[File.join(indir, '**.mp3')].sort.each do |file|
                if File.extname(file) == '.mp3'
                        song = ID3Lib::Tag.new file
                        begin
                                artist =  song.artist
                                album  =  song.album
                                track      =  song.track[0]
                                title  =  song.title
                                # yeah, dupe the code to force the exception, if it's gonna happen.
                                dest = File.join(libdir, artist, album)
                        rescue 
                                # Suck a dick, UTF-16
                                artist = Iconv.conv('UTF-8', 'UTF-16BE', song.artist)
                                album  = Iconv.conv('UTF-8', 'UTF-16BE', song.album)
                                track      = Iconv.conv('UTF-8', 'UTF-16BE', song.track)[0]
                                title  = Iconv.conv('UTF-8', 'UTF-16BE', song.title) 
                        end

                        out_file = filename(track, title)
                        dest = File.join(libdir, artist, album, out_file)
                        artistdir = File.join(libdir, artist)
                        albumdir = File.join(artistdir, album)

                        if !File.exists? dest
                                if !Dir.exists? artistdir
                                        puts "Creating artist directory #{ artistdir }"
                                        Dir.mkdir artistdir
                                end

                                if !Dir.exists? albumdir
                                        puts "Creating album directory #{ albumdir }"
                                        Dir.mkdir albumdir
                                end
                                
                                puts "Now importing #{ title } to #{ dest }"
                                FileUtils.cp file, dest
                        else
                                puts "Destination file #{ dest } exists, skipping..."
                        end
                else

                end
        end
end
run!(*args) click to toggle source
# File lib/rob.rb, line 20
def self.run!(*args)
                                
        case args.length
        when 0
                puts INTRO
        when 1
                indir = args[0]
                import!(indir)
        when 2
                indir, lib = args
                import!(indir, lib)
        else
                puts INTRO
        end
        return 0
end