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

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

1.1       andrew      1: #!/usr/bin/perl -w
1.3     ! andrew      2: # $RedRiver: showall.pl,v 1.2 2006/08/12 00:14:53 andrew Exp $
1.1       andrew      3: ########################################################################
                      4: # showall.pl *** Displays all MP3's in all subdirs
                      5: #
                      6: # 04-27-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/ %mp3s %dirs /;
                     14:
                     15: my $basedir = '/home/mp3/Sorted';
                     16: my $addurl = 'addmp3playlist.pl';
                     17:
                     18: my $countdir = 0;
                     19: my $countmp3 = 0;
                     20: #######################################################################
                     21: # *** MAIN ***
                     22: #######################################################################
                     23:
1.3     ! andrew     24: my ($prefix, $subdir) = split /\&/, $ENV{'QUERY_STRING'};
        !            25: if ($subdir) {
        !            26:         $subdir =~ s/%(..)/pack("c",hex($1))/ge;
        !            27: } else {
        !            28:         $subdir ='';
        !            29: }
        !            30:
        !            31: if ($prefix) {
        !            32:         $prefix =~ s/%(..)/pack("c",hex($1))/ge;
1.1       andrew     33: } else {
1.3     ! andrew     34:         $prefix ='';
1.1       andrew     35: }
                     36:
                     37: #$basedir = $basedir . "/" . $subdir;
                     38:
                     39: print "Content-Type: text/html\n\n";
                     40: print "<html>\n<head>\n\t<meta HTTP-EQUIV='Pragma' CONTENT='no-cache'> <title>' . $subdir . '</title>\n<body>\n\n";
                     41:
                     42:
                     43: #Print_Nav();
                     44:
                     45: if ($subdir) {
                     46:        print "<h3>";
                     47:        SplitDir($subdir);
1.3     ! andrew     48:        print " - <font size=\"-2\"><a href=\"" . "showall.pl" . "\?" . EncodeURL($prefix) . '&' . EncodeURL("$subdir") . "\">Show</a></font>";
        !            49:        print " - <font size=\"-2\"><a href=\"" . "addall.pl" . "\?" . EncodeURL($prefix) . '&' . EncodeURL("$subdir") . "\">Play</a></font>";
        !            50:        print " - <font size=\"-2\"><a href=\"" . "addall.pl" . "\?" . EncodeURL($prefix) . '&' . EncodeURL("$subdir") . EncodeURL('fulllist.lst') . "\">Approve</a></font>" if $prefix;
        !            51:        print "<br>";
1.1       andrew     52:        print "</h3>\n";
                     53:        print "<hr>\n";
                     54: }
                     55:
                     56: #print "<h3>";
                     57: #SplitDir($subdir);
                     58: #print "</h3>\n<hr>\n";
                     59:
                     60: #@mp3s = GetMP3Listing("$basedir/$subdir");
                     61:
                     62: GetDirListing("$subdir");
                     63: #GetDirListing("");
                     64:
                     65: print "<hr>\n<h3>Total Directories displayed: $countdir<br>\n";
                     66: print "Total Songs displayed: $countmp3</h3>\n";
                     67:
                     68: #if (%dirs) {
                     69: #      my $count;
                     70: #      my @sorted = sort { lc($dirs{$a}) cmp lc($dirs{$b}) } (keys %dirs);
                     71: #      foreach my $dir (@sorted) {
1.3     ! andrew     72: #              print "<a href=\"showfiles.pl\?" . EncodeURL($prefix) . '&' . EncodeURL("$dir/$dirs{$dir}") . "\">$dirs{$dir}</a><br>";
1.1       andrew     73: #              $count++;
                     74: #      }
                     75: #      print "Total dirs displayed: $count<p>\n";
                     76: #}
                     77:
                     78: #if (%mp3s) {
                     79: #      print "<ul>\n";
                     80: #      my @sorted = sort { lc($mp3s{$a}) cmp lc($mp3s{$b}) } (keys %mp3s);
                     81: #      my $count;
                     82: #      foreach my $mp3dir (sort keys %mp3s) {
                     83: #              foreach $mp3 (@{ $mp3s{$mp3dir} }) {
