Annotation of mp3/bin/showall.pl, Revision 1.4
1.1 andrew 1: #!/usr/bin/perl -w
1.4 ! andrew 2: # $RedRiver: showall.pl,v 1.3 2007/02/08 20:04:03 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>";
1.4 ! andrew 50: print " - <font size=\"-2\"><a href=\"" . "addall.pl" . "\?" . EncodeURL($prefix) . '&' . EncodeURL("$subdir") . '&' . EncodeURL('fulllist.lst') . "\">Approve</a></font>" if $prefix;
1.3 andrew 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>";
1.4 ! andrew 118: print " - <font size=\"-2\"><a href=\"" . "showall.pl" . "\?" . EncodeURL($prefix) . '&' . EncodeURL("$DIR/$directory") . "\">Show</a></font>";
! 119: print " - <font size=\"-2\"><a href=\"" . "addall.pl" . "\?" . EncodeURL($prefix) . '&' . EncodeURL("$DIR/$directory") . "\">Play</a></font>";
! 120: print " - <font size=\"-2\"><a href=\"" . "addall.pl" . "\?" . EncodeURL($prefix) . '&' . EncodeURL("$DIR/$directory") . '&' . EncodeURL('fulllist.lst') . "\">Approve</a></font>";
1.3 andrew 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.4 ! andrew 152: print "<a href=\"$addurl\?" . EncodeURL($prefix) . '&' . EncodeURL("$DIR/$mp3") . "\" target=\"bottom\">$songtitle</a>\n";
! 153: print " - <font size=\"-2\"><a href=\"$addurl\?" . EncodeURL($prefix) . '&' . EncodeURL("$DIR/$mp3") . '&' . EncodeURL('fulllist.lst') . "\" target=\"bottom\">Approve</a></font>\n" if $prefix;
! 154: print "</li>";
1.1 andrew 155: $countmp3++;
156: }
157: print "</ul>\n";
158: closedir DIR;
159:
160: print "</ul>\n";
161:
162:
163: return sort @directories;
164: }
165:
166:
167:
168:
169: ########################################################################
170: # *** GetMP3Listing: reads the list of directories
171: sub GetMP3Listing {
172: my $DIR = shift;
173: my @songs;
174: opendir DIR, $DIR or bail("Unable to opendir $$!");
175: @songs = grep /\.(mp3|ogg)$/i, readdir(DIR);
176: closedir DIR;
177:
178: return sort @songs;
179: }
180:
181:
182:
183:
184:
185: ########################################################################
186: # *** EncodeURL: %encodes the parameters of the URL
187: sub EncodeURL {
188: my $strURL = shift;
189: $strURL =~ s/(\W)/sprintf("%%%x", ord($1))/eg;
190: return $strURL;
191: }
192:
193:
194:
195:
196: #########################################################################
197: # My name
198: sub MyName {
199: my @filename = (split /\//, $0);
200: pop @filename;
201: }
202:
203:
204:
205: #########################################################################
206: # SplitDir
207: sub SplitDir {
208: my $dir = shift;
209: substr($dir, 0, 1) = "";
210: my @filename = (split /\//, $dir);
211: my $file;
212: my $returntext;
213: my $i;
214:
215:
216: if ($dir ne " ") {
217: for ($i=0;$i<=$#filename;$i++) {
218: my $j;
219: my $url = "";
220: for ($j=0;$j<=$i;$j++) {
221: $url = "$url/$filename[$j]";
222: }
1.3 andrew 223: print "/<a href=\"showfiles.pl\?" . EncodeURL($prefix) . '&' . EncodeURL($url) . "\">$filename[$i]</a>";
1.1 andrew 224:
225: }
226: } else {
227: print "/";
228: }
229: }
230:
231:
232:
233:
234: #######################################################################
235: # Bail: this subrouting dies and displays the error to the browser.
236: # gotten from the example in the O'Reilly
237: # _Learning_Perl_on_Win32_Systems_
238: sub bail {
239: my $error = shift;
240: print "\n\nUnexpected Error: <b>$error</b><br>\n";
241: print "In " . __FILE__ . "\n";
242: die;
243: exit;
244: }
245: sub Print_Nav
246: {
247: open FILE, 'nav.inc' or die "\n\ncouldn't open FILE nav.inc: $!";
248: while (<FILE>) {
249: print;
250: }
251: close FILE;
252: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>