#!/usr/bin/perl -wT use CGI qw(:all); use LWP::Simple qw(get); use strict; print header; my $song = param('song'); my $directory = "insert_directory_here"; my $historylength = 5; my $pass = "pass"; my $url = ""; my $result = ""; my $songentry = $directory . $song; #get the current position of the playing song 0=first song, 1=second song, etc $url = "http://localhost:4800/getlistpos?p=$pass"; $result = get($url); if ( $result > $historylength ) { my $numbertotrim = ( $result - $historylength ); for ( my $i = 1 ; $i == $numbertotrim ; $i++ ) { $url = "http://localhost:4800/deletepos?p=$pass&index=0"; $result = get($url); if ( $result != 1 ) { $i = $numbertotrim; } } } # Change the working directory for sanity $url = "http://localhost:4800/chdir?p=$pass&dir=\"insert_directory_here\""; $result = get($url); if ( $result == 0 ) { &htmlsub("There was an error handling your request."); } # Load the list $url = "http://localhost:4800/getplaylistfile?p=$pass&delim=;"; $result = get($url); if ( $result eq 0 ) { &htmlsub("There was an error handling your request."); } else { my @songs = split( ';', $result ); my $playlistentry = ""; foreach $playlistentry (@songs) { if ( $songentry eq $playlistentry ) { &htmlsub("That song is already in the playlist."); } } } #queue it up, if there are no precedents $url = "http://localhost:4800/playfile?p=$pass&file=" . $songentry; $result = get($url); if ( $result == 0 ) { &htmlsub("There was an error handling your request."); } else { # report success/failure to queue, possibly name the place it is queued in? &htmlsub("The song you requested has been queued."); } sub htmlsub { # this is where you format the HTML print $_[0]; print "
"; exit(0); }