Class MyDiscs
In: db/cddb-mydiscs.rb
Parent: Hash

Each style must provide this class to represent the the user's cd collection.

Methods
loaddir    new   
Public Class methods
new(cddbpath)

Initialize the disc hash.

# File db/cddb-mydiscs.rb, line 51
  def initialize(cddbpath)
    super()
    @cddbpath = cddbpath
  end
Public Instance methods
loaddir(topdir)

Find all dirs below topdir that have a 'discid' file and load the info for the dir from the id stored in that file (idea stolen from jwz's gronk).

topdir
top dir of tree to search
# File db/cddb-mydiscs.rb, line 61
  def loaddir(topdir)
    discids = Array.new
    Find.find(File.expand_path(topdir)) {
      |f|
      base = File.basename(f)
      if base == "discid" && File.file?(f)
	file = File.new(f)
	discid = file.gets.strip
	file.close
	discids.push([ discid, File.dirname(f) ])
      end
    }

    discids.each {
      |pair|
      id = pair.first; dir = pair.last
      cf = Cddbfile.new(File.join(@cddbpath, id))
      mp3s = Dir.glob(File.join(dir, "[0-9][0-9]-*.mp3"))
      next if mp3s.size < 1
      self[ id ] = disc = Disc.new(id)
      disc.dartist = cf.dartist
      disc.dtitle = cf.dtitle
      disc.dtracks = []
      mp3s.sort.each { 
	|f| 
	fn = File.basename(f)
	trk = fn[0,2]
	next if cf.dsongs[trk.to_i].nil?
	disc.dtracks.push(Track.new(trk, f, cf.dsongs[trk.to_i].secs, 
				    cf.dsongs[trk.to_i].song))
      }
      disc.dsecs = cf.dsecs
      disc.dyear = cf.dyear
    }
  end