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

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

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

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