#!/usr/bin/perl -w
#
# $Id: append,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 mp3_file [mp3_file ...]\n";
my $path = 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";
}

do {
    # send the command
    print $sock "APPEND $path\n";
    # print the response
    print scalar <$sock>;
} while ($path = shift);

close $sock;
