#!/bin/sh # # \ exec tclsh $0 $@ package require Mk4tcl source cddb/cddb.tcl proc main { dbfile path } { file delete $dbfile mk::file open db $dbfile set ::cdTable [mk::view layout db.cds "DISCID ARTIST ALBUM" ] set ::trackTable [mk::view layout db.titles "DISCID NR:I1 LABEL" ] followTree $path mk::file close db } proc followTree {path} { if {[file isfile $path]} { readFile $path } elseif {[file isdirectory $path]} { foreach f [glob -nocomplain [file join $path *]] { followTree $f } } } proc readFile {file} { puts $file set fd [open $file r] while {[gets $fd line] >=0} { #puts $line if { [regexp {DISCID=([a-z0-9]*)} $line] } { regexp {DISCID=([a-z0-9]*)} $line all discid #puts "discid $discid" } elseif { [regexp "DTITLE=(.*) / (.*)" $line all artist album] } { #puts "Artist : $artist" #puts "Album : $album" mk::row append $::cdTable DISCID $discid ARTIST $artist ALBUM $album } elseif [regexp "TTITLE(\[0-9]\[0-9]*)=(.*)" $line all track title] { #puts $line incr track if {[ info exists titles($track) ]} { set titles($track) "$titles($track)$title" } else { set titles($track) $title } } } foreach track [array names titles] { #puts "$track : $titles($track)" mk::row append $::trackTable DISCID $discid NR $track LABEL $titles($track) } mk::file commit $::cdTable mk::file commit $::trackTable close $fd } puts [time "main cddb.db DB/classical" 1]