Mercurial > ~darius > hgwebdir.cgi > cddb-stuff
comparison cddb2.tcl @ 6:f5daa3cdeb58
- Clear up old variable usage.
- Grok Artist/Title in TTITLE fields.
- Add the ability to append to track title fields.
author | darius |
---|---|
date | Sat, 12 Aug 2000 07:12:12 +0000 |
parents | dd6e30f7eb42 |
children | 2c01c09bdc0f |
comparison
equal
deleted
inserted
replaced
5:cf06ab549064 | 6:f5daa3cdeb58 |
---|---|
36 } | 36 } |
37 | 37 |
38 set tracks(albumname) ""; | 38 set tracks(albumname) ""; |
39 set tracks(albumartist) ""; | 39 set tracks(albumartist) ""; |
40 set tracks(number) 0; | 40 set tracks(number) 0; |
41 | |
42 set dtitle ""; | |
43 set dartist ""; | |
44 | 41 |
45 # If the file doesn't exist we assume the user wants to enter new data | 42 # If the file doesn't exist we assume the user wants to enter new data |
46 if {![file exists $infile] && $infile != "-"} { | 43 if {![file exists $infile] && $infile != "-"} { |
47 puts "Please enter the number of tracks on the CD..." | 44 puts "Please enter the number of tracks on the CD..." |
48 while { 1 } { | 45 while { 1 } { |
113 set tracks(discid) $value; | 110 set tracks(discid) $value; |
114 # puts "Got ID as $value"; | 111 # puts "Got ID as $value"; |
115 } | 112 } |
116 | 113 |
117 "DTITLE" { | 114 "DTITLE" { |
118 if { [ regexp {^(.*) / (.*)$} $value a tracks(albumartist) tracks(albumname)] == 1 } { | 115 if {[regexp {^(.*) / (.*)$} $value a tracks(albumartist) tracks(albumname)] != 1} { |
119 # puts "Got disc artist as $dartist, title as $dtitle"; | 116 set tracks(albumname) $value; |
120 ; | |
121 } else { | 117 } else { |
122 set tracks(albumname) $value; | 118 puts "Atrist - $tracks(albumartist)"; |
123 # puts "Got title as $value"; | |
124 } | 119 } |
120 puts "Title - $tracks(albumname)"; | |
125 } | 121 } |
126 | 122 |
127 "TTITLE([0-9]+)" { | 123 "TTITLE([0-9]+)" { |
128 regexp {TTITLE([0-9]+)} $key a t_no; | 124 regexp {TTITLE([0-9]+)} $key a t_no; |
129 set t_no [ expr $t_no + 1 ]; | 125 set t_no [ expr $t_no + 1 ]; |
130 | 126 |
131 incr tracks(number); | 127 if {[info exists tracks(title:$t_no)]} { |
132 | 128 append tracks(title:$t_no) $value; |
133 if {![regexp {^(.*) - (.*)$} $value a tracks(artist:$t_no) tracks(title:$t_no)] == 1} { | 129 } else { |
134 if {![regexp {^(.*)--(.*)$} $value a tracks(artist:$t_no) tracks(title:$t_no)] == 1} { | 130 incr tracks(number); |
135 set tracks(artist:$t_no) $value; | 131 |
132 if {![regexp {^(.*) - (.*)$} $value a tracks(artist:$t_no) tracks(title:$t_no)] == 1} { | |
133 if {![regexp {^(.*)--(.*)$} $value a tracks(artist:$t_no) tracks(title:$t_no)] == 1} { | |
134 if {![regexp {^(.*) / (.*)$} $value a tracks(artist:$t_no) tracks(title:$t_no)] == 1} { | |
135 set tracks(title:$t_no) $value; | |
136 } | |
137 } | |
136 } | 138 } |
137 } | 139 } |
138 } | 140 } |
139 | 141 |
140 "EXTT([0-9]+)" { | 142 "EXTT([0-9]+)" { |
159 incr i; | 161 incr i; |
160 } | 162 } |
161 | 163 |
162 for {set i 1} {$i <= $tracks(number)} {incr i} { | 164 for {set i 1} {$i <= $tracks(number)} {incr i} { |
163 if {![info exists tracks(title:$i)]} { | 165 if {![info exists tracks(title:$i)]} { |
164 error "track $i has no title!"; | 166 # error "track $i has no title!"; |
167 set tracks(title:$i) ""; | |
165 } | 168 } |
166 | 169 |
167 if {[info exists tracks(artist:$i)]} { | 170 if {[info exists tracks(artist:$i)]} { |
168 # puts "artist exists for $i"; | 171 # puts "artist exists for $i"; |
169 continue; | 172 continue; |
170 } | 173 } |
171 | 174 |
172 if {$dartist != ""} { | 175 if {$tracks(albumartist) != ""} { |
173 set tracks(artist:$i) $tracks(albumartist); | 176 set tracks(artist:$i) $tracks(albumartist); |
174 # puts "setting artists to $dartist for $i (disc artist)"; | |
175 continue; | 177 continue; |
176 } | 178 } |
177 | 179 |
178 if {[info exists ext($i)] && $ext($i) != ""} { | 180 if {[info exists ext($i)] && $ext($i) != ""} { |
179 set tracks(artist:$i) $ext($i); | 181 set tracks(artist:$i) $ext($i); |
185 } | 187 } |
186 | 188 |
187 # puts "$tracks(number) tracks"; | 189 # puts "$tracks(number) tracks"; |
188 | 190 |
189 } | 191 } |
192 | |
193 if {$tracks(albumartist) == ""} { | |
194 set tracks(albumartist) "Various Artists"; | |
195 } | |
190 | 196 |
191 print_tracks "Before editing"; | 197 print_tracks "Before editing"; |
192 set tracks(updated) 0; | 198 set tracks(updated) 0; |
193 edit_tracks; | 199 edit_tracks; |
194 print_tracks "After editing"; | 200 print_tracks "After editing"; |
221 # | 227 # |
222 # Revision: 1 | 228 # Revision: 1 |
223 # Submitted via: Tcl Mangler 0.1 - Copyright (c) 1999 Daniel O'Connor | 229 # Submitted via: Tcl Mangler 0.1 - Copyright (c) 1999 Daniel O'Connor |
224 # | 230 # |
225 DISCID=$tracks(discid) | 231 DISCID=$tracks(discid) |
226 DTITLE=$tracks(albumname)"; | 232 DTITLE=$tracks(albumartist) - $tracks(albumname)"; |
227 for { set i 1 } { $i <= $tracks(number) } { incr i } { | 233 for { set i 1 } { $i <= $tracks(number) } { incr i } { |
228 puts $fh "TTITLE[expr $i - 1]=$tracks(artist:$i) - $tracks(title:$i)"; | 234 puts $fh "TTITLE[expr $i - 1]=$tracks(artist:$i) - $tracks(title:$i)"; |
229 } | 235 } |
230 } msg ] } { | 236 } msg ] } { |
231 puts "Failed to write $infile, $msg"; | 237 puts "Failed to write $infile, $msg"; |
232 } | 238 } |
233 | 239 |
234 # Eat illegal characters | 240 # Eat illegal characters |
235 regsub {\\} $tracks(albumname) / tracks(albumname) | 241 quoter tracks(albumname); |
236 regsub \" $tracks(albumname) \\\" tracks(albumname) | 242 quoter tracks(albumartist); |
237 | 243 set dirname "$tracks(albumartist) - $tracks(albumname)"; |
238 if { $dartist != "" } { | |
239 set dirname "$dartist - $tracks(albumname)"; | |
240 } else { | |
241 set dirname "Various Artists - $tracks(albumname)"; | |
242 } | |
243 | 244 |
244 puts $out "mkdir \"$dirname\""; | 245 puts $out "mkdir \"$dirname\""; |
245 for { set t_no 1 } { $t_no <= $tracks(number) } { incr t_no } { | 246 for { set t_no 1 } { $t_no <= $tracks(number) } { incr t_no } { |
246 # Eat illegal characters | 247 # Eat illegal characters |
247 regsub -- {\\} $tracks(artist:$t_no) / tracks(artist:$t_no); | 248 quoter tracks(artist:$t_no); |
248 regsub -- {\\} $tracks(title:$t_no) / tracks(title:$t_no); | 249 quoter tracks(title:$t_no); |
249 regsub -- \" $tracks(artist:$t_no) \\\" tracks(artist:$t_no); | 250 |
250 regsub -- \" $tracks(title:$t_no) \\\" tracks(title:$t_no); | |
251 set oldname [ eval format {$oldbasename} {$t_no} ]; | 251 set oldname [ eval format {$oldbasename} {$t_no} ]; |
252 set newname [ eval format {$newbasename} {"$tracks(artist:$t_no) - $tracks(title:$t_no)"} ]; | 252 set newname [ eval format {$newbasename} {"$tracks(artist:$t_no) - $tracks(title:$t_no)"} ]; |
253 | 253 |
254 puts $out "mp3info -a \"$tracks(artist:$t_no)\" -t \"$tracks(title:$t_no)\" -l \"$tracks(albumname)\" -c \"Track $t_no\" -F 4 \"$oldname\""; | 254 puts $out "mp3info -a \"$tracks(artist:$t_no)\" -t \"$tracks(title:$t_no)\" -l \"$tracks(albumname)\" -c \"Track $t_no\" -F 4 \"$oldname\""; |
255 puts $out "mv \"$oldname\" \"$dirname/$newname\""; | 255 puts $out "mv \"$oldname\" \"$dirname/$newname\""; |
262 if {[info exists fh]} { | 262 if {[info exists fh]} { |
263 if {[catch {close $fh} msg]} { | 263 if {[catch {close $fh} msg]} { |
264 puts "Got $msg closing fh"; | 264 puts "Got $msg closing fh"; |
265 } | 265 } |
266 } | 266 } |
267 } | |
268 | |
269 proc quoter {str_var} { | |
270 upvar $str_var str; | |
271 | |
272 regsub -all -- {/} $str {\\} str; | |
273 regsub -all -- {\"} $str {\"} str; | |
274 # regsub -all -- {\'} $str {\'} str; | |
267 } | 275 } |
268 | 276 |
269 proc print_tracks {outtitle} { | 277 proc print_tracks {outtitle} { |
270 global tracks; | 278 global tracks; |
271 | 279 |