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

Annotation of mp3/bin/removemp3playlist.pl, Revision 1.2

1.1       andrew      1: #!/usr/bin/perl -w
1.2     ! andrew      2: # $RedRiver$
1.1       andrew      3: ########################################################################
                      4: # RemoveMP3Playlist.pl *** Removed MP3's from the playlist
                      5: #
                      6: # 04-19-00
                      7: # Written by andrew fresh <andrew@mad-techies.org>
                      8: ########################################################################
                      9: use strict;
                     10: use diagnostics;
                     11:
                     12:
                     13: #my qw/ $removed $filename $list /;
                     14: ########################################################################
                     15: # *** Variables ***
                     16: my $filename = $ENV{'QUERY_STRING'};
                     17: my $list = '/var/www/mp3/playlist/playlist.lst';
                     18:
                     19:
                     20:
                     21: ########################################################################
                     22: # *** MAIN ***
                     23: ########################################################################
                     24:
                     25: my @playlist = get_playlist($list);
                     26: $filename =~ s/%(..)/pack("c",hex($1))/ge;
                     27: my $removed = 0;
                     28: my $oldfilename;
                     29:
                     30: print "Content-Type: text/html\n\n";
                     31: print "<html>\n<head>\n\t<meta HTTP-EQUIV='Pragma' CONTENT='no-cache'> <title>Added $filename</title>\n<body>\n\n";
                     32:
                     33: # Print_Nav();
                     34: my $i;
                     35: for ($i=0;$i<=$#playlist;$i++) {
                     36:        if ($filename eq $playlist[$i]) {
                     37:                $oldfilename = splice(@playlist,$i,1);
                     38:                $removed++;
                     39:        }
                     40: }
                     41:
                     42: save_playlist($list,@playlist) || bail("Unable to save playlist!: $!");
                     43:
                     44: if ($removed == 1) {
                     45:        print "Removed $removed instance of $filename";
                     46: } elsif ($removed > 1) {
                     47:        print "Removed $removed instances of $filename";
                     48: } else {
                     49:        print "Not Removed!<br>\n";
                     50:        print "$filename not found"
                     51: }
                     52:
                     53: print "</body>\n</head>\n</html>\n";
                     54:
                     55:
                     56:
                     57:
                     58:
                     59:
                     60:
                     61:
                     62:
                     63:
                     64: ########################################################################
                     65: # *** SUBS ***
                     66: ########################################################################
                     67:
                     68:
                     69:
                     70:
                     71: #######################################################################
                     72: # writes back the new playlist
                     73: sub save_playlist {
                     74:        my $FILE = shift;
                     75:        my @lines = @_;
                     76:        open (FILE, ">$FILE") || bail ("Couldn\'t open $FILE: $!");
                     77:        foreach (@lines) {
                     78:                print FILE "$_\n";
                     79:        }
                     80:        close (FILE) || bail ("Couldn't close $FILE: $!");
                     81:        return 1;
                     82: }
                     83:
                     84:
                     85:
                     86:
                     87: #######################################################################
                     88: # read in the Playlist
                     89: sub get_playlist {
                     90:        my $FILE = shift;
                     91:        my @lines;
                     92:        while (@lines == 0) {
                     93:                open (FILE, $FILE) || bail ("Couldn\'t open $FILE: $!");
                     94:                chomp (@lines = <FILE>);
                     95:                close (FILE) || bail ("Couldn't close $FILE: $!");
                     96:        }
                     97:        return @lines;
                     98: }
                     99:
                    100:
                    101:
                    102:
                    103:
                    104: ########################################################################
                    105: # Bail: this subrouting dies and displays the error to the browser.
                    106: # gotten from the example in the O'Reilly
                    107: # _Learning_Perl_on_Win32_Systems_
                    108: sub bail {
                    109:        my $error = "@_";
                    110:        print "Error! $error";
                    111:        exit;
                    112: }
                    113: ########################################################################
                    114:
                    115:
                    116: sub Print_Nav
                    117: {
                    118:        open FILE, 'nav.inc' or die "\n\ncouldn't open FILE nav.inc: $!";
                    119:        while (<FILE>) {
                    120:                print;
                    121:        }
                    122:        close FILE;
                    123: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>