comparison get_cdinfo.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 74031379d3cb
children
comparison
equal deleted inserted replaced
8:2c01c09bdc0f 9:f3f2657296d2
1 #!/bin/sh 1 #!/bin/sh
2 # tcl magic \ 2 # tcl magic \
3 exec tclsh8.0 $0 $* 3 exec tclsh8.2 $0 $*
4 4
5 # 5 #
6 # This software is copyright Daniel O'Connor (darius@dons.net.au) 1998, 1999 6 # This software is copyright Daniel O'Connor (darius@dons.net.au) 1998, 1999
7 # 7 #
8 # This software is release under the GNU Public License Version 2. 8 # This software is release under the GNU Public License Version 2.
28 set wfh stdout; 28 set wfh stdout;
29 } else { 29 } else {
30 set wfh [ open $outfile "w" ]; 30 set wfh [ open $outfile "w" ];
31 } 31 }
32 32
33 set fh [ socket cddb.cddb.com 8880 ]; 33 # set fh [ socket cddb.cddb.com 8880 ];
34 if {[catch {set fh [socket freedb.freedb.org 888]} msg]} {
35 puts stderr "Unable to connect to CDDB - $msg";
36 puts stderr "Generating dummy file";
37 generate_dummy $wfh $discid $disclen $trackoffs ;
38 exit 0;
39 }
34 40
35 # Greeting from server 41 # Greeting from server
36 #puts [ gets $fh ]; 42 puts [ gets $fh ];
37 gets $fh; 43 #gets $fh;
38 44
39 puts $fh "CDDB HELLO [ exec id -u -n ] [ exec hostname ] TclMangler 0.1"; 45 puts $fh "CDDB HELLO [ exec id -u -n ] [ exec hostname ] TclMangler 0.1";
46 puts "CDDB HELLO [ exec id -u -n ] [ exec hostname ] TclMangler 0.1";
40 flush $fh 47 flush $fh
41 48
49 puts "Said hello"
50
42 # Hello message 51 # Hello message
43 #puts [ gets $fh ]; 52 # puts [ gets $fh ];
44 gets $fh; 53 gets $fh;
45 54
46 puts $fh "CDDB QUERY $discid [ llength $trackoffs ] $trackoffs $disclen" 55 puts $fh "CDDB QUERY $discid [ llength $trackoffs ] $trackoffs $disclen"
56 puts "CDDB QUERY $discid [ llength $trackoffs ] $trackoffs $disclen"
47 flush $fh 57 flush $fh
48 58
59 puts "Queried"
49 set line [ gets $fh ]; 60 set line [ gets $fh ];
61 puts "Got - $line"
50 if { [ regexp {([0-9][0-9][0-9]) (.*)} $line a rtn rest ] } { 62 if { [ regexp {([0-9][0-9][0-9]) (.*)} $line a rtn rest ] } {
51 switch -- $rtn { 63 switch -- $rtn {
52 "200" { 64 "200" {
53 if { [ regexp {([a-z]*) ([0-9a-f]*) (.*)} $rest a cat discid name ] } { 65 if { [ regexp {([a-z]*) ([0-9a-f]*) (.*)} $rest a cat discid name ] } {
54 puts stderr "Matched CD called $name in category $cat"; 66 puts stderr "Matched CD called $name in category $cat";
58 } 70 }
59 } 71 }
60 72
61 "202" { 73 "202" {
62 puts stderr "No such CD found.. generating dummy file"; 74 puts stderr "No such CD found.. generating dummy file";
63 puts $wfh "# xmcd CD database file 75 generate_dummy $wfh $discid $disclen $trackoffs ;
64 # Copyright (C) 1993-1999 CDDB, Inc.
65 #
66 # Track frame offsets:";
67 foreach t $trackoffs {
68 puts $wfh "#\t$t";
69 }
70 puts $wfh "#
71 # Disc length: $disclen seconds
72 #
73 # Revision: 1
74 # Submitted via: Tcl Mangler 0.1 - Copyright (c) 1999 Daniel O'Connor
75 #
76 DISCID=$discid
77 DTITLE=";
78 set i 0;
79 foreach t $trackoffs {
80 puts $wfh "TTITLE$i=";
81 incr i
82 }
83 76
77 puts "Wrote dummy";
84 exit; 78 exit;
85 } 79 }
86 80
87 "211" { 81 "211" {
88 set tot 0; 82 set tot 0;
108 puts stderr "No matches found for 210?"; 102 puts stderr "No matches found for 210?";
109 exit 1; 103 exit 1;
110 } 104 }
111 105
112 if { $tot == 1 } { 106 if { $tot == 1 } {
107 puts "Only 1 partial match";
113 set num 0; 108 set num 0;
114 } else { 109 } else {
115 puts stderr "Please enter the number which corresponds to the correct entry"; 110 puts stderr "Please enter the number which corresponds to the correct entry";
116 while { 1 } { 111 while { 1 } {
117 set num [ gets stdin ]; 112 set num [ gets stdin ];
164 } 159 }
165 160
166 close $fh; 161 close $fh;
167 } 162 }
168 163
164 proc generate_dummy {fh discid disclen trackoffs} {
165
166 puts $fh "# xmcd CD database file
167 # Copyright (C) 1993-1999 CDDB, Inc.
168 #
169 # Track frame offsets:";
170 foreach t $trackoffs {
171 puts $fh "#\t$t";
172 }
173
174 puts $fh "#
175 # Disc length: $disclen seconds
176 #
177 # Revision: 1
178 # Submitted via: Tcl Mangler 0.1 - Copyright (c) 1999 Daniel O'Connor
179 #
180 DISCID=$discid
181 DTITLE=";
182 set i 0;
183 foreach t $trackoffs {
184 puts $fh "TTITLE$i=";
185 incr i
186 }
187 }
188
169 main; 189 main;