#!/usr/bin/perl -w # $RedRiver$ ######################################################################## # RemoveMP3Playlist.pl *** Removed MP3's from the playlist # # 04-19-00 # Written by andrew fresh ######################################################################## use strict; use diagnostics; #my qw/ $removed $filename $list /; ######################################################################## # *** Variables *** my $filename = $ENV{'QUERY_STRING'}; my $list = '/var/www/mp3/playlist/playlist.lst'; ######################################################################## # *** MAIN *** ######################################################################## my @playlist = get_playlist($list); $filename =~ s/%(..)/pack("c",hex($1))/ge; my $removed = 0; my $oldfilename; print "Content-Type: text/html\n\n"; print "\n\n\t Added $filename\n\n\n"; # Print_Nav(); my $i; for ($i=0;$i<=$#playlist;$i++) { if ($filename eq $playlist[$i]) { $oldfilename = splice(@playlist,$i,1); $removed++; } } save_playlist($list,@playlist) || bail("Unable to save playlist!: $!"); if ($removed == 1) { print "Removed $removed instance of $filename"; } elsif ($removed > 1) { print "Removed $removed instances of $filename"; } else { print "Not Removed!
\n"; print "$filename not found" } print "\n\n\n"; ######################################################################## # *** SUBS *** ######################################################################## ####################################################################### # writes back the new playlist sub save_playlist { my $FILE = shift; my @lines = @_; open (FILE, ">$FILE") || bail ("Couldn\'t open $FILE: $!"); foreach (@lines) { print FILE "$_\n"; } close (FILE) || bail ("Couldn't close $FILE: $!"); return 1; } ####################################################################### # read in the Playlist sub get_playlist { my $FILE = shift; my @lines; while (@lines == 0) { open (FILE, $FILE) || bail ("Couldn\'t open $FILE: $!"); chomp (@lines = ); close (FILE) || bail ("Couldn't close $FILE: $!"); } return @lines; } ######################################################################## # 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; }