1.3     ! andrew     84: #                      print "\t<li>Song: <a href=\"$addurl\?" . EncodeURL($prefix) . '&' . EncodeURL("$mp3dir/$mp3") . "\" target=\"bottom\">$mp3</a></li>\n";
1.1       andrew     85: #                      $count++;
                     86: #              }
                     87: #      }
                     88: #      print "</ul>\n";
                     89: #      print "Total MP3's Displayed: $count<p>\n";
                     90: #}
                     91:
                     92: print "</body>\n</head>\n</html>\n";
                     93:
                     94:
                     95:
                     96:
                     97: ########################################################################
                     98: # *** SUBS ***
                     99: ########################################################################
                    100:
                    101: ########################################################################
                    102: # *** GetDirListing: reads the list of directories
                    103: sub GetDirListing {
                    104:        my $DIR = shift;
                    105:        $DIR ||= '';
                    106:        my @directories;
                    107:        my @songs;
                    108:
                    109:
                    110:        opendir DIR, "$basedir/$DIR" or bail("Unable to opendir $$!");
                    111:                @directories = sort grep { !/^\./ && -d "$basedir$DIR/$_" } readdir(DIR);
                    112:        closedir DIR;
                    113:
                    114:        print "<ul>\n";
                    115:        foreach my $directory (@directories) {
                    116: #              $dirs{"$DIR/$directory"} = $directory;
1.3     ! andrew    117:                print "<li><a href=\"showfiles.pl\?" . EncodeURL($prefix) . '&' . EncodeURL("$DIR/$directory") . "\">$directory</a>";
        !           118:                print " - <font size=\"-1\"><a href=\"" . "showall.pl" . "\?" . EncodeURL($prefix) . '&' . EncodeURL("$DIR/$directory") . "\">Show</a></font>";
        !           119:                print " - <font size=\"-1\"><a href=\"" . "addall.pl" . "\?" . EncodeURL($prefix) . '&' . EncodeURL("$DIR/$directory") . "\">Play</a></font>";
        !           120:                print " - <font size=\"-1\"><a href=\"" . "addall.pl" . "\?" . EncodeURL($prefix) . '&' . EncodeURL("$DIR/$directory") . EncodeURL('fulllist.lst') . "\">Approve</a></font>";
        !           121:                print "</li>";
1.1       andrew    122:
                    123:                $countdir++;
                    124:                my @curdir = GetDirListing("$DIR/$directory");
                    125:
                    126:
                    127:
                    128: #              push @dirs, @curdir;
1.3     ! andrew    129: #              print "<a href=\"showfiles.pl\?" . EncodeURL($prefix) . '&' . EncodeURL("$DIR/$directory") . "\">$directory</a><br>";
1.1       andrew    130:        }
                    131:        opendir DIR, "$basedir/$DIR" or bail("Unable to opendir $$!");
                    132:                my @temp = grep /\.(mp3|ogg)$/i, readdir(DIR);
                    133: #              $mp3s{"$DIR/$directory"} = [ @temp ];
                    134:                print "<ul>\n";
                    135:                foreach my $mp3 (sort @temp) {
                    136:                        my $songtitle = $mp3;
                    137:                        my $directory = $DIR;
                    138:                        $directory =~ s#.*/(.*)$#$1#;
                    139: #                      print "dir ", $directory;
                    140: #                      print "song ", $songtitle;
                    141:                        if ($songtitle =~ /\Q$directory\E\s/i) {
                    142: #                              print "MATCHED";
                    143:                                $songtitle =~ s/^.*- (\d{2}(\.| -) .*)/$1/i;
                    144:                        }
                    145:                        print "\t<li>";
                    146:                        if ($songtitle =~ /\.mp3$/i) {
                    147:                                print "MP3: ";
                    148:                        } elsif ($songtitle =~ /\.ogg$/i) {
                    149:                                print "OGG: ";
                    150:                        }
                    151:                        $songtitle =~ s/\.(mp3|ogg)$//i;
1.3     ! andrew    152:                        print "<a href=\"$addurl\?" . EncodeURL($prefix) . '&' . EncodeURL("$DIR/$mp3") . "\" target=\"bottom\">$songtitle</a></li>\n";
1.1       andrew    153:                        $countmp3++;
                    154:                }
                    155:                print "</ul>\n";
                    156:        closedir DIR;
                    157:
                    158:        print "</ul>\n";
                    159:
                    160:
                    161:        return sort @directories;
                    162: }
                    163:
                    164:
                    165:
                    166:
                    167: ########################################################################
                    168: # *** GetMP3Listing: reads the list of directories
                    169: sub GetMP3Listing {
                    170:        my $DIR = shift;
                    171:        my @songs;
                    172:        opendir DIR, $DIR or bail("Unable to opendir $$!");
                    173:                @songs = grep /\.(mp3|ogg)$/i, readdir(DIR);
                    174:        closedir DIR;
                    175:
                    176:        return sort @songs;
                    177: }
                    178:
                    179:
                    180:
                    181:
                    182:
                    183: ########################################################################
                    184: # *** EncodeURL: %encodes the parameters of the URL
                    185: sub EncodeURL {
                    186:        my $strURL = shift;
                    187:        $strURL =~ s/(\W)/sprintf("%%%x", ord($1))/eg;
                    188:        return $strURL;
                    189: }
                    190:
                    191:
                    192:
                    193:
                    194: #########################################################################
                    195: # My name
                    196: sub MyName {
                    197:        my @filename = (split /\//, $0);
                    198:        pop @filename;
                    199: }
                    200:
                    201:
                    202:
                    203: #########################################################################
                    204: # SplitDir
                    205: sub SplitDir {
                    206:        my $dir = shift;
                    207:        substr($dir, 0, 1) = "";
                    208:        my @filename = (split /\//, $dir);
                    209:        my $file;
                    210:        my $returntext;
                    211:        my $i;
                    212:
                    213:
                    214:        if ($dir ne " ") {
                    215:                for ($i=0;$i<=$#filename;$i++) {
                    216:                        my $j;
                    217:                        my $url = "";
                    218:                        for ($j=0;$j<=$i;$j++) {
                    219:                                $url = "$url/$filename[$j]";
                    220:                        }
1.3     ! andrew    221:                print "/<a href=\"showfiles.pl\?" . EncodeURL($prefix) . '&' . EncodeURL($url) . "\">$filename[$i]</a>";
1.1       andrew    222:
                    223:                }
                    224:        } else {
                    225:                print "/";
                    226:        }
                    227: }
                    228:
                    229:
                    230:
                    231:
                    232: #######################################################################
                    233: # Bail: this subrouting dies and displays the error to the browser.
                    234: # gotten from the example in the O'Reilly
                    235: # _Learning_Perl_on_Win32_Systems_
                    236: sub bail {
                    237:        my $error = shift;
                    238:        print "\n\nUnexpected Error: <b>$error</b><br>\n";
                    239:        print "In " . __FILE__ . "\n";
                    240:        die;
                    241:        exit;
                    242: }
                    243: sub Print_Nav
                    244: {
                    245:        open FILE, 'nav.inc' or die "\n\ncouldn't open FILE nav.inc: $!";
                    246:        while (<FILE>) {
                    247:                print;
                    248:        }
                    249:        close FILE;
                    250: }

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