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

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

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

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