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