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