#!/usr/bin/perl -w # $RedRiver: addmp3playlist.pl,v 1.2 2006/08/12 00:14:53 andrew Exp $ ######################################################################## # addmp3playlist.pl *** Adds MP3's to the playlist # # 04-13-00 # Written by andrew fresh ######################################################################## use strict; use diagnostics; ######################################################################## # *** Variables *** my $DestDir = '/home/mp3/Sorted'; ######################################################################## # *** MAIN *** ######################################################################## if (! -d $DestDir) { mkdir $DestDir, 0777 } my ($prefix, $filename, $playlist) = split /\&/, $ENV{'QUERY_STRING'}; if ($filename) { $filename =~ s/%(..)/pack("c",hex($1))/ge; } else { $filename =''; } if ($playlist) { $playlist =~ s/%(..)/pack("c",hex($1))/ge; } else { $playlist ='playlist.lst'; } if ($prefix) { $prefix =~ s/%(..)/pack("c",hex($1))/ge; } else { $prefix =''; } my $playlist = '/var/www/mp3/playlist/' . $prefix . $playlist; print "Content-Type: text/html\n\n"; if ($filename) { print "\n\n\t"; if ($ENV{'QUERY_STRING'}) { print ""; } print "Added $filename\n\n\n"; print "

Added $filename

\n"; open PLAYLIST, ">>$playlist" or bail("unable to open PLAYLIST: $!"); print PLAYLIST "$filename\n"; close PLAYLIST or bail("unable to close PLAYLIST: $!"); } else { print "

You need to pass a song

"; } print "\n\n\n"; ######################################################################## # *** SUBS *** ######################################################################## ######################################################################## # Bail: this subrouting dies and displays the error to the browser. # gotten from the example in the O'Reilly # _Learning_Perl_on_Win32_Systems_ sub bail { my $error = "@_"; print "Error! $error"; exit; } ######################################################################## sub Print_Nav { open FILE, 'nav.inc' or die "\n\ncouldn't open FILE nav.inc: $!"; while () { print; } close FILE; }