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