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

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

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

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