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