Files
samskivert/projects/robodj/bin/mpcmd
T
mdb 7f70824e42 Fail if we can't connect to the music daemon and get the music daemon host
and port from the environment if they're in there.


git-svn-id: https://samskivert.googlecode.com/svn/trunk@112 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2001-03-22 03:00:25 +00:00

51 lines
1.2 KiB
Perl
Executable File

#!/usr/bin/perl -w
#
# $Id: mpcmd,v 1.2 2001/03/22 03:00:25 mdb Exp $
#
# Appends the supplied song or songs to the playlist of a running MP3
# daemon.
use strict;
use IO::Socket;
my $usage = "Usage: $0 COMMAND [ARGUMENT ...]\n";
my $command = shift or die $usage;
# determine our music daemon host and port
my $host = "localhost";
if (defined $ENV{"MUSICD_HOST"}) {
$host = $ENV{"MUSICD_HOST"};
}
my $port = 2500;
if (defined $ENV{"MUSICD_PORT"}) {
$port = $ENV{"MUSICD_PORT"};
}
# establish a socket connection with the server
my $sock = new IO::Socket::INET(PeerAddr => $host,
PeerPort => $port,
Proto => "tcp");
if (!defined $sock) {
die "Unable to connect to music server on $host:$port.\n";
}
# send the command
print $sock "$command " . join(" ", @ARGV) . "\n";
# PLAYLIST has a multiline response, others are single line
if ($command eq "PLAYLIST") {
my $rsp = <$sock>;
print $rsp;
if ($rsp =~ m/200 Playlist songs: (\d+)/) {
my $i;
for ($i = 0; $i < $1; $i++) {
print scalar <$sock>;
}
}
} else {
print scalar <$sock>;
}
close $sock;