annotate get_cdinfo.tcl @ 5:cf06ab549064

Write files to mark our progress and skip doing tracks if we have already done them.
author darius
date Sat, 12 Aug 2000 07:11:06 +0000
parents 74031379d3cb
children f3f2657296d2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
74031379d3cb Initial revision
darius
parents:
diff changeset
1 #!/bin/sh
74031379d3cb Initial revision
darius
parents:
diff changeset
2 # tcl magic \
74031379d3cb Initial revision
darius
parents:
diff changeset
3 exec tclsh8.0 $0 $*
74031379d3cb Initial revision
darius
parents:
diff changeset
4
74031379d3cb Initial revision
darius
parents:
diff changeset
5 #
74031379d3cb Initial revision
darius
parents:
diff changeset
6 # This software is copyright Daniel O'Connor (darius@dons.net.au) 1998, 1999
74031379d3cb Initial revision
darius
parents:
diff changeset
7 #
74031379d3cb Initial revision
darius
parents:
diff changeset
8 # This software is release under the GNU Public License Version 2.
74031379d3cb Initial revision
darius
parents:
diff changeset
9 # A copy of this licence must be distributed with this software.
74031379d3cb Initial revision
darius
parents:
diff changeset
10 #
74031379d3cb Initial revision
darius
parents:
diff changeset
11
74031379d3cb Initial revision
darius
parents:
diff changeset
12 proc main {} {
74031379d3cb Initial revision
darius
parents:
diff changeset
13 global argv0 argv tracks auto_path;
74031379d3cb Initial revision
darius
parents:
diff changeset
14
74031379d3cb Initial revision
darius
parents:
diff changeset
15 lappend auto_path ".";
74031379d3cb Initial revision
darius
parents:
diff changeset
16
74031379d3cb Initial revision
darius
parents:
diff changeset
17 if { [ llength $argv ] < 4 } {
74031379d3cb Initial revision
darius
parents:
diff changeset
18 puts stderr "Bad usage";
74031379d3cb Initial revision
darius
parents:
diff changeset
19 puts stderr "$argv0 <outfile> <discid> \[ <tracks> ... \] <disclen>";
74031379d3cb Initial revision
darius
parents:
diff changeset
20 exit 1;
74031379d3cb Initial revision
darius
parents:
diff changeset
21 }
74031379d3cb Initial revision
darius
parents:
diff changeset
22 set outfile [ lindex $argv 0 ];
74031379d3cb Initial revision
darius
parents:
diff changeset
23 set discid [ lindex $argv 1 ];
74031379d3cb Initial revision
darius
parents:
diff changeset
24 set trackoffs [ lrange $argv 2 [ expr [ llength $argv ] - 2 ] ];
74031379d3cb Initial revision
darius
parents:
diff changeset
25 set disclen [ lindex $argv end ];
74031379d3cb Initial revision
darius
parents:
diff changeset
26
74031379d3cb Initial revision
darius
parents:
diff changeset
27 if { $outfile == "-" } {
74031379d3cb Initial revision
darius
parents:
diff changeset
28 set wfh stdout;
74031379d3cb Initial revision
darius
parents:
diff changeset
29 } else {
74031379d3cb Initial revision
darius
parents:
diff changeset
30 set wfh [ open $outfile "w" ];
74031379d3cb Initial revision
darius
parents:
diff changeset
31 }
74031379d3cb Initial revision
darius
parents:
diff changeset
32
74031379d3cb Initial revision
darius
parents:
diff changeset
33 set fh [ socket cddb.cddb.com 8880 ];
74031379d3cb Initial revision
darius
parents:
diff changeset
34
74031379d3cb Initial revision
darius
parents:
diff changeset
35 # Greeting from server
74031379d3cb Initial revision
darius
parents:
diff changeset
36 #puts [ gets $fh ];
74031379d3cb Initial revision
darius
parents:
diff changeset
37 gets $fh;
74031379d3cb Initial revision
darius
parents:
diff changeset
38
74031379d3cb Initial revision
darius
parents:
diff changeset
39 puts $fh "CDDB HELLO [ exec id -u -n ] [ exec hostname ] TclMangler 0.1";
74031379d3cb Initial revision
darius
parents:
diff changeset
40 flush $fh
74031379d3cb Initial revision
darius
parents:
diff changeset
41
74031379d3cb Initial revision
darius
parents:
diff changeset
42 # Hello message
74031379d3cb Initial revision
darius
parents:
diff changeset
43 #puts [ gets $fh ];
74031379d3cb Initial revision
darius
parents:
diff changeset
44 gets $fh;
74031379d3cb Initial revision
darius
parents:
diff changeset
45
74031379d3cb Initial revision
darius
parents:
diff changeset
46 puts $fh "CDDB QUERY $discid [ llength $trackoffs ] $trackoffs $disclen"
74031379d3cb Initial revision
darius
parents:
diff changeset
47 flush $fh
74031379d3cb Initial revision
darius
parents:
diff changeset
48
74031379d3cb Initial revision
darius
parents:
diff changeset
49 set line [ gets $fh ];
74031379d3cb Initial revision
darius
parents:
diff changeset
50 if { [ regexp {([0-9][0-9][0-9]) (.*)} $line a rtn rest ] } {
74031379d3cb Initial revision
darius
parents:
diff changeset
51 switch -- $rtn {
74031379d3cb Initial revision
darius
parents:
diff changeset
52 "200" {
74031379d3cb Initial revision
darius
parents:
diff changeset
53 if { [ regexp {([a-z]*) ([0-9a-f]*) (.*)} $rest a cat discid name ] } {
74031379d3cb Initial revision
darius
parents:
diff changeset
54 puts stderr "Matched CD called $name in category $cat";
74031379d3cb Initial revision
darius
parents:
diff changeset
55 } else {
74031379d3cb Initial revision
darius
parents:
diff changeset
56 puts stderr "Couldn't parse line with code 200 '$rest'";
74031379d3cb Initial revision
darius
parents:
diff changeset
57 exit 1;
74031379d3cb Initial revision
darius
parents:
diff changeset
58 }
74031379d3cb Initial revision
darius
parents:
diff changeset
59 }
74031379d3cb Initial revision
darius
parents:
diff changeset
60
74031379d3cb Initial revision
darius
parents:
diff changeset
61 "202" {
74031379d3cb Initial revision
darius
parents:
diff changeset
62 puts stderr "No such CD found.. generating dummy file";
74031379d3cb Initial revision
darius
parents:
diff changeset
63 puts $wfh "# xmcd CD database file
74031379d3cb Initial revision
darius
parents:
diff changeset
64 # Copyright (C) 1993-1999 CDDB, Inc.
74031379d3cb Initial revision
darius
parents:
diff changeset
65 #
74031379d3cb Initial revision
darius
parents:
diff changeset
66 # Track frame offsets:";
74031379d3cb Initial revision
darius
parents:
diff changeset
67 foreach t $trackoffs {
74031379d3cb Initial revision
darius
parents:
diff changeset
68 puts $wfh "#\t$t";
74031379d3cb Initial revision
darius
parents:
diff changeset
69 }
74031379d3cb Initial revision
darius
parents:
diff changeset
70 puts $wfh "#
74031379d3cb Initial revision
darius
parents:
diff changeset
71 # Disc length: $disclen seconds
74031379d3cb Initial revision
darius
parents:
diff changeset
72 #
74031379d3cb Initial revision
darius
parents:
diff changeset
73 # Revision: 1
74031379d3cb Initial revision
darius
parents:
diff changeset
74 # Submitted via: Tcl Mangler 0.1 - Copyright (c) 1999 Daniel O'Connor
74031379d3cb Initial revision
darius
parents:
diff changeset
75 #
74031379d3cb Initial revision
darius
parents:
diff changeset
76 DISCID=$discid
74031379d3cb Initial revision
darius
parents:
diff changeset
77 DTITLE=";
74031379d3cb Initial revision
darius
parents:
diff changeset
78 set i 0;
74031379d3cb Initial revision
darius
parents:
diff changeset
79 foreach t $trackoffs {
74031379d3cb Initial revision
darius
parents:
diff changeset
80 puts $wfh "TTITLE$i=";
74031379d3cb Initial revision
darius
parents:
diff changeset
81 incr i
74031379d3cb Initial revision
darius
parents:
diff changeset
82 }
74031379d3cb Initial revision
darius
parents:
diff changeset
83
74031379d3cb Initial revision
darius
parents:
diff changeset
84 exit;
74031379d3cb Initial revision
darius
parents:
diff changeset
85 }
74031379d3cb Initial revision
darius
parents:
diff changeset
86
74031379d3cb Initial revision
darius
parents:
diff changeset
87 "211" {
74031379d3cb Initial revision
darius
parents:
diff changeset
88 set tot 0;
74031379d3cb Initial revision
darius
parents:
diff changeset
89 set matches "";
74031379d3cb Initial revision
darius
parents:
diff changeset
90
74031379d3cb Initial revision
darius
parents:
diff changeset
91 while { 1 } {
74031379d3cb Initial revision
darius
parents:
diff changeset
92 set line [ gets $fh ];
74031379d3cb Initial revision
darius
parents:
diff changeset
93 if { $line == "." } {
74031379d3cb Initial revision
darius
parents:
diff changeset
94 break;
74031379d3cb Initial revision
darius
parents:
diff changeset
95 }
74031379d3cb Initial revision
darius
parents:
diff changeset
96
74031379d3cb Initial revision
darius
parents:
diff changeset
97 if { [ regexp {^([a-z]*) ([0-9a-f]*) (.*)} $line a cat discid name ] } {
74031379d3cb Initial revision
darius
parents:
diff changeset
98 puts stderr "[ expr $tot + 1 ]) Matched CD called $name in category $cat";
74031379d3cb Initial revision
darius
parents:
diff changeset
99 lappend matches [ list $cat $discid $name ];
74031379d3cb Initial revision
darius
parents:
diff changeset
100 incr tot;
74031379d3cb Initial revision
darius
parents:
diff changeset
101 } else {
74031379d3cb Initial revision
darius
parents:
diff changeset
102 puts stderr "Couldn't parse line after code 210 - '$line'";
74031379d3cb Initial revision
darius
parents:
diff changeset
103 exit 1;
74031379d3cb Initial revision
darius
parents:
diff changeset
104 }
74031379d3cb Initial revision
darius
parents:
diff changeset
105 }
74031379d3cb Initial revision
darius
parents:
diff changeset
106
74031379d3cb Initial revision
darius
parents:
diff changeset
107 if { $tot == 0 } {
74031379d3cb Initial revision
darius
parents:
diff changeset
108 puts stderr "No matches found for 210?";
74031379d3cb Initial revision
darius
parents:
diff changeset
109 exit 1;
74031379d3cb Initial revision
darius
parents:
diff changeset
110 }
74031379d3cb Initial revision
darius
parents:
diff changeset
111
74031379d3cb Initial revision
darius
parents:
diff changeset
112 if { $tot == 1 } {
74031379d3cb Initial revision
darius
parents:
diff changeset
113 set num 0;
74031379d3cb Initial revision
darius
parents:
diff changeset
114 } else {
74031379d3cb Initial revision
darius
parents:
diff changeset
115 puts stderr "Please enter the number which corresponds to the correct entry";
74031379d3cb Initial revision
darius
parents:
diff changeset
116 while { 1 } {
74031379d3cb Initial revision
darius
parents:
diff changeset
117 set num [ gets stdin ];
74031379d3cb Initial revision
darius
parents:
diff changeset
118 if { ($num >= 1) && ($num <= $tot ) } {
74031379d3cb Initial revision
darius
parents:
diff changeset
119 break;
74031379d3cb Initial revision
darius
parents:
diff changeset
120 }
74031379d3cb Initial revision
darius
parents:
diff changeset
121 puts stderr "Sorry, that number is invalid, please try again";
74031379d3cb Initial revision
darius
parents:
diff changeset
122 }
74031379d3cb Initial revision
darius
parents:
diff changeset
123
74031379d3cb Initial revision
darius
parents:
diff changeset
124 set cat [ lindex [ lindex $matches [ expr $num - 1 ] ] 0 ];
74031379d3cb Initial revision
darius
parents:
diff changeset
125 set discid [ lindex [ lindex $matches [ expr $num - 1 ] ] 1 ];
74031379d3cb Initial revision
darius
parents:
diff changeset
126 set name [ lindex [ lindex $matches [ expr $num - 1 ] ] 2 ];
74031379d3cb Initial revision
darius
parents:
diff changeset
127 }
74031379d3cb Initial revision
darius
parents:
diff changeset
128 }
74031379d3cb Initial revision
darius
parents:
diff changeset
129
74031379d3cb Initial revision
darius
parents:
diff changeset
130 "501" {
74031379d3cb Initial revision
darius
parents:
diff changeset
131 puts stderr"Invalid disc ID $discid";
74031379d3cb Initial revision
darius
parents:
diff changeset
132 exit 1;
74031379d3cb Initial revision
darius
parents:
diff changeset
133 }
74031379d3cb Initial revision
darius
parents:
diff changeset
134
74031379d3cb Initial revision
darius
parents:
diff changeset
135 default {
74031379d3cb Initial revision
darius
parents:
diff changeset
136 puts stderr "Couldn't parse '$line'";
74031379d3cb Initial revision
darius
parents:
diff changeset
137 exit 1;
74031379d3cb Initial revision
darius
parents:
diff changeset
138 }
74031379d3cb Initial revision
darius
parents:
diff changeset
139 }
74031379d3cb Initial revision
darius
parents:
diff changeset
140 }
74031379d3cb Initial revision
darius
parents:
diff changeset
141
74031379d3cb Initial revision
darius
parents:
diff changeset
142 puts $fh "CDDB READ $cat $discid"
74031379d3cb Initial revision
darius
parents:
diff changeset
143 flush $fh
74031379d3cb Initial revision
darius
parents:
diff changeset
144
74031379d3cb Initial revision
darius
parents:
diff changeset
145 gets $fh line;
74031379d3cb Initial revision
darius
parents:
diff changeset
146
74031379d3cb Initial revision
darius
parents:
diff changeset
147 if { [ regexp {([0-9][0-9][0-9]) (.*)} $line a rtn rest ] } {
74031379d3cb Initial revision
darius
parents:
diff changeset
148 if { $rtn != "210" } {
74031379d3cb Initial revision
darius
parents:
diff changeset
149 puts stderr "Bad error from CDDB READ command ($line)"
74031379d3cb Initial revision
darius
parents:
diff changeset
150 exit 1;
74031379d3cb Initial revision
darius
parents:
diff changeset
151 }
74031379d3cb Initial revision
darius
parents:
diff changeset
152 } else {
74031379d3cb Initial revision
darius
parents:
diff changeset
153 puts stderr "Couldn't parse $line";
74031379d3cb Initial revision
darius
parents:
diff changeset
154 exit 1;
74031379d3cb Initial revision
darius
parents:
diff changeset
155 }
74031379d3cb Initial revision
darius
parents:
diff changeset
156
74031379d3cb Initial revision
darius
parents:
diff changeset
157 while { 1 } {
74031379d3cb Initial revision
darius
parents:
diff changeset
158 set line [ gets $fh ];
74031379d3cb Initial revision
darius
parents:
diff changeset
159 if { $line == "." } {
74031379d3cb Initial revision
darius
parents:
diff changeset
160 break;
74031379d3cb Initial revision
darius
parents:
diff changeset
161 }
74031379d3cb Initial revision
darius
parents:
diff changeset
162
74031379d3cb Initial revision
darius
parents:
diff changeset
163 puts $wfh $line;
74031379d3cb Initial revision
darius
parents:
diff changeset
164 }
74031379d3cb Initial revision
darius
parents:
diff changeset
165
74031379d3cb Initial revision
darius
parents:
diff changeset
166 close $fh;
74031379d3cb Initial revision
darius
parents:
diff changeset
167 }
74031379d3cb Initial revision
darius
parents:
diff changeset
168
74031379d3cb Initial revision
darius
parents:
diff changeset
169 main;