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 |
# Purposes: |
15 |
# - Trigger "Rip CD" from remote |
16 |
# - Poll for "Rip Status" |
17 |
|
18 |
use strict; |
19 |
use warnings; |
20 |
|
21 |
use Data::Dumper; |
22 |
use gdclient; |
23 |
|
24 |
my $action = shift; |
25 |
my $hostname = 'siggi'; |
26 |
|
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 |
gd_connect($hostname); |
46 |
|
47 |
# 1. check if cd is already in database (probably ripped?) |
48 |
if (my $check_cd = gd_command("chcd", undef, 1)) { |
49 |
print "-" x 60, "\n"; |
50 |
print "CD already ripped:", "\n", $check_cd, "\n"; |
51 |
print "-" x 60, "\n"; |
52 |
} |
53 |
|
54 |
# TODO: parse $check_cd and propagate cddb-id to "lcddi", if desired |
55 |
|
56 |
# 2. get cd information |
57 |
my $cdinfo_raw = gd_command("lcddi", undef, 1); |
58 |
my $cdinfo = lcddi_parse_response($cdinfo_raw); |
59 |
#print Dumper($cdinfo); |
60 |
#return; |
61 |
|
62 |
if (!$cdinfo->{'cddb_id'}) { |
63 |
print "ERROR: CDDB id is undefined.", "\n"; |
64 |
print "Check if your database table 'album' contains an entry like: '- - NULL NULL 2005-03-08 NULL'", "\n"; |
65 |
return; |
66 |
} |
67 |
|
68 |
# 3. insert album information to database and rip cd |
69 |
gd_command("cspcd"); |
70 |
#return; |
71 |
|
72 |
my $album_args = [ $cdinfo->{'artist'}, $cdinfo->{'album'}, $cdinfo->{'cddb_id'} ]; |
73 |
#print Dumper($album_args); |
74 |
gd_command("repar", $album_args); |
75 |
#return; |
76 |
|
77 |
foreach my $track_args (@{$cdinfo->{'tracks'}}) { |
78 |
#print join(" ", @$track_args), "\n"; |
79 |
gd_command("reccdt", $track_args); |
80 |
} |
81 |
|
82 |
print "Sent rip command to GiantDisc...", "\n"; |
83 |
print "Check job-status with 'gdc.pl ripstatus'.", "\n"; |
84 |
|
85 |
gd_disconnect(); |
86 |
} |
87 |
|
88 |
sub ripstatus { |
89 |
gd_connect($hostname); |
90 |
|
91 |
while (1) { |
92 |
my $status_rip = gd_command("grpst", undef, 1); |
93 |
print "-" x 40, "\n"; |
94 |
print "Rip Status:", "\n"; |
95 |
print $status_rip, "\n"; |
96 |
|
97 |
print "-" x 40, "\n"; |
98 |
my $status_compress = gd_command("gcpst", undef, 1); |
99 |
print "Compress Status:", "\n"; |
100 |
print $status_compress, "\n"; |
101 |
print "\n"; |
102 |
|
103 |
sleep 5; |
104 |
} |
105 |
|
106 |
gd_disconnect(); |
107 |
} |
108 |
|
109 |
############################################################################### |