# HG changeset patch # User darius # Date 1026974232 0 # Node ID f3f2657296d2358921941a18a6df31089e5d5c60 # Parent 2c01c09bdc0f25f0303acf4f6bc3e12da60259a6 Use Tcl 8.2 Catch socket errors. Create separate dummy file generation proc. diff -r 2c01c09bdc0f -r f3f2657296d2 get_cdinfo.tcl --- a/get_cdinfo.tcl Thu Jul 18 06:33:52 2002 +0000 +++ b/get_cdinfo.tcl Thu Jul 18 06:37:12 2002 +0000 @@ -1,6 +1,6 @@ #!/bin/sh # tcl magic \ -exec tclsh8.0 $0 $* +exec tclsh8.2 $0 $* # # This software is copyright Daniel O'Connor (darius@dons.net.au) 1998, 1999 @@ -30,23 +30,35 @@ set wfh [ open $outfile "w" ]; } - set fh [ socket cddb.cddb.com 8880 ]; +# set fh [ socket cddb.cddb.com 8880 ]; + if {[catch {set fh [socket freedb.freedb.org 888]} msg]} { + puts stderr "Unable to connect to CDDB - $msg"; + puts stderr "Generating dummy file"; + generate_dummy $wfh $discid $disclen $trackoffs ; + exit 0; + } # Greeting from server - #puts [ gets $fh ]; - gets $fh; + puts [ gets $fh ]; + #gets $fh; puts $fh "CDDB HELLO [ exec id -u -n ] [ exec hostname ] TclMangler 0.1"; + puts "CDDB HELLO [ exec id -u -n ] [ exec hostname ] TclMangler 0.1"; flush $fh + puts "Said hello" + # Hello message - #puts [ gets $fh ]; +# puts [ gets $fh ]; gets $fh; puts $fh "CDDB QUERY $discid [ llength $trackoffs ] $trackoffs $disclen" + puts "CDDB QUERY $discid [ llength $trackoffs ] $trackoffs $disclen" flush $fh + puts "Queried" set line [ gets $fh ]; + puts "Got - $line" if { [ regexp {([0-9][0-9][0-9]) (.*)} $line a rtn rest ] } { switch -- $rtn { "200" { @@ -60,27 +72,9 @@ "202" { puts stderr "No such CD found.. generating dummy file"; - puts $wfh "# xmcd CD database file -# Copyright (C) 1993-1999 CDDB, Inc. -# -# Track frame offsets:"; - foreach t $trackoffs { - puts $wfh "#\t$t"; - } - puts $wfh "# -# Disc length: $disclen seconds -# -# Revision: 1 -# Submitted via: Tcl Mangler 0.1 - Copyright (c) 1999 Daniel O'Connor -# -DISCID=$discid -DTITLE="; - set i 0; - foreach t $trackoffs { - puts $wfh "TTITLE$i="; - incr i - } + generate_dummy $wfh $discid $disclen $trackoffs ; + puts "Wrote dummy"; exit; } @@ -110,6 +104,7 @@ } if { $tot == 1 } { + puts "Only 1 partial match"; set num 0; } else { puts stderr "Please enter the number which corresponds to the correct entry"; @@ -166,4 +161,29 @@ close $fh; } -main; \ No newline at end of file +proc generate_dummy {fh discid disclen trackoffs} { + + puts $fh "# xmcd CD database file +# Copyright (C) 1993-1999 CDDB, Inc. +# +# Track frame offsets:"; + foreach t $trackoffs { + puts $fh "#\t$t"; + } + + puts $fh "# +# Disc length: $disclen seconds +# +# Revision: 1 +# Submitted via: Tcl Mangler 0.1 - Copyright (c) 1999 Daniel O'Connor +# +DISCID=$discid +DTITLE="; + set i 0; + foreach t $trackoffs { + puts $fh "TTITLE$i="; + incr i + } +} + +main;