annotate cddb2.tcl @ 7:ad83a38c3f5a

Don't open RW - not necessary.
author darius
date Thu, 18 Jul 2002 06:29:35 +0000
parents f5daa3cdeb58
children 2c01c09bdc0f
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 # If the file doesn't exist we assume the user wants to enter new data
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
43 if {![file exists $infile] && $infile != "-"} {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
44 puts "Please enter the number of tracks on the CD..."
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
45 while { 1 } {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
46 puts -nonewline "-> ";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
47 flush stdout;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
48 set tracks(number) [ gets stdin ];
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
49 if { ($tracks(number) >= 1) && ($tracks(number) <= 100) } {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
50 break;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
51 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
52 puts "Please enter a number between 1 and 100";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
53 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
54
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
55 set tracks(disclen) 1;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
56 set tracks(discid) 1;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
57
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
58 for { set t_no 1 } { $t_no <= $tracks(number) } { incr t_no } {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
59 set tracks(artist:$t_no) "";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
60 set tracks(title:$t_no) "";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
61 set tracks(offset:$t_no) 1;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
62 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
63
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
64 } else {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
65 if { $infile == "-" } {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
66 set fh stdin;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
67 } else {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
68 set fh [ open $infile "r" ];
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
69 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
70
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
71 set offset_seek 0;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
72 set offset_list "";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
73
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
74 while {![eof $fh]} {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
75 set line [gets $fh];
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
76 # puts "Line = $line";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
77 if {$offset_seek > 0} {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
78 if {$line == "\#"} {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
79 # puts "Comment skip"
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
80 continue;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
81 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
82
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
83 if {[ regexp {^\#[ ]+([0-9]+)} $line a offset] == 1} {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
84 puts "Adding $offset";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
85 lappend offset_list $offset;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
86 continue;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
87 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
88
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
89 # Change back to default state
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
90 puts "Not looking for offsets";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
91 set offset_seek 0;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
92 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
93
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
94 if {[regexp {^\# Track frame offsets:} $line] == 1} {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
95 # Change to looking for offsets state
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
96 puts "Looking for offsets";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
97 set offset_seek 1;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
98 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
99
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
100 if {[regexp {^\# Disc length: +([0-9]+)} $line a tracks(disclen)] == 1} {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
101 continue;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
102 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
103
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
104 if {[regexp {([A-Z0-9]*)=(.*)} $line a key value] == 0} {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
105 continue;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
106 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
107
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
108 switch -regexp -- $key {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
109 "DISCID" {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
110 set tracks(discid) $value;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
111 # puts "Got ID as $value";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
112 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
113
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
114 "DTITLE" {
6
f5daa3cdeb58 - Clear up old variable usage.
darius
parents: 1
diff changeset
115 if {[regexp {^(.*) / (.*)$} $value a tracks(albumartist) tracks(albumname)] != 1} {
f5daa3cdeb58 - Clear up old variable usage.
darius
parents: 1
diff changeset
116 set tracks(albumname) $value;
1
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
117 } else {
6
f5daa3cdeb58 - Clear up old variable usage.
darius
parents: 1
diff changeset
118 puts "Atrist - $tracks(albumartist)";
1
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
119 }
6
f5daa3cdeb58 - Clear up old variable usage.
darius
parents: 1
diff changeset
120 puts "Title - $tracks(albumname)";
1
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
121 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
122
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
123 "TTITLE([0-9]+)" {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
124 regexp {TTITLE([0-9]+)} $key a t_no;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
125 set t_no [ expr $t_no + 1 ];
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
126
6
f5daa3cdeb58 - Clear up old variable usage.
darius
parents: 1
diff changeset
127 if {[info exists tracks(title:$t_no)]} {
f5daa3cdeb58 - Clear up old variable usage.
darius
parents: 1
diff changeset
128 append tracks(title:$t_no) $value;
f5daa3cdeb58 - Clear up old variable usage.
darius
parents: 1
diff changeset
129 } else {
f5daa3cdeb58 - Clear up old variable usage.
darius
parents: 1
diff changeset
130 incr tracks(number);
f5daa3cdeb58 - Clear up old variable usage.
darius
parents: 1
diff changeset
131
f5daa3cdeb58 - Clear up old variable usage.
darius
parents: 1
diff changeset
132 if {![regexp {^(.*) - (.*)$} $value a tracks(artist:$t_no) tracks(title:$t_no)] == 1} {
f5daa3cdeb58 - Clear up old variable usage.
darius
parents: 1
diff changeset
133 if {![regexp {^(.*)--(.*)$} $value a tracks(artist:$t_no) tracks(title:$t_no)] == 1} {
f5daa3cdeb58 - Clear up old variable usage.
darius
parents: 1
diff changeset
134 if {![regexp {^(.*) / (.*)$} $value a tracks(artist:$t_no) tracks(title:$t_no)] == 1} {
f5daa3cdeb58 - Clear up old variable usage.
darius
parents: 1
diff changeset
135 set tracks(title:$t_no) $value;
f5daa3cdeb58 - Clear up old variable usage.
darius
parents: 1
diff changeset
136 }
f5daa3cdeb58 - Clear up old variable usage.
darius
parents: 1
diff changeset
137 }
1
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
138 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
139 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
140 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
141
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
142 "EXTT([0-9]+)" {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
143 regexp {EXTT([0-9]+)} $key a t_no;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
144 set t_no [ expr $t_no + 1 ];
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
145 set ext($t_no) $value;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
146 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
147 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
148 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
149
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
150 # puts "Offset list - $offset_list";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
151 # puts "Disclength - $tracks(disclen)";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
152
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
153 if {$tracks(number) < 1 || [llength $offset_list] != $tracks(number)} {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
154 puts stderr "Invalid file, $tracks(number)";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
155 exit 1;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
156 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
157
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
158 set i 1;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
159 foreach t $offset_list {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
160 set tracks(offset:$i) $t;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
161 incr i;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
162 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
163
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
164 for {set i 1} {$i <= $tracks(number)} {incr i} {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
165 if {![info exists tracks(title:$i)]} {
6
f5daa3cdeb58 - Clear up old variable usage.
darius
parents: 1
diff changeset
166 # error "track $i has no title!";
f5daa3cdeb58 - Clear up old variable usage.
darius
parents: 1
diff changeset
167 set tracks(title:$i) "";
1
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
168 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
169
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
170 if {[info exists tracks(artist:$i)]} {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
171 # puts "artist exists for $i";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
172 continue;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
173 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
174
6
f5daa3cdeb58 - Clear up old variable usage.
darius
parents: 1
diff changeset
175 if {$tracks(albumartist) != ""} {
1
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
176 set tracks(artist:$i) $tracks(albumartist);
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
177 continue;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
178 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
179
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
180 if {[info exists ext($i)] && $ext($i) != ""} {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
181 set tracks(artist:$i) $ext($i);
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
182 # puts "setting artist to $ext($i) for $i";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
183 continue;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
184 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
185
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
186 set t_artist($i) "Unknown";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
187 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
188
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
189 # puts "$tracks(number) tracks";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
190
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
191 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
192
6
f5daa3cdeb58 - Clear up old variable usage.
darius
parents: 1
diff changeset
193 if {$tracks(albumartist) == ""} {
f5daa3cdeb58 - Clear up old variable usage.
darius
parents: 1
diff changeset
194 set tracks(albumartist) "Various Artists";
f5daa3cdeb58 - Clear up old variable usage.
darius
parents: 1
diff changeset
195 }
f5daa3cdeb58 - Clear up old variable usage.
darius
parents: 1
diff changeset
196
1
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
197 print_tracks "Before editing";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
198 set tracks(updated) 0;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
199 edit_tracks;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
200 print_tracks "After editing";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
201
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
202 if {$tracks(updated) == 0} {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
203 puts "Nothing saved aborting";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
204 puts "";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
205 exit 0;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
206 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
207
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
208 set out [ open $shellfile "w" ];
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
209
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
210 if { [ catch {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
211 if {$infile == "-"} {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
212 set fh stdout;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
213 } else {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
214 file rename -force "$infile" "$infile.old"
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
215 set fh [ open "$infile" "w" ];
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
216 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
217
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
218 puts $fh "# xmcd CD database file
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
219 # Copyright (C) 1993-1999 CDDB, Inc.
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
220 #
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
221 # Track frame offsets:";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
222 for { set i 1 } { $i <= $tracks(number) } { incr i } {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
223 puts $fh "#\t$tracks(offset:$i)"
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
224 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
225 puts $fh "#
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
226 # Disc length: $tracks(disclen) seconds
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
227 #
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
228 # Revision: 1
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
229 # Submitted via: Tcl Mangler 0.1 - Copyright (c) 1999 Daniel O'Connor
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
230 #
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
231 DISCID=$tracks(discid)
6
f5daa3cdeb58 - Clear up old variable usage.
darius
parents: 1
diff changeset
232 DTITLE=$tracks(albumartist) - $tracks(albumname)";
1
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
233 for { set i 1 } { $i <= $tracks(number) } { incr i } {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
234 puts $fh "TTITLE[expr $i - 1]=$tracks(artist:$i) - $tracks(title:$i)";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
235 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
236 } msg ] } {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
237 puts "Failed to write $infile, $msg";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
238 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
239
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
240 # Eat illegal characters
6
f5daa3cdeb58 - Clear up old variable usage.
darius
parents: 1
diff changeset
241 quoter tracks(albumname);
f5daa3cdeb58 - Clear up old variable usage.
darius
parents: 1
diff changeset
242 quoter tracks(albumartist);
f5daa3cdeb58 - Clear up old variable usage.
darius
parents: 1
diff changeset
243 set dirname "$tracks(albumartist) - $tracks(albumname)";
1
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
244
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
245 puts $out "mkdir \"$dirname\"";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
246 for { set t_no 1 } { $t_no <= $tracks(number) } { incr t_no } {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
247 # Eat illegal characters
6
f5daa3cdeb58 - Clear up old variable usage.
darius
parents: 1
diff changeset
248 quoter tracks(artist:$t_no);
f5daa3cdeb58 - Clear up old variable usage.
darius
parents: 1
diff changeset
249 quoter tracks(title:$t_no);
f5daa3cdeb58 - Clear up old variable usage.
darius
parents: 1
diff changeset
250
1
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
6
f5daa3cdeb58 - Clear up old variable usage.
darius
parents: 1
diff changeset
269 proc quoter {str_var} {
f5daa3cdeb58 - Clear up old variable usage.
darius
parents: 1
diff changeset
270 upvar $str_var str;
f5daa3cdeb58 - Clear up old variable usage.
darius
parents: 1
diff changeset
271
f5daa3cdeb58 - Clear up old variable usage.
darius
parents: 1
diff changeset
272 regsub -all -- {/} $str {\\} str;
f5daa3cdeb58 - Clear up old variable usage.
darius
parents: 1
diff changeset
273 regsub -all -- {\"} $str {\"} str;
f5daa3cdeb58 - Clear up old variable usage.
darius
parents: 1
diff changeset
274 # regsub -all -- {\'} $str {\'} str;
f5daa3cdeb58 - Clear up old variable usage.
darius
parents: 1
diff changeset
275 }
f5daa3cdeb58 - Clear up old variable usage.
darius
parents: 1
diff changeset
276
1
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
277 proc print_tracks {outtitle} {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
278 global tracks;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
279
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
280 puts "================================================================================";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
281 puts "$outtitle";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
282 puts "================================================================================";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
283 puts "Title: $tracks(albumname)"
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
284 if { $tracks(albumartist) != "" } {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
285 puts "Artist: $tracks(albumartist)";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
286 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
287 for { set t_no 1 } { $t_no <= $tracks(number) } { incr t_no } {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
288 puts [format "Track %d: %s - %s" $t_no $tracks(artist:$t_no) $tracks(title:$t_no)];
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
289 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
290
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
291 puts "================================================================================";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
292 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
293
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
294 main;