# HG changeset patch # User darius # Date 966064332 0 # Node ID f5daa3cdeb58663e98d7d8ed91d781c61e4614f3 # Parent cf06ab549064e1022f277f2ab9c264bddda97078 - Clear up old variable usage. - Grok Artist/Title in TTITLE fields. - Add the ability to append to track title fields. diff -r cf06ab549064 -r f5daa3cdeb58 cddb2.tcl --- a/cddb2.tcl Sat Aug 12 07:11:06 2000 +0000 +++ b/cddb2.tcl Sat Aug 12 07:12:12 2000 +0000 @@ -39,9 +39,6 @@ set tracks(albumartist) ""; set tracks(number) 0; - set dtitle ""; - set dartist ""; - # If the file doesn't exist we assume the user wants to enter new data if {![file exists $infile] && $infile != "-"} { puts "Please enter the number of tracks on the CD..." @@ -115,24 +112,29 @@ } "DTITLE" { - if { [ regexp {^(.*) / (.*)$} $value a tracks(albumartist) tracks(albumname)] == 1 } { -# puts "Got disc artist as $dartist, title as $dtitle"; - ; + if {[regexp {^(.*) / (.*)$} $value a tracks(albumartist) tracks(albumname)] != 1} { + set tracks(albumname) $value; } else { - set tracks(albumname) $value; -# puts "Got title as $value"; + puts "Atrist - $tracks(albumartist)"; } + puts "Title - $tracks(albumname)"; } "TTITLE([0-9]+)" { regexp {TTITLE([0-9]+)} $key a t_no; set t_no [ expr $t_no + 1 ]; - incr tracks(number); - - if {![regexp {^(.*) - (.*)$} $value a tracks(artist:$t_no) tracks(title:$t_no)] == 1} { - if {![regexp {^(.*)--(.*)$} $value a tracks(artist:$t_no) tracks(title:$t_no)] == 1} { - set tracks(artist:$t_no) $value; + if {[info exists tracks(title:$t_no)]} { + append tracks(title:$t_no) $value; + } else { + incr tracks(number); + + if {![regexp {^(.*) - (.*)$} $value a tracks(artist:$t_no) tracks(title:$t_no)] == 1} { + if {![regexp {^(.*)--(.*)$} $value a tracks(artist:$t_no) tracks(title:$t_no)] == 1} { + if {![regexp {^(.*) / (.*)$} $value a tracks(artist:$t_no) tracks(title:$t_no)] == 1} { + set tracks(title:$t_no) $value; + } + } } } } @@ -161,7 +163,8 @@ for {set i 1} {$i <= $tracks(number)} {incr i} { if {![info exists tracks(title:$i)]} { - error "track $i has no title!"; +# error "track $i has no title!"; + set tracks(title:$i) ""; } if {[info exists tracks(artist:$i)]} { @@ -169,9 +172,8 @@ continue; } - if {$dartist != ""} { + if {$tracks(albumartist) != ""} { set tracks(artist:$i) $tracks(albumartist); - # puts "setting artists to $dartist for $i (disc artist)"; continue; } @@ -188,6 +190,10 @@ } + if {$tracks(albumartist) == ""} { + set tracks(albumartist) "Various Artists"; + } + print_tracks "Before editing"; set tracks(updated) 0; edit_tracks; @@ -223,7 +229,7 @@ # Submitted via: Tcl Mangler 0.1 - Copyright (c) 1999 Daniel O'Connor # DISCID=$tracks(discid) -DTITLE=$tracks(albumname)"; +DTITLE=$tracks(albumartist) - $tracks(albumname)"; for { set i 1 } { $i <= $tracks(number) } { incr i } { puts $fh "TTITLE[expr $i - 1]=$tracks(artist:$i) - $tracks(title:$i)"; } @@ -232,22 +238,16 @@ } # Eat illegal characters - regsub {\\} $tracks(albumname) / tracks(albumname) - regsub \" $tracks(albumname) \\\" tracks(albumname) - - if { $dartist != "" } { - set dirname "$dartist - $tracks(albumname)"; - } else { - set dirname "Various Artists - $tracks(albumname)"; - } + quoter tracks(albumname); + quoter tracks(albumartist); + set dirname "$tracks(albumartist) - $tracks(albumname)"; puts $out "mkdir \"$dirname\""; for { set t_no 1 } { $t_no <= $tracks(number) } { incr t_no } { # Eat illegal characters - regsub -- {\\} $tracks(artist:$t_no) / tracks(artist:$t_no); - regsub -- {\\} $tracks(title:$t_no) / tracks(title:$t_no); - regsub -- \" $tracks(artist:$t_no) \\\" tracks(artist:$t_no); - regsub -- \" $tracks(title:$t_no) \\\" tracks(title:$t_no); + quoter tracks(artist:$t_no); + quoter tracks(title:$t_no); + set oldname [ eval format {$oldbasename} {$t_no} ]; set newname [ eval format {$newbasename} {"$tracks(artist:$t_no) - $tracks(title:$t_no)"} ]; @@ -266,6 +266,14 @@ } } +proc quoter {str_var} { + upvar $str_var str; + + regsub -all -- {/} $str {\\} str; + regsub -all -- {\"} $str {\"} str; +# regsub -all -- {\'} $str {\'} str; +} + proc print_tracks {outtitle} { global tracks;