mkcddb.rb
Path: mkcddb/mkcddb.rb
Modified: Wed Mar 26 21:36:05 MST 2003
Required files
find    ftools    optparse    shellwords    tempfile    mp3info   
Methods
cddb_discid    cddb_sum    main    mkcddbfile    start   
Classes and Modules
Class FInfo
Class FilesInDir
Class Opts
Class SecsFrames
Public Instance methods
cddb_sum(n)
# File mkcddb/mkcddb.rb, line 103
def cddb_sum(n)
  ret = 0
  begin
    ret += (n % 10); n /= 10
  end until n < 1
  return ret
end
cddb_discid(files)
# File mkcddb/mkcddb.rb, line 111
def cddb_discid(files)
  n = 0
  files.files.values {
    |file|
    n += cddb_sum(file.length.secs)
  }
  totlen = files.dsecs
  format("%08x", ((n & 0xff) << 24) | (totlen << 8) | files.files.size)
end
mkcddbfile(dir, v)
# File mkcddb/mkcddb.rb, line 121
def mkcddbfile(dir, v)
  files = FilesInDir.new(dir)
  starts = [ 150 ]
  lasttrk = files.files.keys.last.to_i
  1.upto(lasttrk) {
    |n|
    key = format("%02d", n)
    if files.files[key].nil?
      starts << starts.last
    else
      starts << files.files[key].length.frames + starts.last
    end
  }
  tf = Tempfile.new(APPNAME)
  tfpath = tf.path
  tf.puts("# xmcd CD database file created by mkcddb.pl")
  tf.puts("#")
  tf.puts("# Track frame offsets:")
  tf.puts("#")
  starts.each {
    |frame|
    tf.puts("#\t#{frame}")
  }
  tf.puts("#")
  tf.puts("# Disc length in seconds: #{files.dsecs}")
  tf.puts("#")
  tf.puts("# Revision: 3")
  tf.puts("# Submitted by mkcddb.pl (c) 2003 Alan Eldridge")
  tf.puts("#")
  tf.puts("DISCID=#{files.discid}")
  tf.puts("DTITLE=#{files.dartist} / #{files.dtitle}")
  tf.puts("DYEAR=1900")
  tf.puts("DGENRE=rock")
  1.upto(lasttrk) {
    |n|
    key = format("%02d", n)
    if files.files[key].nil?
      tf.puts("TTITLE#{n - 1}=Null_#{n}")
    else
      tf.puts("TTITLE#{n - 1}=#{files.files[key].title}")
    end
  }
  tf.close
  fork {
    exec("vim #{tfpath}")
  }
  Process.wait
  tf.open
  STDOUT.write(tf.readlines.join)
end
main(opts, rest)
# File mkcddb/mkcddb.rb, line 172
def main(opts, rest)

  v = opts["verbose"]

  if rest.size == 0
    while dir = $stdin.gets()
      mkcddbfile(dir.chomp, v)
    end
  else
    rest.each {
      |dir| mkcddbfile(dir.chomp, v)
    }
  end
  return 0

end
start(av)

Entry point if called as executable.

# File mkcddb/mkcddb.rb, line 251
def start(av)
  opts = Opts.new(USAGE, BANNER)
  return main(opts.hopt, opts.parse(av))
end