annotate cddb2.tcl @ 9:f3f2657296d2

Use Tcl 8.2 Catch socket errors. Create separate dummy file generation proc.
author darius
date Thu, 18 Jul 2002 06:37:12 +0000
parents 2c01c09bdc0f
children
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" {
8
2c01c09bdc0f Handle "artist - title" as well as "artist / title".
darius
parents: 6
diff changeset
115 puts "Searching title - $value";
2c01c09bdc0f Handle "artist - title" as well as "artist / title".
darius
parents: 6
diff changeset
116 if {![regexp {^(.*) / (.*)$} $value a tracks(albumartist) tracks(albumname)]} {
2c01c09bdc0f Handle "artist - title" as well as "artist / title".
darius
parents: 6
diff changeset
117 if {![regexp {^(.*) - (.*)$} $value a tracks(albumartist) tracks(albumname)]} {
2c01c09bdc0f Handle "artist - title" as well as "artist / title".
darius
parents: 6
diff changeset
118 set tracks(albumname) $value;
2c01c09bdc0f Handle "artist - title" as well as "artist / title".
darius
parents: 6
diff changeset
119 }
1
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
120 }
8
2c01c09bdc0f Handle "artist - title" as well as "artist / title".
darius
parents: 6
diff changeset
121 puts "Artist - $tracks(albumartist)";
6
f5daa3cdeb58 - Clear up old variable usage.
darius
parents: 1
diff changeset
122 puts "Title - $tracks(albumname)";
1
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
123 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
124
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
125 "TTITLE([0-9]+)" {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
126 regexp {TTITLE([0-9]+)} $key a t_no;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
127 set t_no [ expr $t_no + 1 ];
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
128
6
f5daa3cdeb58 - Clear up old variable usage.
darius
parents: 1
diff changeset
129 if {[info exists tracks(title:$t_no)]} {
f5daa3cdeb58 - Clear up old variable usage.
darius
parents: 1
diff changeset
130 append tracks(title:$t_no) $value;
f5daa3cdeb58 - Clear up old variable usage.
darius
parents: 1
diff changeset
131 } else {
f5daa3cdeb58 - Clear up old variable usage.
darius
parents: 1
diff changeset
132 incr tracks(number);
f5daa3cdeb58 - Clear up old variable usage.
darius
parents: 1
diff changeset
133
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 if {![regexp {^(.*)--(.*)$} $value a tracks(artist:$t_no) tracks(title:$t_no)] == 1} {
f5daa3cdeb58 - Clear up old variable usage.
darius
parents: 1
diff changeset
136 if {![regexp {^(.*) / (.*)$} $value a tracks(artist:$t_no) tracks(title:$t_no)] == 1} {
f5daa3cdeb58 - Clear up old variable usage.
darius
parents: 1
diff changeset
137 set tracks(title:$t_no) $value;
f5daa3cdeb58 - Clear up old variable usage.
darius
parents: 1
diff changeset
138 }
f5daa3cdeb58 - Clear up old variable usage.
darius
parents: 1
diff changeset
139 }
1
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
140 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
141 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
142 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
143
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
144 "EXTT([0-9]+)" {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
145 regexp {EXTT([0-9]+)} $key a t_no;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
146 set t_no [ expr $t_no + 1 ];
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
147 set ext($t_no) $value;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
148 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
149 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
150 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
151
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
152 # puts "Offset list - $offset_list";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
153 # puts "Disclength - $tracks(disclen)";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
154
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
155 if {$tracks(number) < 1 || [llength $offset_list] != $tracks(number)} {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
156 puts stderr "Invalid file, $tracks(number)";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
157 exit 1;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
158 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
159
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
160 set i 1;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
161 foreach t $offset_list {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
162 set tracks(offset:$i) $t;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
163 incr i;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
164 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
165
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
166 for {set i 1} {$i <= $tracks(number)} {incr i} {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
167 if {![info exists tracks(title:$i)]} {
6
f5daa3cdeb58 - Clear up old variable usage.
darius
parents: 1
diff changeset
168 # error "track $i has no title!";
f5daa3cdeb58 - Clear up old variable usage.
darius
parents: 1
diff changeset
169 set tracks(title:$i) "";
1
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 {[info exists tracks(artist:$i)]} {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
173 # puts "artist exists for $i";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
174 continue;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
175 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
176
6
f5daa3cdeb58 - Clear up old variable usage.
darius
parents: 1
diff changeset
177 if {$tracks(albumartist) != ""} {
1
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
178 set tracks(artist:$i) $tracks(albumartist);
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
179 continue;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
180 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
181
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
182 if {[info exists ext($i)] && $ext($i) != ""} {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
183 set tracks(artist:$i) $ext($i);
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
184 # puts "setting artist to $ext($i) for $i";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
185 continue;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
186 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
187
8
2c01c09bdc0f Handle "artist - title" as well as "artist / title".
darius
parents: 6
diff changeset
188 set tracks(artist:$i) "";
1
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
189 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
190
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
191 # puts "$tracks(number) tracks";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
192
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
193 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
194
6
f5daa3cdeb58 - Clear up old variable usage.
darius
parents: 1
diff changeset
195 if {$tracks(albumartist) == ""} {
f5daa3cdeb58 - Clear up old variable usage.
darius
parents: 1
diff changeset
196 set tracks(albumartist) "Various Artists";
f5daa3cdeb58 - Clear up old variable usage.
darius
parents: 1
diff changeset
197 }
f5daa3cdeb58 - Clear up old variable usage.
darius
parents: 1
diff changeset
198
1
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
199 print_tracks "Before editing";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
200 set tracks(updated) 0;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
201 edit_tracks;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
202 print_tracks "After editing";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
203
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
204 if {$tracks(updated) == 0} {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
205 puts "Nothing saved aborting";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
206 puts "";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
207 exit 0;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
208 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
209
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
210 set out [ open $shellfile "w" ];
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
211
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
212 if { [ catch {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
213 if {$infile == "-"} {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
214 set fh stdout;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
215 } else {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
216 file rename -force "$infile" "$infile.old"
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
217 set fh [ open "$infile" "w" ];
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
218 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
219
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
220 puts $fh "# xmcd CD database file
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
221 # Copyright (C) 1993-1999 CDDB, Inc.
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
222 #
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
223 # Track frame offsets:";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
224 for { set i 1 } { $i <= $tracks(number) } { incr i } {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
225 puts $fh "#\t$tracks(offset:$i)"
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
226 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
227 puts $fh "#
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
228 # Disc length: $tracks(disclen) seconds
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
229 #
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
230 # Revision: 1
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
231 # Submitted via: Tcl Mangler 0.1 - Copyright (c) 1999 Daniel O'Connor
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
232 #
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
233 DISCID=$tracks(discid)
6
f5daa3cdeb58 - Clear up old variable usage.
darius
parents: 1
diff changeset
234 DTITLE=$tracks(albumartist) - $tracks(albumname)";
1
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
235 for { set i 1 } { $i <= $tracks(number) } { incr i } {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
236 puts $fh "TTITLE[expr $i - 1]=$tracks(artist:$i) - $tracks(title:$i)";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
237 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
238 } msg ] } {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
239 puts "Failed to write $infile, $msg";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
240 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
241
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
242 # Eat illegal characters
6
f5daa3cdeb58 - Clear up old variable usage.
darius
parents: 1
diff changeset
243 quoter tracks(albumname);
f5daa3cdeb58 - Clear up old variable usage.
darius
parents: 1
diff changeset
244 quoter tracks(albumartist);
f5daa3cdeb58 - Clear up old variable usage.
darius
parents: 1
diff changeset
245 set dirname "$tracks(albumartist) - $tracks(albumname)";
1
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
246
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
247 puts $out "mkdir \"$dirname\"";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
248 for { set t_no 1 } { $t_no <= $tracks(number) } { incr t_no } {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
249 # Eat illegal characters
6
f5daa3cdeb58 - Clear up old variable usage.
darius
parents: 1
diff changeset
250 quoter tracks(artist:$t_no);
f5daa3cdeb58 - Clear up old variable usage.
darius
parents: 1
diff changeset
251 quoter tracks(title:$t_no);
f5daa3cdeb58 - Clear up old variable usage.
darius
parents: 1
diff changeset
252
1
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
253 set oldname [ eval format {$oldbasename} {$t_no} ];
8
2c01c09bdc0f Handle "artist - title" as well as "artist / title".
darius
parents: 6
diff changeset
254 set newname [ eval format {$newbasename} {"[format %02d $t_no] $tracks(artist:$t_no) - $tracks(title:$t_no)"} ];
1
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
255
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
256 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
257 puts $out "mv \"$oldname\" \"$dirname/$newname\"";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
258 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
259
8
2c01c09bdc0f Handle "artist - title" as well as "artist / title".
darius
parents: 6
diff changeset
260 if {$infile != "-"} {
2c01c09bdc0f Handle "artist - title" as well as "artist / title".
darius
parents: 6
diff changeset
261 puts $out "mv \"$infile\" \"$dirname\"";
2c01c09bdc0f Handle "artist - title" as well as "artist / title".
darius
parents: 6
diff changeset
262 }
1
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
263 if {[catch {close $out} msg]} {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
264 puts "Got $msg closing renamer";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
265 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
266
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
267 if {[info exists fh]} {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
268 if {[catch {close $fh} msg]} {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
269 puts "Got $msg closing fh";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
270 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
271 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
272 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
273
6
f5daa3cdeb58 - Clear up old variable usage.
darius
parents: 1
diff changeset
274 proc quoter {str_var} {
f5daa3cdeb58 - Clear up old variable usage.
darius
parents: 1
diff changeset
275 upvar $str_var str;
f5daa3cdeb58 - Clear up old variable usage.
darius
parents: 1
diff changeset
276
f5daa3cdeb58 - Clear up old variable usage.
darius
parents: 1
diff changeset
277 regsub -all -- {/} $str {\\} str;
f5daa3cdeb58 - Clear up old variable usage.
darius
parents: 1
diff changeset
278 regsub -all -- {\"} $str {\"} str;
f5daa3cdeb58 - Clear up old variable usage.
darius
parents: 1
diff changeset
279 # regsub -all -- {\'} $str {\'} str;
f5daa3cdeb58 - Clear up old variable usage.
darius
parents: 1
diff changeset
280 }
f5daa3cdeb58 - Clear up old variable usage.
darius
parents: 1
diff changeset
281
1
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
282 proc print_tracks {outtitle} {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
283 global tracks;
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
284
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
285 puts "================================================================================";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
286 puts "$outtitle";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
287 puts "================================================================================";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
288 puts "Title: $tracks(albumname)"
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
289 if { $tracks(albumartist) != "" } {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
290 puts "Artist: $tracks(albumartist)";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
291 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
292 for { set t_no 1 } { $t_no <= $tracks(number) } { incr t_no } {
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
293 puts [format "Track %d: %s - %s" $t_no $tracks(artist:$t_no) $tracks(title:$t_no)];
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
294 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
295
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
296 puts "================================================================================";
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
297 }
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
298
dd6e30f7eb42 Initial revision
darius
parents:
diff changeset
299 main;