[BACK]Return to search.pl CVS log [TXT][DIR] Up to [local] / mp3 / bin

Annotation of mp3/bin/search.pl, Revision 1.4

1.1       andrew      1: #!/usr/bin/perl -w
1.4     ! andrew      2: # $RedRiver: search.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/ $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:
1.4     ! andrew     89:        print $Query->submit(-name=>'Submit', -value=>'Play All');
        !            90:
        !            91:        print $Query->submit(-name=>'Submit', -value=>'Approve All') if $prefix;
        !            92:
        !            93:         print $Query->end_form, "\n";;
1.1       andrew     94:
                     95:        #List_Recipes(%recipes);
                     96:
                     97:
                     98:        if (@playlist) {
                     99:                my $counter;
                    100:
                    101:                foreach my $filename (@playlist) {
1.3       andrew    102:                        print "\t<li><a href=\"$exe\?" . EncodeURL($prefix) . '&' . EncodeURL($filename) . "\" target=\"bottom\">$filename</a>";
                    103:                        print " - <a href=\"$exe\?" . EncodeURL($prefix) . '&' . EncodeURL($filename) . '&' . EncodeURL('fulllist.lst') . "\" target=\"bottom\">Approve</a>";
                    104:                        print "</li>\n";
1.1       andrew    105:                        $counter++;
                    106:                }
                    107:                print "<H3>Total displayed: $counter</h3>\n";
                    108:        } else {
                    109:                print "\t<li>Nothing in list</li>\n";
                    110:        }
                    111: }
                    112:
                    113:
                    114:
                    115: print "</UL>\n</body>\n</head>\n</html>\n";
                    116:
                    117:
                    118:
                    119:
                    120:
                    121:
                    122:
                    123:
                    124:
                    125:
                    126:
                    127:
                    128:
                    129:
                    130:
                    131:
                    132: #########################################################################
                    133: # GetTime
                    134: sub GetTime {
                    135:        my $hours = shift;
                    136:        my ($sec,$min,$hour,$mday,$mon,$year,,,) = localtime(); # 86400 seconds is one day
                    137:
                    138:        if ($min  < 10) { $min  = "0$min"}
                    139:        if ($sec  < 10) { $sec  = "0$sec"}
                    140:        if ($hour < 10) { $hour = "0$hour"}
                    141:        if ($mday < 10) { $mday = "0$mday"}
                    142:        if ($mon  < 10) { $mon  = "0$mon"}
                    143:
                    144:        my $time = ($year + 1900) . '-' . ++$mon . '-' . $mday  . ' ' . $hour . ':' . $min . ':' . $sec;
                    145:        return $time;
                    146: }
                    147: #########################################################################
                    148:
                    149:
                    150:
                    151:
                    152:
                    153: #######################################################################
                    154: # read in the Playlist
                    155: sub Search {
                    156:        my $FILE = shift;
                    157:        my $fields = shift;
                    158:        my $term = shift;
                    159:        my @lines;
                    160:        open (FILE, $FILE) || bail ("Couldn\'t open $FILE: $!");
                    161:        while (<FILE>) {
                    162:                if (/$term/i) {
                    163:                        chomp;
                    164:                        push @lines, $_;
                    165:                }
                    166:        }
                    167:        close (FILE) || bail ("Couldn't close $FILE: $!");
                    168:        return @lines;
                    169: }
                    170:
                    171:
                    172:
                    173:
                    174: ########################################################################
                    175: # *** EncodeURL: %encodes the parameters of the URL
                    176: sub EncodeURL {
                    177:        my $strURL = shift;
                    178:        $strURL =~ s/(\W)/sprintf("%%%x", ord($1))/eg;
                    179:        return $strURL;
                    180: }
                    181:
                    182:
                    183:
                    184:
                    185: #######################################################################
                    186: # Bail: this subrouting dies and displays the error to the browser.
                    187: # gotten from the example in the O'Reilly
                    188: # _Learning_Perl_on_Win32_Systems_
                    189: sub bail {
                    190:        my $error = "@_";
                    191:        print "Unexpected Error: $error";
                    192:        exit;
                    193: }
                    194:
                    195:
                    196: sub Print_Nav
                    197: {
                    198:        open FILE, 'nav.inc' or die "\n\ncouldn't open FILE nav.inc: $!";
                    199:        while (<FILE>) {
                    200:                print;
                    201:        }
                    202:        close FILE;
                    203: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>