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

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

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

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