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

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

1.1     ! andrew      1: #!/usr/bin/perl -w
        !             2: ########################################################################
        !             3: # ShowPlaylist.pl *** Displays our current playlist on a web page
        !             4: #
        !             5: # 04-14-00
        !             6: # Written by andrew fresh <andrew@mad-techies.org>
        !             7: ########################################################################
        !             8: use strict;
        !             9: use diagnostics;
        !            10:
        !            11: #use MP3::Info;
        !            12: #my qw/ $list @playlist $maplay $filename $basedir $htmldir $add /;
        !            13:
        !            14: my $args = shift;
        !            15:
        !            16: my ($listfile,$add);
        !            17: if ($args) {
        !            18:        ($listfile,$add) = split /\\&/, $args;
        !            19: }
        !            20: $listfile ||= 'playlist.lst';
        !            21:
        !            22: my $list = '/var/www/mp3/playlist/' . $listfile;
        !            23:
        !            24: my $playlist = '/var/www/mp3/playlist/playlist.lst';
        !            25:
        !            26: my $exe = 'removemp3playlist.pl';
        !            27: unless ($listfile eq 'playlist.lst') {
        !            28:        $exe = 'addmp3playlist.pl';
        !            29: } else {
        !            30:        $add = undef;
        !            31: }
        !            32:
        !            33: #######################################################################
        !            34: # *** MAIN ***
        !            35: #######################################################################
        !            36:
        !            37: my @playlist = get_playlist($list);
        !            38:
        !            39: print "Content-Type: text/html\n\n";
        !            40: print "\n\n<html>\n<head>\n\t<meta HTTP-EQUIV='Pragma' CONTENT='no-cache'> <title>$listfile</title>\n";
        !            41: print "<meta HTTP-EQUIV=\"REFRESH\" CONTENT=\"300\">\n";
        !            42: print "<body>\n\n";
        !            43:
        !            44: use CGI::Carp qw/ fatalsToBrowser /;
        !            45:
        !            46: #Print_Nav();
        !            47: #print "args: $args\n";
        !            48: if ($listfile eq 'playlist.lst') {
        !            49:        print '<a href="deleteplaylist.pl">Delete Playlist</a>';
        !            50: }
        !            51:
        !            52:
        !            53:
        !            54:
        !            55: unless ($add) {
        !            56:        print "<h1>Currently in $listfile as of " . GetTime() . "</h1><hr>\n";
        !            57:        my $file = $0;
        !            58:        $file =~ s#^.*[//]##;
        !            59:        print "<a href='$file?$listfile\&ADD'>Add All</A><br>\n";
        !            60: } else {
        !            61:        print "<h1>Added to playlist from $listfile as of " . GetTime() . "</h1><hr>\n";
        !            62: }
        !            63:
        !            64:
        !            65:
        !            66: if (@playlist) {
        !            67:        my $counter;
        !            68:
        !            69:        foreach my $filename (@playlist) {
        !            70:                if ($add) {
        !            71:                        AddSong($filename);
        !            72:                } else {
        !            73:                        print "\t<li><a href=\"$exe\?" . EncodeURL($filename) . "\" target=\"bottom\">$filename</a></li>\n";
        !            74:                }
        !            75:                $counter++;
        !            76:        }
        !            77:        print "<H3>Total displayed: $counter</h3>\n";
        !            78: } else {
        !            79:        print "\t<li>Nothing in list</li>\n";
        !            80: }
        !            81: print "</UL>\n</body>\n</head>\n</html>\n";
        !            82:
        !            83:
        !            84:
        !            85:
        !            86:
        !            87:
        !            88:
        !            89:
        !            90:
        !            91:
        !            92:
        !            93:
        !            94:
        !            95:
        !            96:
        !            97:
        !            98: #########################################################################
        !            99: # GetTime
        !           100: sub GetTime {
        !           101:        my $hours = shift;
        !           102:        my ($sec,$min,$hour,$mday,$mon,$year,,,) = localtime(); # 86400 seconds is one day
        !           103:
        !           104:        if ($min  < 10) { $min  = "0$min"}
        !           105:        if ($sec  < 10) { $sec  = "0$sec"}
        !           106:        if ($hour < 10) { $hour = "0$hour"}
        !           107:        if ($mday < 10) { $mday = "0$mday"}
        !           108:        if ($mon  < 10) { $mon  = "0$mon"}
        !           109:
        !           110:        my $time = ($year + 1900) . '-' . ++$mon . '-' . $mday  . ' ' . $hour . ':' . $min . ':' . $sec;
        !           111:        return $time;
        !           112: }
        !           113: #########################################################################
        !           114:
        !           115:
        !           116:
        !           117:
        !           118:
        !           119: #######################################################################
        !           120: # read in the Playlist
        !           121: sub get_playlist {
        !           122:        my $FILE = shift;
        !           123:        my @lines;
        !           124:        if (-e $FILE) {
        !           125:                open (FILE, $FILE) || bail ("Couldn\'t open $FILE: $!");
        !           126:                chomp (@lines = <FILE>);
        !           127:                close (FILE) || bail ("Couldn't close $FILE: $!");
        !           128:        }
        !           129:        return @lines;
        !           130: }
        !           131:
        !           132:
        !           133:
        !           134:
        !           135: ########################################################################
        !           136: # *** EncodeURL: %encodes the parameters of the URL
        !           137: sub EncodeURL {
        !           138:        my $strURL = shift;
        !           139:        $strURL =~ s/(\W)/sprintf("%%%x", ord($1))/eg;
        !           140:        return $strURL;
        !           141: }
        !           142:
        !           143:
        !           144:
        !           145:
        !           146: #######################################################################
        !           147: # Bail: this subrouting dies and displays the error to the browser.
        !           148: # gotten from the example in the O'Reilly
        !           149: # _Learning_Perl_on_Win32_Systems_
        !           150: sub bail {
        !           151:        my $error = "@_";
        !           152:        print "Unexpected Error: $error";
        !           153:        exit;
        !           154: }
        !           155:
        !           156:
        !           157: sub Print_Nav
        !           158: {
        !           159:        open FILE, 'nav.inc' or die "\n\ncouldn't open FILE nav.inc: $!";
        !           160:        while (<FILE>) {
        !           161:                print;
        !           162:        }
        !           163:        close FILE;
        !           164: }
        !           165: sub AddSong
        !           166: {
        !           167:        my $filename = shift;
        !           168:        $filename =~ s/%(..)/pack("c",hex($1))/ge;
        !           169:
        !           170:        if ($filename) {
        !           171:                open  PLAYLIST, ">>$playlist" or bail("unable to open PLAYLIST: $!");
        !           172:                print PLAYLIST "$filename\n";
        !           173:                close PLAYLIST or bail("unable to close PLAYLIST: $!");
        !           174:                print "Added $filename<br>\n";
        !           175:        } else {
        !           176:                print "<h1>You need to pass a song</h1>";
        !           177:        }
        !           178: }

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