annotate cddb2.tcl @ 2:5cead4da1db9

Initial import. Seems to work nicely.
author darius
date Wed, 09 Aug 2000 02:18:47 +0000
parents dd6e30f7eb42
children f5daa3cdeb58
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
1 #!/usr/local/bin/tclsh8.2
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
2
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
3 #
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
4 # This software is copyright Daniel O'Connor (darius@dons.net.au) 1998, 1999
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
5 #
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
6 # This software is release under the GNU Public License Version 2.
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
7 # A copy of this licence must be distributed with this software.
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
8 #
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
9
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
10 proc main {} {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
11 global argv0 argv tracks auto_path;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
12
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
13 lappend auto_path "[file dirname $argv0]";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
14 lappend auto_path ".";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
15
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
16 if { [ catch {loadlibs [ list tk82 ]} msg] } {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
17 log "Failed to load library files - $msg";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
18 exit 1;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
19 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
20 # puts $auto_path
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
21
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
22 if { [ llength $argv ] != 4 } {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
23 puts "Bad usage";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
24 puts "$argv0 <shellfile> <oldbasename> <newbasename> <infile>";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
25 exit;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
26 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
27
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
28 set shellfile [ lindex $argv 0 ];
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
29 set oldbasename [ lindex $argv 1 ];
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
30 set newbasename [ lindex $argv 2 ];
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
31 set infile [ lindex $argv 3 ]
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
32
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
33 if {[file exists $shellfile] && ![file writable $shellfile]} {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
34 puts "$shellfile not writeable, aborting";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
35 exit 1;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
36 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
37
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
38 set tracks(albumname) "";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
39 set tracks(albumartist) "";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
40 set tracks(number) 0;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
41
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
42 set dtitle "";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
43 set dartist "";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
44
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
45 # If the file doesn't exist we assume the user wants to enter new data
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
46 if {![file exists $infile] && $infile != "-"} {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
47 puts "Please enter the number of tracks on the CD..."
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
48 while { 1 } {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
49 puts -nonewline "-> ";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
50 flush stdout;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
51 set tracks(number) [ gets stdin ];
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
52 if { ($tracks(number) >= 1) && ($tracks(number) <= 100) } {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
53 break;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
54 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
55 puts "Please enter a number between 1 and 100";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
56 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
57
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
58 set tracks(disclen) 1;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
59 set tracks(discid) 1;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
60
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
61 for { set t_no 1 } { $t_no <= $tracks(number) } { incr t_no } {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
62 set tracks(artist:$t_no) "";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
63 set tracks(title:$t_no) "";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
64 set tracks(offset:$t_no) 1;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
65 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
66
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
67 } else {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
68 if { $infile == "-" } {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
69 set fh stdin;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
70 } else {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
71 set fh [ open $infile "r" ];
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
72 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
73
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
74 set offset_seek 0;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
75 set offset_list "";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
76
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
77 while {![eof $fh]} {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
78 set line [gets $fh];
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
79 # puts "Line = $line";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
80 if {$offset_seek > 0} {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
81 if {$line == "\#"} {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
82 # puts "Comment skip"
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
83 continue;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
84 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
85
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
86 if {[ regexp {^\#[ ]+([0-9]+)} $line a offset] == 1} {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
87 puts "Adding $offset";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
88 lappend offset_list $offset;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
89 continue;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
90 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
91
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
92 # Change back to default state
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
93 puts "Not looking for offsets";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
94 set offset_seek 0;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
95 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
96
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
97 if {[regexp {^\# Track frame offsets:} $line] == 1} {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
98 # Change to looking for offsets state
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
99 puts "Looking for offsets";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
100 set offset_seek 1;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
101 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
102
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
103 if {[regexp {^\# Disc length: +([0-9]+)} $line a tracks(disclen)] == 1} {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
104 continue;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
105 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
106
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
107 if {[regexp {([A-Z0-9]*)=(.*)} $line a key value] == 0} {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
108 continue;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
109 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
110
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
111 switch -regexp -- $key {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
112 "DISCID" {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
113 set tracks(discid) $value;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
114 # puts "Got ID as $value";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
115 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
116
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
117 "DTITLE" {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
118 if { [ regexp {^(.*) / (.*)$} $value a tracks(albumartist) tracks(albumname)] == 1 } {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
119 # puts "Got disc artist as $dartist, title as $dtitle";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
120 ;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
121 } else {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
122 set tracks(albumname) $value;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
123 # puts "Got title as $value";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
124 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
125 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
126
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
127 "TTITLE([0-9]+)" {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
128 regexp {TTITLE([0-9]+)} $key a t_no;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
129 set t_no [ expr $t_no + 1 ];
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
130
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
131 incr tracks(number);
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
132
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
133 if {![regexp {^(.*) - (.*)$} $value a tracks(artist:$t_no) tracks(title:$t_no)] == 1} {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
134 if {![regexp {^(.*)--(.*)$} $value a tracks(artist:$t_no) tracks(title:$t_no)] == 1} {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
135 set tracks(artist:$t_no) $value;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
136 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
137 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
138 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
139
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
140 "EXTT([0-9]+)" {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
141 regexp {EXTT([0-9]+)} $key a t_no;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
142 set t_no [ expr $t_no + 1 ];
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
143 set ext($t_no) $value;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
144 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
145 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
146 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
147
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
148 # puts "Offset list - $offset_list";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
149 # puts "Disclength - $tracks(disclen)";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
150
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
151 if {$tracks(number) < 1 || [llength $offset_list] != $tracks(number)} {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
152 puts stderr "Invalid file, $tracks(number)";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
153 exit 1;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
154 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
155
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
156 set i 1;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
157 foreach t $offset_list {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
158 set tracks(offset:$i) $t;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
159 incr i;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
160 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
161
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
162 for {set i 1} {$i <= $tracks(number)} {incr i} {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
163 if {![info exists tracks(title:$i)]} {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
164 error "track $i has no title!";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
165 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
166
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
167 if {[info exists tracks(artist:$i)]} {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
168 # puts "artist exists for $i";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
169 continue;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
170 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
171
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
172 if {$dartist != ""} {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
173 set tracks(artist:$i) $tracks(albumartist);
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
174 # puts "setting artists to $dartist for $i (disc artist)";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
175 continue;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
176 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
177
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
178 if {[info exists ext($i)] && $ext($i) != ""} {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
179 set tracks(artist:$i) $ext($i);
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
180 # puts "setting artist to $ext($i) for $i";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
181 continue;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
182 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
183
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
184 set t_artist($i) "Unknown";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
185 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
186
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
187 # puts "$tracks(number) tracks";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
188
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
189 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
190
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
191 print_tracks "Before editing";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
192 set tracks(updated) 0;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
193 edit_tracks;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
194 print_tracks "After editing";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
195
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
196 if {$tracks(updated) == 0} {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
197 puts "Nothing saved aborting";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
198 puts "";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
199 exit 0;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
200 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
201
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
202 set out [ open $shellfile "w" ];
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
203
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
204 if { [ catch {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
205 if {$infile == "-"} {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
206 set fh stdout;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
207 } else {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
208 file rename -force "$infile" "$infile.old"
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
209 set fh [ open "$infile" "w" ];
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
210 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
211
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
212 puts $fh "# xmcd CD database file
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
213 # Copyright (C) 1993-1999 CDDB, Inc.
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
214 #
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
215 # Track frame offsets:";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
216 for { set i 1 } { $i <= $tracks(number) } { incr i } {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
217 puts $fh "#\t$tracks(offset:$i)"
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
218 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
219 puts $fh "#
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
220 # Disc length: $tracks(disclen) seconds
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
221 #
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
222 # Revision: 1
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
223 # Submitted via: Tcl Mangler 0.1 - Copyright (c) 1999 Daniel O'Connor
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
224 #
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
225 DISCID=$tracks(discid)
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
226 DTITLE=$tracks(albumname)";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
227 for { set i 1 } { $i <= $tracks(number) } { incr i } {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
228 puts $fh "TTITLE[expr $i - 1]=$tracks(artist:$i) - $tracks(title:$i)";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
229 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
230 } msg ] } {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
231 puts "Failed to write $infile, $msg";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
232 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
233
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
234 # Eat illegal characters
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
235 regsub {\\} $tracks(albumname) / tracks(albumname)
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
236 regsub \" $tracks(albumname) \\\" tracks(albumname)
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
237
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
238 if { $dartist != "" } {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
239 set dirname "$dartist - $tracks(albumname)";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
240 } else {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
241 set dirname "Various Artists - $tracks(albumname)";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
242 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
243
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
244 puts $out "mkdir \"$dirname\"";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
245 for { set t_no 1 } { $t_no <= $tracks(number) } { incr t_no } {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
246 # Eat illegal characters
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
247 regsub -- {\\} $tracks(artist:$t_no) / tracks(artist:$t_no);
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
248 regsub -- {\\} $tracks(title:$t_no) / tracks(title:$t_no);
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
249 regsub -- \" $tracks(artist:$t_no) \\\" tracks(artist:$t_no);
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
250 regsub -- \" $tracks(title:$t_no) \\\" tracks(title:$t_no);
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
251 set oldname [ eval format {$oldbasename} {$t_no} ];
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
252 set newname [ eval format {$newbasename} {"$tracks(artist:$t_no) - $tracks(title:$t_no)"} ];
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
253
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
254 puts $out "mp3info -a \"$tracks(artist:$t_no)\" -t \"$tracks(title:$t_no)\" -l \"$tracks(albumname)\" -c \"Track $t_no\" -F 4 \"$oldname\"";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
255 puts $out "mv \"$oldname\" \"$dirname/$newname\"";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
256 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
257
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
258 if {[catch {close $out} msg]} {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
259 puts "Got $msg closing renamer";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
260 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
261
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
262 if {[info exists fh]} {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
263 if {[catch {close $fh} msg]} {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
264 puts "Got $msg closing fh";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
265 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
266 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
267 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
268
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
269 proc print_tracks {outtitle} {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
270 global tracks;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
271
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
272 puts "================================================================================";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
273 puts "$outtitle";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
274 puts "================================================================================";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
275 puts "Title: $tracks(albumname)"
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
276 if { $tracks(albumartist) != "" } {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
277 puts "Artist: $tracks(albumartist)";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
278 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
279 for { set t_no 1 } { $t_no <= $tracks(number) } { incr t_no } {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
280 puts [format "Track %d: %s - %s" $t_no $tracks(artist:$t_no) $tracks(title:$t_no)];
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
281 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
282
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
283 puts "================================================================================";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
284 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
285
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
286 main;