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

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

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