File: [local] / mp3 / bin / addmp3playlist.pl (download)
Revision 1.3, Thu Feb 8 20:04:03 2007 UTC (17 years, 5 months ago) by andrew
Branch: MAIN
CVS Tags: HEAD Changes since 1.2: +20 -4 lines
First shot at making multiple jukeboxes from the same files.
|
#!/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 <andrew@mad-techies.org>
########################################################################
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 "<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;
}