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

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

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