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

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

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

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