Annotation of mp3/bin/addsearch.pl, Revision 1.3
1.1 andrew 1: #!/usr/bin/perl -w
1.3 ! andrew 2: # $RedRiver: addsearch.pl,v 1.2 2006/08/12 00:14:53 andrew Exp $
1.1 andrew 3: ########################################################################
4: # Search.pl *** Searches the full list of songs and finds matches.
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/ @playlist $maplay $filename $basedir $htmldir /;
14:
15:
16: my $exe = 'addmp3playlist.pl';
17: my $Search = 'search.pl';
18:
19: #######################################################################
20: # *** MAIN ***
21: #######################################################################
22:
1.3 ! andrew 23: my $prefix = $ENV{'QUERY_STRING'};
! 24: if ($prefix) {
! 25: $prefix =~ s/%(..)/pack("c",hex($1))/ge;
! 26: } else {
! 27: $prefix ='';
! 28: }
! 29:
! 30: my $listfile = $prefix . 'fulllist.lst';
! 31: my $list = '/var/www/mp3/playlist/' . $listfile;
! 32: my $playlist = '/var/www/mp3/playlist/' . $prefix . 'playlist.lst';
1.1 andrew 33:
34: print "Content-Type: text/html\n\n";
35: print "\n\n<html>\n<head>\n\t<meta HTTP-EQUIV='Pragma' CONTENT='no-cache'> <title>MP3 Search</title>\n";
36: #print "<meta HTTP-EQUIV=\"REFRESH\" CONTENT=\"300\">\n";
37: print "<body>\n\n";
38:
39:
40: #Print_Nav();
41:
42: print "<h1>Adding MP3's . . .</h1><hr>\n";
43:
44: use CGI qw/:standard/;
45: use CGI::Carp qw/fatalsToBrowser/;
46:
47: my $Query = new CGI;
48:
49: my @playlist;
50:
51: my $Search_Term = $Query->param('Search_Term');
52: my @Fields_To_Search = $Query->param('Fields');
53: @Fields_To_Search = ('Artist', 'Album', 'Song') unless @Fields_To_Search;
54:
55:
56: #print $Query->header;
57: #print "Search_Term: $Search_Term<br>\n";
58:
59: print $Query->start_form(-action=>$Search);
60: # $Query->hidden('Fields', \@Fields_To_Search);
61:
62: print "Search For: ",
63: $Query->textfield(-name=>'Search_Term',
64: -size=>70,
65: -maxlength=>80);
66:
67: # print $Query->checkbox_group(-name=>'Fields',
68: # -values=>[@Fields_To_Search],
69: # -default=>[@Fields_To_Search],
70: ## -linebreak=>'true',
71: # ), br();
72:
73:
74: print $Query->submit(-name=>'Submit',
75: -value=>'Submit'),
76: $Query->end_form;
77:
78: if ($Search_Term) {
79: print "Found ";
80:
81: @playlist = Search($list, \@Fields_To_Search, $Search_Term);
82:
83: print scalar @playlist;
84: print " Songs<P>\n";
85:
86: #List_Recipes(%recipes);
87:
88:
89: if (@playlist) {
90: my $counter;
91:
92: print "<br>\n";
93: foreach my $filename (@playlist) {
1.3 ! andrew 94: #print "\t<li><a href=\"$exe\?" . EncodeURL($prefix) . '&' . EncodeURL($filename) . "\" target=\"bottom\">$filename</a></li>\n";
1.1 andrew 95: AddSong($filename);
96: $counter++;
97: }
98: print "<H3>Total displayed: $counter</h3>\n";
99: } else {
100: print "\t<li>Nothing in list</li>\n";
101: }
102: }
103:
104:
105:
106: print "</UL>\n</body>\n</head>\n</html>\n";
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123: #########################################################################
124: # GetTime
125: sub GetTime {
126: my $hours = shift;
127: my ($sec,$min,$hour,$mday,$mon,$year,,,) = localtime(); # 86400 seconds is one day
128:
129: if ($min < 10) { $min = "0$min"}
130: if ($sec < 10) { $sec = "0$sec"}
131: if ($hour < 10) { $hour = "0$hour"}
132: if ($mday < 10) { $mday = "0$mday"}
133: if ($mon < 10) { $mon = "0$mon"}
134:
135: my $time = ($year + 1900) . '-' . ++$mon . '-' . $mday . ' ' . $hour . ':' . $min . ':' . $sec;
136: return $time;
137: }
138: #########################################################################
139:
140:
141:
142:
143:
144: #######################################################################
145: # read in the Playlist
146: sub Search {
147: my $FILE = shift;
148: my $fields = shift;
149: my $term = shift;
150: my @lines;
151: open (FILE, $FILE) || bail ("Couldn\'t open $FILE: $!");
152: while (<FILE>) {
153: if (/$term/i) {
154: chomp;
155: push @lines, $_;
156: }
157: }
158: close (FILE) || bail ("Couldn't close $FILE: $!");
159: return @lines;
160: }
161:
162:
163:
164:
165: ########################################################################
166: # *** EncodeURL: %encodes the parameters of the URL
167: sub EncodeURL {
168: my $strURL = shift;
169: $strURL =~ s/(\W)/sprintf("%%%x", ord($1))/eg;
170: return $strURL;
171: }
172:
173:
174:
175:
176: #######################################################################
177: # Bail: this subrouting dies and displays the error to the browser.
178: # gotten from the example in the O'Reilly
179: # _Learning_Perl_on_Win32_Systems_
180: sub bail {
181: my $error = "@_";
182: print "Unexpected Error: $error";
183: exit;
184: }
185:
186:
187: sub Print_Nav
188: {
189: open FILE, 'nav.inc' or die "\n\ncouldn't open FILE nav.inc: $!";
190: while (<FILE>) {
191: print;
192: }
193: close FILE;
194: }
195:
196: sub AddSong
197: {
198: my $filename = shift;
199: $filename =~ s/%(..)/pack("c",hex($1))/ge;
200:
201: if ($filename) {
202: open PLAYLIST, ">>$playlist" or bail("unable to open PLAYLIST: $!");
203: print PLAYLIST "$filename\n";
204: close PLAYLIST or bail("unable to close PLAYLIST: $!");
205: print "Added $filename<br>\n";
206: } else {
207: print "<h1>You need to pass a song</h1>";
208: }
209: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>