[BACK]Return to addmp3playlist.pl CVS log [TXT][DIR] Up to [local] / mp3 / bin

File: [local] / mp3 / bin / addmp3playlist.pl (download)

Revision 1.1, Thu Mar 2 23:20:47 2006 UTC (18 years, 2 months ago) by andrew
Branch: MAIN

Initial revision

#!/usr/bin/perl -w
########################################################################
# addmp3playlist.pl *** Adds MP3's to the playlist
#
# 04-13-00
# Written by andrew fresh <andrew@mad-techies.org>
########################################################################
use strict;
use diagnostics;



########################################################################
# *** Variables ***
my $DestDir = '/home/mp3/Sorted';
my $filename = $ENV{'QUERY_STRING'};
my $playlist = '/var/www/mp3/playlist/playlist.lst';



########################################################################
# *** MAIN ***
########################################################################
if (! -d $DestDir) { mkdir $DestDir, 0777 }



print "Content-Type: text/html\n\n";

$filename =~ s/%(..)/pack("c",hex($1))/ge;

if ($filename) {
	print "<html>\n<head>\n\t<meta HTTP-EQUIV='Pragma' CONTENT='no-cache'>";

	if ($ENV{'QUERY_STRING'}) {
        	print "<meta HTTP-EQUIV=Refresh CONTENT=\"10; URL=/blank.htm\">";
	}

	print "<title>Added $filename</title>\n<body>\n\n";

	print "<h3>Added $filename</h3>\n";
	open  PLAYLIST, ">>$playlist" or bail("unable to open PLAYLIST: $!");
	print PLAYLIST "$filename\n";
	close PLAYLIST or bail("unable to close PLAYLIST: $!");
} else {
	print "<h1>You need to pass a song</h1>";
}

print "</body>\n</head>\n</html>\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 (<FILE>) {
		print;
	}
	close FILE;
}