Annotation of mp3/bin/showfiles.pl, Revision 1.3
1.1 andrew 1: #!/usr/bin/perl -w
1.3 ! andrew 2: # $RedRiver: showfiles.pl,v 1.2 2006/08/12 00:14:53 andrew Exp $
1.1 andrew 3: ########################################################################
4: # GenerateMP3HTML.pl *** Generates the HTML files for the playlist.
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/ @mp3s @dirs /;
14:
15: my $basedir = '/home/mp3/Sorted';
16: my $addurl = 'addmp3playlist.pl';
17:
18: #######################################################################
19: # *** MAIN ***
20: #######################################################################
21:
1.3 ! andrew 22: my ($prefix, $subdir) = split /\&/, $ENV{'QUERY_STRING'};
1.1 andrew 23: if ($subdir) {
24: $subdir =~ s/%(..)/pack("c",hex($1))/ge;
25: } else {
26: $subdir ='';
27: }
28:
1.3 ! andrew 29: if ($prefix) {
! 30: $prefix =~ s/%(..)/pack("c",hex($1))/ge;
! 31: } else {
! 32: $prefix ='';
! 33: }
! 34:
1.1 andrew 35: my @dirs = GetDirListing("$basedir/$subdir");
36: my @mp3s = GetMP3Listing("$basedir/$subdir");
37:
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: #Print_Nav();
43:
44: if ($subdir) {
45: print "<h3>";
46: SplitDir($subdir);
1.3 ! andrew 47: print " - <font size=\"-2\"><a href=\"" . "showall.pl" . "\?" . EncodeURL($prefix) . '&' . EncodeURL("$subdir") . "\">Show</a></font>";
! 48: print " - <font size=\"-2\"><a href=\"" . "addall.pl" . "\?" . EncodeURL($prefix) . '&' . EncodeURL("$subdir") . "\">Play</a></font>";
! 49: print " - <font size=\"-2\"><a href=\"" . "addall.pl" . "\?" . EncodeURL($prefix) . '&' . EncodeURL("$subdir") . '&' . EncodeURL('fulllist.lst') . "\">Approve</a></font>" if $prefix;
! 50: print "<br>\n";
1.1 andrew 51: print "</h3>\n";
52: print "<hr>\n";
53: }
54:
55: if (@dirs) {
56: foreach my $dir (@dirs) {
1.3 ! andrew 57: print "<a href=\"" . MyName() . "\?" . EncodeURL($prefix) . '&' . EncodeURL("$subdir/$dir") . "\">$dir</a> ";
! 58: print "- <font size=\"-2\"><a href=\"" . "showall.pl" . "\?" . EncodeURL($prefix) . '&' . EncodeURL("$subdir/$dir") . "\">Show</a></font>";
! 59: print "- <font size=\"-2\"><a href=\"" . "addall.pl" . "\?" . EncodeURL($prefix) . '&' . EncodeURL("$subdir/$dir") . "\">Play</a></font>";
! 60: print "- <font size=\"-2\"><a href=\"" . "addall.pl" . "\?" . EncodeURL($prefix) . '&' . EncodeURL("$subdir/$dir") . '&' . EncodeURL('fulllist.lst') . "\">Approve</a></font>" if $prefix;
! 61: print "<br>\n";
1.1 andrew 62: }
63: }
64:
65: if (@mp3s) {
66: print "<ul>\n";
67: foreach my $mp3 (@mp3s) {
68: my $songtitle = $mp3;
69: my $directory = $subdir;
70: $directory =~ s#.*/(.*)$#$1#;
71: # print "dir ", $directory;
72: # print "song ", $songtitle;
73: if ($songtitle =~ /\Q$directory\E\s/i) {
74: $songtitle =~ s/^.*- (\d{2}(\.| -) .*)/$1/i;
75: }
76:
77: print "\t<li>";
78: if ($songtitle =~ /\.mp3$/i) {
79: print "MP3: ";
80: } elsif ($songtitle =~ /\.ogg$/i) {
81: print "OGG: ";
82: }
83:
84: $songtitle =~ s/\.(mp3|ogg)$//i;
1.3 ! andrew 85: print "<a href=\"$addurl\?" . EncodeURL($prefix) . '&' . EncodeURL("$subdir/$mp3") . "\" target=\"bottom\">$songtitle</a>";
! 86: print " - <a href=\"$addurl\?" . EncodeURL($prefix) . '&' . EncodeURL("$subdir/$mp3") . '&' . EncodeURL('fulllist.lst') . "\" target=\"bottom\">Approve</a>" if $prefix;
! 87: print "</li>\n";
1.1 andrew 88: }
89: print "</ul>\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: my @directories;
106: my @songs;
107: opendir DIR, $DIR or bail("Unable to opendir $$!");
108: @directories = grep { !/^\./ && -d "$DIR/$_" } readdir(DIR);
109: closedir DIR;
110:
111: return sort @directories;
112: }
113:
114:
115:
116:
117: ########################################################################
118: # *** GetMP3Listing: reads the list of directories
119: sub GetMP3Listing {
120: my $DIR = shift;
121: my @songs;
122: opendir DIR, $DIR or bail("Unable to opendir $$!");
123: @songs = grep /\.(mp3|ogg)$/i, readdir(DIR);
124: closedir DIR;
125:
126: return sort @songs;
127: }
128:
129:
130:
131:
132:
133: ########################################################################
134: # *** EncodeURL: %encodes the parameters of the URL
135: sub EncodeURL {
136: my $strURL = shift;
137: $strURL =~ s/(\W)/sprintf("%%%x", ord($1))/eg;
138: return $strURL;
139: }
140:
141:
142:
143:
144: #########################################################################
145: # My name
146: sub MyName {
147: my @filename = (split /\//, $0);
148: pop @filename;
149: }
150:
151:
152:
153: #########################################################################
154: # SplitDir
155: sub SplitDir {
156: my $dir = shift;
157: substr($dir, 0, 1) = "";
158: my @filename = (split /\//, $dir);
159: my $file;
160: my $returntext;
161: my $i;
162:
163:
164: if ($dir ne " ") {
165: for ($i=0;$i<=$#filename;$i++) {
166: my $j;
167: my $url = "";
168: for ($j=0;$j<=$i;$j++) {
169: $url = "$url/$filename[$j]";
170: }
1.3 ! andrew 171: print "/<a href=\"showfiles.pl\?" . EncodeURL($prefix) . '&' . EncodeURL($url) . "\">$filename[$i]</a>";
1.1 andrew 172:
173: }
174: } else {
175: print "/";
176: }
177: }
178:
179:
180:
181:
182: #######################################################################
183: # Bail: this subrouting dies and displays the error to the browser.
184: # gotten from the example in the O'Reilly
185: # _Learning_Perl_on_Win32_Systems_
186: sub bail {
187: my $error = shift;
188: print "\n\nUnexpected Error: <b>$error</b><br>\n";
189: print "In " . __FILE__ . "\n";
190: die;
191: exit;
192: }
193: sub Print_Nav
194: {
195: open FILE, 'nav.inc' or die "\n\ncouldn't open FILE nav.inc: $!";
196: while (<FILE>) {
197: print;
198: }
199: close FILE;
200: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>