| 1 | joko | 1.1 | #!/usr/bin/perl | 
| 2 |  |  |  | 
| 3 |  |  | ################################################## | 
| 4 |  |  | # | 
| 5 |  |  | # GiantDisc mp3 Jukebox Client | 
| 6 |  |  | # | 
| 7 |  |  | #  2005, Andreas Motl | 
| 8 |  |  | # | 
| 9 |  |  | ################################################## | 
| 10 |  |  |  | 
| 11 |  |  |  | 
| 12 |  |  | # Client script talking to GiantDisc TCP port. | 
| 13 |  |  | # | 
| 14 | joko | 1.2 | # Purposes: | 
| 15 |  |  | #   - Trigger "Rip CD" from remote | 
| 16 |  |  | #   - Poll for "Rip Status" | 
| 17 | joko | 1.1 |  | 
| 18 |  |  | use strict; | 
| 19 |  |  | use warnings; | 
| 20 |  |  |  | 
| 21 | joko | 1.2 | use Data::Dumper; | 
| 22 | joko | 1.1 | use gdclient; | 
| 23 | joko | 1.2 |  | 
| 24 |  |  | my $action = shift; | 
| 25 | joko | 1.3 | my $hostname = 'siggi'; | 
| 26 | joko | 1.2 |  | 
| 27 |  |  | sub usage { | 
| 28 |  |  | print "Usage: gdc.pl ripcd|ripstatus", "\n"; | 
| 29 |  |  | } | 
| 30 |  |  |  | 
| 31 |  |  | if (!$action) { | 
| 32 |  |  | usage(); | 
| 33 |  |  | exit; | 
| 34 |  |  | } elsif ($action eq 'ripcd') { | 
| 35 |  |  | ripcd(); | 
| 36 |  |  | } elsif ($action eq 'ripstatus') { | 
| 37 |  |  | ripstatus(); | 
| 38 |  |  | } else { | 
| 39 |  |  | usage(); | 
| 40 |  |  | exit; | 
| 41 |  |  | } | 
| 42 |  |  |  | 
| 43 |  |  |  | 
| 44 |  |  | sub ripcd { | 
| 45 | joko | 1.3 | gd_connect($hostname); | 
| 46 | joko | 1.2 |  | 
| 47 |  |  | # 1. check if cd is already in database (probably ripped?) | 
| 48 | joko | 1.4 | print "-" x 60, "\n"; | 
| 49 |  |  | print "Check CD: "; | 
| 50 |  |  | my $check_cd; | 
| 51 |  |  | if ($check_cd = gd_command("chcd", undef, 1)) { | 
| 52 |  |  | print "CD already ripped!"; | 
| 53 | joko | 1.2 | } | 
| 54 | joko | 1.4 | print "\n"; | 
| 55 |  |  | print $check_cd, "\n"; | 
| 56 |  |  | print "-" x 60, "\n"; | 
| 57 | joko | 1.2 |  | 
| 58 |  |  | # TODO: parse $check_cd and propagate cddb-id to "lcddi", if desired | 
| 59 |  |  |  | 
| 60 |  |  | # 2. get cd information | 
| 61 |  |  | my $cdinfo_raw = gd_command("lcddi", undef, 1); | 
| 62 |  |  | my $cdinfo = lcddi_parse_response($cdinfo_raw); | 
| 63 |  |  | #print Dumper($cdinfo); | 
| 64 |  |  | #return; | 
| 65 |  |  |  | 
| 66 |  |  | if (!$cdinfo->{'cddb_id'}) { | 
| 67 |  |  | print "ERROR: CDDB id is undefined.", "\n"; | 
| 68 |  |  | print "Check if your database table 'album' contains an entry like: '-      -               NULL    NULL    2005-03-08      NULL'", "\n"; | 
| 69 |  |  | return; | 
| 70 |  |  | } | 
| 71 |  |  |  | 
| 72 |  |  | # 3. insert album information to database and rip cd | 
| 73 |  |  | gd_command("cspcd"); | 
| 74 |  |  | #return; | 
| 75 |  |  |  | 
| 76 |  |  | my $album_args = [ $cdinfo->{'artist'}, $cdinfo->{'album'}, $cdinfo->{'cddb_id'} ]; | 
| 77 |  |  | #print Dumper($album_args); | 
| 78 |  |  | gd_command("repar", $album_args); | 
| 79 |  |  | #return; | 
| 80 |  |  |  | 
| 81 |  |  | foreach my $track_args (@{$cdinfo->{'tracks'}}) { | 
| 82 |  |  | #print join(" ", @$track_args), "\n"; | 
| 83 |  |  | gd_command("reccdt", $track_args); | 
| 84 |  |  | } | 
| 85 |  |  |  | 
| 86 |  |  | print "Sent rip command to GiantDisc...", "\n"; | 
| 87 |  |  | print "Check job-status with 'gdc.pl ripstatus'.", "\n"; | 
| 88 |  |  |  | 
| 89 |  |  | gd_disconnect(); | 
| 90 |  |  | } | 
| 91 |  |  |  | 
| 92 |  |  | sub ripstatus { | 
| 93 | joko | 1.3 | gd_connect($hostname); | 
| 94 | joko | 1.2 |  | 
| 95 |  |  | while (1) { | 
| 96 |  |  | my $status_rip = gd_command("grpst", undef, 1); | 
| 97 |  |  | print "-" x 40, "\n"; | 
| 98 |  |  | print "Rip Status:", "\n"; | 
| 99 |  |  | print $status_rip, "\n"; | 
| 100 |  |  |  | 
| 101 |  |  | print "-" x 40, "\n"; | 
| 102 |  |  | my $status_compress = gd_command("gcpst", undef, 1); | 
| 103 |  |  | print "Compress Status:", "\n"; | 
| 104 |  |  | print $status_compress, "\n"; | 
| 105 |  |  | print "\n"; | 
| 106 |  |  |  | 
| 107 |  |  | sleep 5; | 
| 108 |  |  | } | 
| 109 |  |  |  | 
| 110 |  |  | gd_disconnect(); | 
| 111 |  |  | } | 
| 112 | joko | 1.1 |  | 
| 113 |  |  | ############################################################################### |