File: [local] / mp3 / bin / search.pl (download)
Revision 1.4, Thu Feb 8 23:03:15 2007 UTC (17 years, 7 months ago) by andrew
Branch: MAIN
CVS Tags: HEAD Changes since 1.3: +6 -4 lines
fix some of the approval links.
|
#!/usr/bin/perl -w
# $RedRiver: search.pl,v 1.3 2007/02/08 20:04:03 andrew Exp $
########################################################################
# Search.pl *** Searches the full list of songs and finds matches.
#
# 04-14-00
# Written by andrew fresh <andrew@mad-techies.org>
########################################################################
use strict;
use diagnostics;
#use MP3::Info;
#my qw/ $list @playlist $maplay $filename $basedir $htmldir /;
my $exe = 'addmp3playlist.pl';
my $Add_Search = 'addsearch.pl';
#######################################################################
# *** MAIN ***
#######################################################################
my ($prefix) = split /\&/, $ENV{'QUERY_STRING'};
if ($prefix) {
$prefix =~ s/%(..)/pack("c",hex($1))/ge;
} else {
$prefix ='';
}
my $listfile = 'fulllist.lst';
my $list = '/var/www/mp3/playlist/' . $listfile;
print "Content-Type: text/html\n\n";
print "\n\n<html>\n<head>\n\t<meta HTTP-EQUIV='Pragma' CONTENT='no-cache'> <title>MP3 Search</title>\n";
#print "<meta HTTP-EQUIV=\"REFRESH\" CONTENT=\"300\">\n";
print "<body>\n\n";
#Print_Nav();
print "<h1>Searching MP3's . . .</h1><hr>\n";
use CGI qw/:standard/;
use CGI::Carp qw/fatalsToBrowser/;
my $Query = new CGI;
my @playlist;
my $Search_Term = $Query->param('Search_Term');
my @Fields_To_Search = $Query->param('Fields');
@Fields_To_Search = ('Artist', 'Album', 'Song') unless @Fields_To_Search;
#print $Query->header;
#print "Search_Term: $Search_Term<br>\n";
print $Query->start_form();
# $Query->hidden('Fields', \@Fields_To_Search);
print "Search For: ",
$Query->textfield(-name=>'Search_Term',
-size=>70,
-maxlength=>80);
# print $Query->checkbox_group(-name=>'Fields',
# -values=>[@Fields_To_Search],
# -default=>[@Fields_To_Search],
## -linebreak=>'true',
# ), br();
print $Query->submit(-name=>'Submit',
-value=>'Submit'),
$Query->end_form;
if ($Search_Term) {
print "Found ";
@playlist = Search($list, \@Fields_To_Search, $Search_Term);
print scalar @playlist;
print " Songs\n";
print $Query->start_form(-action=>$Add_Search);
foreach my $key ($Query->param) {
print $Query->hidden($key, $Query->param($key));
}
print $Query->submit(-name=>'Submit', -value=>'Play All');
print $Query->submit(-name=>'Submit', -value=>'Approve All') if $prefix;
print $Query->end_form, "\n";;
#List_Recipes(%recipes);
if (@playlist) {
my $counter;
foreach my $filename (@playlist) {
print "\t<li><a href=\"$exe\?" . EncodeURL($prefix) . '&' . EncodeURL($filename) . "\" target=\"bottom\">$filename</a>";
print " - <a href=\"$exe\?" . EncodeURL($prefix) . '&' . EncodeURL($filename) . '&' . EncodeURL('fulllist.lst') . "\" target=\"bottom\">Approve</a>";
print "</li>\n";
$counter++;
}
print "<H3>Total displayed: $counter</h3>\n";
} else {
print "\t<li>Nothing in list</li>\n";
}
}
print "</UL>\n</body>\n</head>\n</html>\n";
#########################################################################
# GetTime
sub GetTime {
my $hours = shift;
my ($sec,$min,$hour,$mday,$mon,$year,,,) = localtime(); # 86400 seconds is one day
if ($min < 10) { $min = "0$min"}
if ($sec < 10) { $sec = "0$sec"}
if ($hour < 10) { $hour = "0$hour"}
if ($mday < 10) { $mday = "0$mday"}
if ($mon < 10) { $mon = "0$mon"}
my $time = ($year + 1900) . '-' . ++$mon . '-' . $mday . ' ' . $hour . ':' . $min . ':' . $sec;
return $time;
}
#########################################################################
#######################################################################
# read in the Playlist
sub Search {
my $FILE = shift;
my $fields = shift;
my $term = shift;
my @lines;
open (FILE, $FILE) || bail ("Couldn\'t open $FILE: $!");
while (<FILE>) {
if (/$term/i) {
chomp;
push @lines, $_;
}
}
close (FILE) || bail ("Couldn't close $FILE: $!");
return @lines;
}
########################################################################
# *** EncodeURL: %encodes the parameters of the URL
sub EncodeURL {
my $strURL = shift;
$strURL =~ s/(\W)/sprintf("%%%x", ord($1))/eg;
return $strURL;
}
#######################################################################
# Bail: this subrouting dies and displays the error to the browser.
# gotten from the example in the O'Reilly
# _Learning_Perl_on_Win32_Systems_
sub bail {
my $error = "@_";
print "Unexpected Error: $error";
exit;
}
sub Print_Nav
{
open FILE, 'nav.inc' or die "\n\ncouldn't open FILE nav.inc: $!";
while (<FILE>) {
print;
}
close FILE;
}