--- nfo/perl/scripts/giantdisc/bin/gdc.pl 2005/03/08 16:00:57 1.1 +++ nfo/perl/scripts/giantdisc/bin/gdc.pl 2005/03/08 20:53:46 1.2 @@ -11,39 +11,98 @@ # Client script talking to GiantDisc TCP port. # -# Purpose: Trigger "Rip CD" from remote +# Purposes: +# - Trigger "Rip CD" from remote +# - Poll for "Rip Status" use strict; use warnings; -use Data::Dumper; +use Data::Dumper; use gdclient; - -my $payload = [ - 'Guano Apes', - 'Open Your Eyes', - '', - '', - '', - '', - '0', - '0', - '189', - '0', - '1e0c1f12', - '1', - '', - '0', - '0', - '', - '', - 'mp3 192' - ]; - - -gd_connect("siggi"); -gd_command("reccdt", @$payload); -gd_disconnect(); - + +my $action = shift; + +sub usage { + print "Usage: gdc.pl ripcd|ripstatus", "\n"; +} + +if (!$action) { + usage(); + exit; +} elsif ($action eq 'ripcd') { + ripcd(); +} elsif ($action eq 'ripstatus') { + ripstatus(); +} else { + usage(); + exit; +} + + +sub ripcd { + gd_connect("siggi"); + + # 1. check if cd is already in database (probably ripped?) + if (my $check_cd = gd_command("chcd", undef, 1)) { + print "-" x 60, "\n"; + print "CD already ripped:", "\n", $check_cd, "\n"; + print "-" x 60, "\n"; + } + + # TODO: parse $check_cd and propagate cddb-id to "lcddi", if desired + + # 2. get cd information + my $cdinfo_raw = gd_command("lcddi", undef, 1); + my $cdinfo = lcddi_parse_response($cdinfo_raw); + #print Dumper($cdinfo); + #return; + + if (!$cdinfo->{'cddb_id'}) { + print "ERROR: CDDB id is undefined.", "\n"; + print "Check if your database table 'album' contains an entry like: '- - NULL NULL 2005-03-08 NULL'", "\n"; + return; + } + + # 3. insert album information to database and rip cd + gd_command("cspcd"); + #return; + + my $album_args = [ $cdinfo->{'artist'}, $cdinfo->{'album'}, $cdinfo->{'cddb_id'} ]; + #print Dumper($album_args); + gd_command("repar", $album_args); + #return; + + foreach my $track_args (@{$cdinfo->{'tracks'}}) { + #print join(" ", @$track_args), "\n"; + gd_command("reccdt", $track_args); + } + + print "Sent rip command to GiantDisc...", "\n"; + print "Check job-status with 'gdc.pl ripstatus'.", "\n"; + + gd_disconnect(); +} + +sub ripstatus { + gd_connect("siggi"); + + while (1) { + my $status_rip = gd_command("grpst", undef, 1); + print "-" x 40, "\n"; + print "Rip Status:", "\n"; + print $status_rip, "\n"; + + print "-" x 40, "\n"; + my $status_compress = gd_command("gcpst", undef, 1); + print "Compress Status:", "\n"; + print $status_compress, "\n"; + print "\n"; + + sleep 5; + } + + gd_disconnect(); +} ###############################################################################