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

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

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

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