#!/usr/bin/perl ################################################# ################################################# ################################################# # The web-based flash mp3player # version 052305 # Gigfoot LLC # James True ################################################# # MP3_BIN # The default for this to run smooth is that this script # reside inside the folder where your mp3 files exist. # If you want to change this, you may specify an # absolute directory path where your mp3files are found. # examples are "/home/you/web/mp3" or "c:/IIS/web/shares/" etc # If you change the MP3_BIN you will need to also change to MP3_BIN_URL accordingly. # Hint, MP3_BIN_URL will usually be your absolute MP3_BIN without the DOCUMENT_ROOT at the front. # ALWAYS end both of these variables with a slash (/). # Change at your own risk and rock on. my $MP3_BIN = ""; my $MP3_BIN_URL = ""; ################################################# # START_PAGE # This is optional, set this to a url if you do not # want this program to decide on your start page. # The start page is the url displayed in the main frames window my $START_PAGE = ""; ################################################# # BG_COLOR # if you want to override the random colors you can specify a hex color below. # Example: $BG_COLOR = ""; = RANDOM # Example: $BG_COLOR = "FF0000"; = ALWAYS RED # Example: $BG_COLOR = "00FF00"; = ALWAYS GREEN # Example: $BG_COLOR = "0000FF"; = ALWAYS BLUE my $BG_COLOR = ""; ################################################# # RECURSE # if your mp3 files are stored inside of seperate subfolders # turn on FOLDER_RECURSE to have it scan the subfolders for a new song # Example: 0 = off 1 = on my $FOLDER_RECURSE = 0; ################################################# # SECURITY # UNIX,LINUX,MACOSX servers may be able to provide # extra security by enabling CHMODING. This turns # the file permissions off for all mp3 files cept # the one currently being played. If you turn this # feature on, make sure your player is working properly on your server! # 1 = on | 0 = off my $SECURITY_CHMOD = 0; ################################################# # AUTOCOMPLETE # used mainly by folks who are running their player out of a cgi-bin folder # If auto-complete is on, you can request a mp3song by the title of the mp3 only. # This only works if you pass an src variable with no slashes in it. # So if AUTO_COMPLETE_URL is set to 1 then the url below will work # http://www.yourdomain.com/cgi-bin/mp3player.cgi?src=Acoustic Syndicate - secret track.mp3 my $AUTO_COMPLETE = 1; ################################################# ################################################# ### End of user defined section ################################################# ################################################# use strict;##### strick means if you see an internal server error, check your logs for complete details :) #use LWP::Simple; use Cwd; print "Content-type:text/html\n\n"; my $debug = ""; my %MYENV = &initENV; my %GET = &readGet; if (($AUTO_COMPLETE)&&($GET{'src'})&&($GET{'src'} !~ /[\\\/]+/)){$GET{'src'} = $MP3_BIN_URL.$GET{'src'};} ################################################# ################################################# ################################################# if ($SECURITY_CHMOD){&SecureFiles();} &readGet; if ($GET{'action'} eq ""){$GET{'action'} = "frames";} if ($GET{'action'} eq "Info"){&Info();exit;} #if ($GET{'action'} eq "Visual"){&Visual();exit;} if ($GET{'action'} eq "Playlist"){&Playlist();exit;} if ($GET{'action'} eq "Playlist2"){&Playlist2();exit;} if ($GET{'action'} eq "Search"){&Search();exit;} if ($GET{'action'} eq "frames"){&frames();exit;} if ($GET{'action'} eq "frames2"){&frames2();exit;} if ($GET{'action'} eq "framesvisual"){&framesvisual();exit;} if ($GET{'action'} eq "PlaylistFrames"){&PlaylistFrames();exit;} if ($GET{'action'} eq "mp3frame"){&mp3frame();exit;} if ($GET{'action'} eq "mp3frame2"){&mp3frame2();exit;} if ($GET{'action'} eq "mp3framevisual"){&mp3framevisual();exit;} exit; ################################################# ################################################# ################################################# sub AllowFile{ chmod (0755,$_[0]); }########################################### end AllowFile sub SecureFiles{ ## turn off all permissions for mp3 file to prrevent users from downloading my @sec; if ($FOLDER_RECURSE){ @sec = &RecurseMP3($MP3_BIN); }else{ @sec = &ReadContent($MP3_BIN,'\.mp3'); } foreach my $file(@sec){ chmod (0700,"$MP3_BIN$file"); } }########################################### end SecureFiles #sub Visual{ ## OUTPUT a numeric representation of this song to the flash environment #if (!$GET{'VMETHOD'}){$GET{'VMETHOD'} = "SINGLE";} #my %MP; #print "//
Output Flash readable code for this mp3 src\n";
#if ($GET{'src'}){
##%MP = &DescribeMP3($GET{'src'});
#print "&VMETHOD=$GET{'VMETHOD'}&\n";
#print "&viznotes=V:$MP{'VERSION'} L:$MP{'LAYER'} M:$MP{'MODE'}&\n";
#print "&bsize=".(-s "$GET{'src'}")."&\n";
#my $xx;
#if ($GET{'VMETHOD'} eq "SINGLE"){$xx = &SINGLE(%MP);}
#foreach my $li(keys %MP){
#my $clsrc = $MP{$li};
#$clsrc =~ s/\&/\%26/g;
#print "&$li=$clsrc&\n";
#}
#print "&xx=".$xx."&\n";
#}#################
#print "&vloaded=1&\n";
#print "//
\n"; #exit; #}############################################### end Visual sub SINGLE{ my %MP = @_; my $str; for(my $tt=0;$tt<$MP{'SECS'};$tt++){ my @sec; my $startSeek = ($MP{'BYTES_PER_SECOND'}*($tt+1))+$MP{'START_SOUND'}; while(($#sec+1)<=20){ ################## local $/ = \1; my $scnt; open (FILE,"$GET{'src'}"); seek(FILE,$startSeek,0); while (my $zline = ){$scnt++; $zline = unpack 'c2', $zline; $zline = $zline+128; $zline = int(($zline*100)/256); if ($GET{'debug'}){print "
  • $zline\n";} push(@sec,$zline); $startSeek = $startSeek+($MP{'BYTES_PER_SECOND'}*($#sec+2))+1; last; }close FILE; ################## my $vl = $tt; $vl =~ s/.*(.)$/$1/; push(@sec,$vl); } $str .= join("|",@sec)."|"; } $str =~ s/\|$//; return $str; }################################################# end SINGLE #sub DescribeMP3{ #my $file = $_[0]; #my %OUT; #$OUT{'src'} = $file; #use MP3::Info qw(:all); #my $info = get_mp3info($file) or ($OUT{'ERROR'} = "get_mp3info $1 $! $_"); #if ($OUT{'ERROR'}){return %OUT;} #foreach my $ky(keys %$info){ #$OUT{$ky} = $info->{$ky}; #my $kvv = $info->{$ky}; #$kvv =~ s/\&/\%26/g; #} #$OUT{'BYTES_PER_SECOND'} = ($OUT{'SIZE'}/$OUT{'SECS'}); #$OUT{'START_SOUND'} = (-s $file)-$OUT{'SIZE'}; #my $tag = get_mp3tag($file) or ($OUT{'ERROR'} = "get_mp3tag $1 $! $_"); #if ($OUT{'ERROR'}){return %OUT;} #foreach my $ky(keys %$tag){ #$OUT{$ky} = $tag->{$ky}; #my $kv = $OUT{$ky};$kv =~ s/\&/\%26/g; #} #return %OUT; #}################################### end DescribeMP3 sub frames{ ##########################action=$GET{'action'}&shuffle=$GET{'shuffle'}&reload=$GET{'reload'}&autoStart=$GET{'autoStart'}&src=$src my $auto = ""; if ($ENV{'QUERY_STRING'} !~ /\&/){ $auto = "y"; $GET{'shuffle'} = "y"; $GET{'autoStart'} = "y"; $GET{'reload'} = "y"; } if (!$GET{'startPage'}){$GET{'startPage'} = $START_PAGE;} if (!$GET{'startPage'}){$GET{'startPage'} = $ENV{'HTTP_REFERER'};} if (!$GET{'startPage'}){$GET{'startPage'} = "http://$ENV{'SERVER_NAME'}";} if ($GET{'bgColor'}){$GET{'bgColor'} = "bgColor=$GET{'bgColor'}";} if ($GET{'vol'}){$GET{'vol'} = "vol=$GET{'vol'}";} print <MP3 Player / $ENV{'SERVER_NAME'} <body> <p>This Page Requires Frames.</p> </body> EOM }################################################## end frames sub framesvisual{ ##########################action=$GET{'action'}&shuffle=$GET{'shuffle'}&reload=$GET{'reload'}&autoStart=$GET{'autoStart'}&src=$src my $auto = ""; if ($ENV{'QUERY_STRING'} !~ /\&/){ $auto = "y"; $GET{'shuffle'} = "y"; $GET{'autoStart'} = "y"; $GET{'reload'} = "y"; } if (!$GET{'startPage'}){$GET{'startPage'} = $START_PAGE;} if (!$GET{'startPage'}){$GET{'startPage'} = $ENV{'HTTP_REFERER'};} if (!$GET{'startPage'}){$GET{'startPage'} = "http://$ENV{'SERVER_NAME'}";} if ($GET{'bgColor'}){$GET{'bgColor'} = "bgColor=$GET{'bgColor'}";} my $tm = time; print <MP3 Player / $ENV{'SERVER_NAME'} <body> <p>This Page Requires Frames.</p> </body> EOM }################################################## end framesvisual sub frames2{ ##########################action=$GET{'action'}&shuffle=$GET{'shuffle'}&reload=$GET{'reload'}&autoStart=$GET{'autoStart'}&src=$src my $auto = ""; if ($ENV{'QUERY_STRING'} !~ /\&/){ $auto = "y"; $GET{'shuffle'} = "y"; $GET{'autoStart'} = "y"; $GET{'reload'} = "y"; } if ($GET{'vol'}){$GET{'vol'} = "&vol=$GET{'vol'}&";} if (!$GET{'startPage'}){$GET{'startPage'} = $START_PAGE;} if (!$GET{'startPage'}){$GET{'startPage'} = $ENV{'HTTP_REFERER'};} if (!$GET{'startPage'}){$GET{'startPage'} = "http://$ENV{'SERVER_NAME'}";} if ($GET{'bgColor'}){$GET{'bgColor'} = "bgColor=$GET{'bgColor'}";} my $tm = time; print <MP3 Player / $ENV{'SERVER_NAME'} <body> <p>This Page Requires Frames.</p> </body> EOM }################################################## end frames2 sub PlaylistFrames{ ##########################action=$GET{'action'}&shuffle=$GET{'shuffle'}&reload=$GET{'reload'}&autoStart=$GET{'autoStart'}&src=$src my $auto = ""; if ($ENV{'QUERY_STRING'} !~ /\&/){ $auto = "y"; $GET{'shuffle'} = "y"; $GET{'autoStart'} = "y"; $GET{'reload'} = "y"; } if (!$GET{'startPage'}){$GET{'startPage'} = $START_PAGE;} if (!$GET{'startPage'}){$GET{'startPage'} = $ENV{'HTTP_REFERER'};} if (!$GET{'startPage'}){$GET{'startPage'} = "http://$ENV{'SERVER_NAME'}";} if ($GET{'bgColor'}){$GET{'bgColor'} = "bgColor=$GET{'bgColor'}";} print <MP3 Player / $ENV{'SERVER_NAME'} <body> <p>This Page Requires Frames.</p> </body> EOM }################################################## end PlaylistFrames sub mp3framevisual{ #my %GET = %_; my @mp3s; my @cnt; ##print "$MP3_BIN cnt=$#cnt
    "; if ($FOLDER_RECURSE){ @cnt = &RecurseMP3($MP3_BIN); }else{ @cnt = &ReadContent($MP3_BIN,'\.mp3'); } my $LIBRARY_TOTAL = $#cnt+1; my $nowx = 0; my $emptymp3; my $st; my $src; my $srcX; if ($GET{'src'}){$src = $GET{'src'};} my $lastSrc = $GET{'lastSrc'}; my $lastSrcPattern; $lastSrc =~ s/.*\///; $srcX = $src; $srcX =~ s/.*\///; my @dcnt = @cnt; if ($lastSrc eq ""){$lastSrcPattern = "BLAGGABLUGGABLOOGA";}else{$lastSrcPattern = "$lastSrc";} foreach my $of(@dcnt){ if ($of =~ /\.mp3$/i){ $emptymp3 = $of; my $cof = $of; my $clastSrcPattern = $lastSrcPattern; $cof =~ s/\W+//g; $clastSrcPattern =~ s/\W+//g; if ($cof !~ /$clastSrcPattern/i){ push (@mp3s,$of); } $of =~ s/\W+//g; my $srcD = $src; $srcD =~ s/\W+//g; my $srcXD = $srcX; $srcXD =~ s/\W+//g; my $lastSrcD = $lastSrc; $lastSrcD =~ s/\W+//g; if (($srcXD)&&($of =~ /$srcXD$/i)){$st = $nowx;} if (($lastSrcD)&&($of =~ /$lastSrcD$/i)){$st = $nowx;} $nowx++; } } if ($st > $#mp3s){$st = 0;} if ($src eq ""){$src = "".$mp3s[$st];$srcX = $mp3s[$st]; } if ($src eq ""){$src = $emptymp3;} #$GET{'src'} = $src; my $tPlaylist = "y"; my $tShuffle = "y"; my $tReload = "y"; my $tAutoStart = "y"; my $tPlaylistStyle = "blon"; my $tShuffleStyle = "BlackLinks"; my $tReloadStyle = "BlackLinks"; my $tAutoStartStyle = "BlackLinks"; if ($GET{'shuffle'}){$src = $mp3s[rand($#mp3s)];$tShuffle = "";$tShuffleStyle = "blon";} if ($GET{'reload'}){$tReload = "";$tReloadStyle = "blon";} if ($GET{'autoStart'}){$tAutoStart = "";$tAutoStartStyle = "blon";} ##### my %newQ = (); my $qstr = "$ENV{'QUERY_STRING'}"; my @qs = split(/\&/,$qstr); foreach my $li(@qs){ my($ln,$lv)=split(/\=/,$li); #print "$li / $ln==$lv
    "; $newQ{$ln} = $lv; } my $cleanQ = ""; foreach my $li(keys %newQ){ if ($li){$cleanQ .= "$li=".$newQ{$li}."&";} } $ENV{'QUERY_STRING'} = $cleanQ; my @colors = ("333333","9f0000","009f00","9f0000","9f009f","0000aa","dddddd","af64af","646464","98aa99"); my $bgColor; if ($GET{'bgColor'} eq ""){$bgColor = $colors[rand($#colors)];$GET{'bgColor'} = $bgColor;}else{$bgColor = $GET{'bgColor'};} if ($BG_COLOR){$bgColor = $BG_COLOR;} my $srcQ = $MP3_BIN_URL.$src; $srcQ =~ s/\%/\%25/g; $srcQ =~ s/\+/\%2B/g; $srcQ =~ s/\&/\%26/g; $srcQ =~ s/\#/\%23/g; $srcQ =~ s/\~/\%7E/g; $srcQ =~ s/\'/\%27/g; $srcQ =~ s/\(/\%28/g; $srcQ =~ s/\)/\%29/g; $srcQ =~ s/\-/\%2D/g; $srcQ =~ s/\=/\%3D/g; $srcQ =~ tr/ /+/; $src = $srcQ; if ($GET{'src'}){$src = $GET{'src'};} $src =~ s/\&/\%26/g; $tPlaylist = <Playlist EOM $tShuffle = <Shuffle EOM $tReload = <Reload EOM $tAutoStart = <AutoStart EOM print < a.blon:link{font-family:tahoma;text-decoration:underline;color:$bgColor;} a.blon:visited{font-family:tahoma;text-decoration:underline;color:$bgColor;} a.blon:hover{font-family:tahoma;text-decoration:underline;color:ff0000;} a.BlackLinks:link{font-family:tahoma;text-decoration:none;color:$bgColor;} a.BlackLinks:visited{font-family:tahoma;text-decoration:none;color:$bgColor;} a.BlackLinks:hover{font-family:tahoma;text-decoration:none;color:ff0000;}
    $tPlaylist / $tReload / $tAutoStart / $tShuffle / Next Song / Hide MP3 Player
    EOM }################################################## end mp3framevisual sub mp3frame{ #my %GET = %_; my @mp3s; my @cnt; ##print "$MP3_BIN cnt=$#cnt
    "; if ($FOLDER_RECURSE){ @cnt = &RecurseMP3($MP3_BIN); }else{ @cnt = &ReadContent($MP3_BIN,'\.mp3'); } my $LIBRARY_TOTAL = $#cnt+1; my $nowx = 0; my $emptymp3; my $st; my $src; my $srcX; if ($GET{'src'}){$src = $GET{'src'};} my $lastSrc = $GET{'lastSrc'}; my $lastSrcPattern; $lastSrc =~ s/.*\///; $srcX = $src; $srcX =~ s/.*\///; my @dcnt = @cnt; if ($lastSrc eq ""){$lastSrcPattern = "BLAGGABLUGGABLOOGA";}else{$lastSrcPattern = "$lastSrc";} foreach my $of(@dcnt){ if ($of =~ /\.mp3$/i){ $emptymp3 = $of; my $cof = $of; my $clastSrcPattern = $lastSrcPattern; $cof =~ s/\W+//g; $clastSrcPattern =~ s/\W+//g; if ($cof !~ /$clastSrcPattern/i){ push (@mp3s,$of); } $of =~ s/\W+//g; my $srcD = $src; $srcD =~ s/\W+//g; my $srcXD = $srcX; $srcXD =~ s/\W+//g; my $lastSrcD = $lastSrc; $lastSrcD =~ s/\W+//g; if (($srcXD)&&($of =~ /$srcXD$/i)){$st = $nowx;} if (($lastSrcD)&&($of =~ /$lastSrcD$/i)){$st = $nowx;} $nowx++; } } if ($st > $#mp3s){$st = 0;} if ($src eq ""){$src = "".$mp3s[$st];$srcX = $mp3s[$st]; } if ($src eq ""){$src = $emptymp3;} #$GET{'src'} = $src; my $tPlaylist = "y"; my $tShuffle = "y"; my $tReload = "y"; my $tAutoStart = "y"; my $tPlaylistStyle = "blon"; my $tShuffleStyle = "BlackLinks"; my $tReloadStyle = "BlackLinks"; my $tAutoStartStyle = "BlackLinks"; if ($GET{'shuffle'}){$src = $mp3s[rand($#mp3s)];$tShuffle = "";$tShuffleStyle = "blon";} if ($GET{'reload'}){$tReload = "";$tReloadStyle = "blon";} if ($GET{'autoStart'}){$tAutoStart = "";$tAutoStartStyle = "blon";} ##### my %newQ = (); my $qstr = "$ENV{'QUERY_STRING'}"; my @qs = split(/\&/,$qstr); foreach my $li(@qs){ my($ln,$lv)=split(/\=/,$li); #print "$li / $ln==$lv
    "; $newQ{$ln} = $lv; } my $cleanQ = ""; foreach my $li(keys %newQ){ if ($li){$cleanQ .= "$li=".$newQ{$li}."&";} } $ENV{'QUERY_STRING'} = $cleanQ; my @colors = ("333333","9f0000","009f00","9f0000","9f009f","0000aa","dddddd","af64af","646464","98aa99"); my $bgColor; if ($GET{'bgColor'} eq ""){$bgColor = $colors[rand($#colors)];$GET{'bgColor'} = $bgColor;}else{$bgColor = $GET{'bgColor'};} if ($BG_COLOR){$bgColor = $BG_COLOR;} if ($SECURITY_CHMOD){&AllowFile("$MP3_BIN$src");} my $srcQ = $MP3_BIN_URL.$src; $srcQ =~ s/\%/\%25/g; $srcQ =~ s/\+/\%2B/g; $srcQ =~ s/\&/\%26/g; $srcQ =~ s/\#/\%23/g; $srcQ =~ s/\~/\%7E/g; $srcQ =~ s/\'/\%27/g; $srcQ =~ s/\(/\%28/g; $srcQ =~ s/\)/\%29/g; $srcQ =~ s/\-/\%2D/g; $srcQ =~ s/\=/\%3D/g; $srcQ =~ tr/ /+/; $src = $srcQ; if ($GET{'src'}){$src = $GET{'src'};} $src =~ s/\&/\%26/g; $tPlaylist = <Playlist EOM $tShuffle = <Shuffle EOM $tReload = <Reload EOM $tAutoStart = <AutoStart EOM my $volmod; if ($GET{'vol'}){$volmod = "vol=$GET{'vol'}";} print < a.blon:link{font-family:tahoma;text-decoration:underline;color:$bgColor;} a.blon:visited{font-family:tahoma;text-decoration:underline;color:$bgColor;} a.blon:hover{font-family:tahoma;text-decoration:underline;color:ff0000;} a.BlackLinks:link{font-family:tahoma;text-decoration:none;color:$bgColor;} a.BlackLinks:visited{font-family:tahoma;text-decoration:none;color:$bgColor;} a.BlackLinks:hover{font-family:tahoma;text-decoration:none;color:ff0000;}
    $tPlaylist / $tReload / $tAutoStart / $tShuffle / Next Song / Hide MP3 Player
    EOM }################################################## end mp3frame sub mp3frame2{ my @mp3s; my @cnt; if ($FOLDER_RECURSE){ @cnt = &RecurseMP3($MP3_BIN); }else{ @cnt = &ReadContent($MP3_BIN,'\.mp3'); } my $LIBRARY_TOTAL = $#cnt+1; my $nowx = 0; my $emptymp3; my $st; my $src; my $srcX; if ($GET{'src'}){$src = $GET{'src'};} my $lastSrc = $GET{'lastSrc'}; my $lastSrcPattern; $lastSrc =~ s/.*\///; $srcX = $src; $srcX =~ s/.*\///; my @dcnt = @cnt; if ($lastSrc eq ""){$lastSrcPattern = "BLAGGABLUGGABLOOGA";}else{$lastSrcPattern = "$lastSrc";} foreach my $of(@dcnt){ if ($of =~ /\.mp3$/i){ $emptymp3 = $of; my $cof = $of; my $clastSrcPattern = $lastSrcPattern; $cof =~ s/\W+//g; $clastSrcPattern =~ s/\W+//g; if ($cof !~ /$clastSrcPattern/i){ push (@mp3s,$of); } $of =~ s/\W+//g; my $srcD = $src; $srcD =~ s/\W+//g; my $srcXD = $srcX; $srcXD =~ s/\W+//g; my $lastSrcD = $lastSrc; $lastSrcD =~ s/\W+//g; if (($srcXD)&&($of =~ /$srcXD$/i)){$st = $nowx;} if (($lastSrcD)&&($of =~ /$lastSrcD$/i)){$st = $nowx;} $nowx++; } } if ($st > $#mp3s){$st = 0;} if ($src eq ""){$src = "".$mp3s[$st];$srcX = $mp3s[$st]; } if ($src eq ""){$src = $emptymp3;} #$GET{'src'} = $src; my $tPlaylist = "y"; my $tShuffle = "y"; my $tReload = "y"; my $tAutoStart = "y"; my $tPlaylistStyle = "blon"; my $tShuffleStyle = "BlackLinks"; my $tReloadStyle = "BlackLinks"; my $tAutoStartStyle = "BlackLinks"; if ($GET{'shuffle'}){$src = $mp3s[rand($#mp3s)];$tShuffle = "";$tShuffleStyle = "blon";} if ($GET{'reload'}){$tReload = "";$tReloadStyle = "blon";} if ($GET{'autoStart'}){$tAutoStart = "";$tAutoStartStyle = "blon";} ##### my %newQ = (); my $qstr = "$ENV{'QUERY_STRING'}"; my @qs = split(/\&/,$qstr); foreach my $li(@qs){ my($ln,$lv)=split(/\=/,$li); $newQ{$ln} = $lv; } my $cleanQ = ""; foreach my $li(keys %newQ){ if ($li){$cleanQ .= "$li=".$newQ{$li}."&";} } $ENV{'QUERY_STRING'} = $cleanQ; my @colors = ("333333","9f0000","009f00","9f0000","9f009f","0000aa","dddddd","af64af","646464","98aa99"); my $bgColor; if ($GET{'bgColor'} eq ""){$bgColor = $colors[rand($#colors)];$GET{'bgColor'} = $bgColor;}else{$bgColor = $GET{'bgColor'};} if ($BG_COLOR){$bgColor = $BG_COLOR;} my $srcQ = $MP3_BIN_URL.$src; $srcQ =~ s/\%/\%25/g; $srcQ =~ s/\+/\%2B/g; $srcQ =~ s/\&/\%26/g; $srcQ =~ s/\#/\%23/g; $srcQ =~ s/\~/\%7E/g; $srcQ =~ s/\'/\%27/g; $srcQ =~ s/\(/\%28/g; $srcQ =~ s/\)/\%29/g; $srcQ =~ s/\-/\%2D/g; $srcQ =~ s/\=/\%3D/g; $srcQ =~ tr/ /+/; $src = $srcQ; if ($GET{'src'}){$src = $GET{'src'};} $src =~ s/\&/\%26/g; $tPlaylist = <Playlist EOM $tShuffle = <Shuffle EOM $tReload = <Reload EOM $tAutoStart = <AutoStart EOM if ($GET{'vol'} =~ /^\d+$/){ $GET{'vol'} = "&vol=$GET{'vol'}&"; } print < a.blon:link{font-family:tahoma;text-decoration:underline;color:$bgColor;} a.blon:visited{font-family:tahoma;text-decoration:underline;color:$bgColor;} a.blon:hover{font-family:tahoma;text-decoration:underline;color:ff0000;} a.BlackLinks:link{font-family:tahoma;text-decoration:none;color:$bgColor;} a.BlackLinks:visited{font-family:tahoma;text-decoration:none;color:$bgColor;} a.BlackLinks:hover{font-family:tahoma;text-decoration:none;color:ff0000;}
    $tPlaylist / $tReload / $tAutoStart / $tShuffle / Next Song / Hide MP3 Player
    EOM }################################################## end mp3frame2 sub Search{ my $FONT = "font-family:arial;"; my $COL1 = "background-color:#AAAA00;"; my $COL2 = "background-color:#CCCC00;"; my $borders = <= 1){ $GET{'RESULT'} = "Results found: $fnd"; &Playlist2; }else{ $RESULT = "No results found"; } } print <MP3 Player Playlist
    Search
    $RESULT
    Search
    EOM exit; }################################# end Search sub Playlist2{ my @playlist; my $SHOW_TITLE = 1; my $SHOW_SIZE = 1; my $SHOW_MODIFIED = 1; my $SHOW_CREATED = 0; my $SHOW_CNT = 1; my $COL; my $FONT = "font-family:arial;"; my $COL1 = "background-color:#998899;"; my $COL2 = "background-color:#887788;"; my $borders = <All Songs / EOM } my $LIBRARY_TOTAL = $#playlist+1; my @RECURSE_TITLE = ("Off","On"); print <MP3 Player Playlist EOM if ($SHOW_CNT){print "";} foreach my $field(@fields){my $vl = eval("\$SHOW_$field");if ($vl){print "";}}print "\n"; my $cnt; foreach my $mp3(@playlist){$cnt++; my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = stat("$MP3_BIN$mp3"); my $mp3q = $mp3; $mp3q =~ s/\&/\%26/g; $mp3q =~ s/\s+/\+/g; if ($COL eq "$COL2"){$COL = "$COL1";}else{$COL = "$COL2";} if ($SHOW_CNT){print "\n";} if ($SHOW_TITLE){print "\n";} if ($SHOW_SIZE){$size = &DescribeSize($size);print "\n";} if ($SHOW_MODIFIED){$mtime = &Epoch2Style($mtime,"mon/dat/yr time");print "\n";} if ($SHOW_CREATED){$ctime = &Epoch2Style($ctime,"mon/dat/yr time");print "\n";} print ""; } print < 
    MP3Player Playlist $smodSearch Playlist
    $GET{'RESULT'}
     $field
    $cnt$mp3$size$mtime$ctime
    EOM exit; }################################################## end Playlist2 sub Info{ my @playlist; if ($FOLDER_RECURSE){ @playlist = &RecurseMP3($MP3_BIN); }else{ @playlist = &ReadContent($MP3_BIN,'\.mp3'); } my $LIBRARY_TOTAL = $#playlist+1; my @RECURSE_TITLE = ("Off","On"); print <MP3 Player Info
    MP3 Player Info
    MP3_BIN:$MP3_BIN
    TOTAL SONGS:$LIBRARY_TOTAL
    FOLDER_RECURSE:$RECURSE_TITLE[$FOLDER_RECURSE]
    EOM foreach my $mp3(@playlist){ print "
  • $mp3\n"; } exit; }################################################## end Info sub Playlist{ my @playlist; my $SHOW_TITLE = 1; my $SHOW_SIZE = 1; my $SHOW_MODIFIED = 1; my $SHOW_CREATED = 0; my $SHOW_CNT = 1; my $COL; my $FONT = "font-family:arial;"; my $COL1 = "background-color:#AAAA00;"; my $COL2 = "background-color:#CCCC00;"; my $borders = <MP3 Player Playlist EOM if ($SHOW_CNT){print "";} foreach my $field(@fields){my $vl = eval("\$SHOW_$field");if ($vl){print "";}}print "\n"; my $cnt; foreach my $mp3(@playlist){$cnt++; my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = stat("$MP3_BIN$mp3"); if ($COL eq "$COL2"){$COL = "$COL1";}else{$COL = "$COL2";} if ($SHOW_CNT){print "\n";} if ($SHOW_TITLE){print "\n";} if ($SHOW_SIZE){$size = &DescribeSize($size);print "\n";} if ($SHOW_MODIFIED){$mtime = &Epoch2Style($mtime,"mon/dat/yr time");print "\n";} if ($SHOW_CREATED){$ctime = &Epoch2Style($ctime,"mon/dat/yr time");print "\n";} print ""; } print < 
    MP3Player Playlist
     $field
    $cnt$mp3$size$mtime$ctime
    EOM exit; }################################################## end Playlist sub DescribeSize{ my $bytes = $_[0]; my $val = 0;my $size = 0;my $kilobytes = 0;my $megabytes = 0;my $gigabytes = 0; my $fmat = "b"; if ($bytes > 1024){$val = $bytes/1024;$fmat = "k";$kilobytes = $bytes/1024;} if ($bytes > (1024*1024)){$val = $bytes/(1024*1024);$fmat = "M";$megabytes = $bytes/(1024*1024);} if ($bytes > (1024*1024*1024)){$val = $bytes/(1024*1024*1024);$fmat = "G";$gigabytes = $bytes/(1024*1024*1024);} $val =~ s/\.(.).*/\.$1/; if (($_[0] > 0)&&($_[0] < 1025)){$val = 1;$fmat = "k";} $val = "$val $fmat"; if ($val eq "0 b"){$val = "";} return $val; }#################################### end DescribeSize sub Epoch2Style{ my $tima = $_[0]; my $template = $_[1]; my %TIM = (); $TIM{'time'} = $tima; $TIM{'template'} = $template; $TIM{'date'} = localtime($TIM{'time'}); my($dow,$mon,$dat,$tim,$yer)=split(/\s+/,$TIM{'date'}); my $yr = $yer;$yr =~ s/^\d\d//; my($hr,$min,$sec)=split(/\:/,$tim); my $time24 = $tim; $time24 =~ s/\D+//g; my($hr24,$min24,$sec24)=split(/\:/,$tim); my $mer = "am";if ($hr > 11){$mer = "pm";$hr = $hr - 12;} $hr =~ s/^0//; my $monthid = &GetMonthID("$mon"); my $monthvalue = "00".$monthid; $monthvalue =~ s/.*(..)$/$1/; my $datevalue = "00".$dat; $datevalue =~ s/.*(..)$/$1/; my $hrv = "00".$hr; $hrv =~ s/.*(..)$/$1/; my $minv = "00".$min; $minv =~ s/.*(..)$/$1/; $TIM{'template'} =~ s/mmm/$mon/g; $TIM{'template'} =~ s/timestamp/$yer$monthvalue$datevalue$time24/gi; $TIM{'template'} =~ s/month/$mon/g; $TIM{'template'} =~ s/mon/$mon/g; $TIM{'template'} =~ s/mm/$monthid/g; $TIM{'template'} =~ s/mv/$monthvalue/g; $TIM{'template'} =~ s/dd/$dat/g; $TIM{'template'} =~ s/hv/$hrv/g; $TIM{'template'} =~ s/hrv/$hrv/g; $TIM{'template'} =~ s/time24/$hr24$min24$sec24/g; $TIM{'template'} =~ s/hr24/$hr24/g; $TIM{'template'} =~ s/min24/$min24/g; $TIM{'template'} =~ s/sec24/$sec24/g; $TIM{'template'} =~ s/hr/$hr/g; $TIM{'template'} =~ s/minv/$minv/g; $TIM{'template'} =~ s/min/$min/g; $TIM{'template'} =~ s/sec/$sec/g; $TIM{'template'} =~ s/mer/$mer/g; $TIM{'template'} =~ s/datevalue/$datevalue/g; $TIM{'template'} =~ s/datvalue/$datevalue/g; $TIM{'template'} =~ s/datv/$datevalue/g; $TIM{'template'} =~ s/dv/$datevalue/g; $TIM{'template'} =~ s/date/$dat/g; $TIM{'template'} =~ s/dat/$dat/g; $TIM{'template'} =~ s/year/$yer/gi; $TIM{'template'} =~ s/yr/$yr/gi; $TIM{'template'} =~ s/yy/$yr/gi; $TIM{'template'} =~ s/dow/$dow/g; $TIM{'template'} =~ s/time/$tim/g; #20040203200000 if ($TIM{'template'} =~ /mysql/){ my $monthid = &GetMonthID("$mon"); my $dateid = "00".$dat;$dateid =~ s/.*(\d\d)$/$1/; my $hourid = "00".$hr;$hourid =~ s/.*(\d\d)$/$1/; my $minid = "00".$min;$minid =~ s/.*(\d\d)$/$1/; my $secid = "00".$sec;$secid =~ s/.*(\d\d)$/$1/; my $mysql = $yer.$monthid.$dateid.$hourid.$minid.$secid; $TIM{'template'} =~ s/mysql/$mysql/g; } return $TIM{'template'}; }################################ end Epoch2Style sub GetMonthID{ my $month = $_[0]; my $month_id; my @month_titles = ("January","February","March","April","May","June","July","August","September","October","November","December"); my $Y = 0; foreach my $month_title(@month_titles){$Y++; if ($month_title =~ /$month/i){$month_id = $Y;} } return $month_id; }##################################### end GetMonthID sub RecurseMP3{ my @playlist = &ReadContent($MP3_BIN,'\.mp3'); my %PLIST; foreach my $song(@playlist){$PLIST{$song} = 1;} my @FOLDERS = &Recurse($MP3_BIN); my $RECURSE; foreach my $subf(@FOLDERS){ my @subdir = &ReadContent($subf,'\.mp3'); $RECURSE .= "
  • $subf=".($#subdir+1)."\n"; my $apend = $subf; $apend =~ s/^$MP3_BIN//; if ($MP3_BIN =~ /\\/){$apend .= "\\";}else{$apend .= "/";} foreach my $submp3(@subdir){ if (!$PLIST{$submp3}){push(@playlist,$apend.$submp3);} } } return @playlist; }################################################## end RecurseMP3 sub Recurse{ my $path = $_[0]; my $req = $_[1]; my @subs = (); my @dir = &ReadContent("$path"); if ($path =~ /\\/){#### are we using the downhill slash in our path? $path =~ s/\\+$//; foreach my $ld(@dir){ if (-d $path."\\".$ld){ push (@subs,$path."\\".$ld); my @asubs = &Recurse("$path\\$ld"); foreach my $ald(@asubs){if (-d $ald){push(@subs,$ald);}} } } }else{#### then do it the nice unix way $path =~ s/\/+$//; foreach my $ld(@dir){ if (-d $path."/".$ld){ push (@subs,$path."/".$ld); my @asubs = &Recurse("$path/$ld"); foreach my $ald(@asubs){if (-d $ald){push(@subs,$ald);}} } } } return @subs; }####################################### end Recurse sub ReadContent{ my $content = $_[0]; my $qrequire = $_[1]; my @content = (); if (!$content){return;} if (-d "$content"){ opendir Tdir, "$content"; my $dir = readdir(Tdir); while($dir = readdir(Tdir)){chomp $dir; if ($dir eq ".."){}else{if ($qrequire){if ($dir =~ /$qrequire/i){push (@content,"$dir");}}else{push (@content,"$dir");}} }close Tdir; }else{ open (FILE,$content); #flock(FILE,LOCK_EX); while (){chomp $_; push (@content,$_); } #flock(FILE,LOCK_UN); close FILE; } return @content; }##################################### end ReadContent sub ReadContentOLD{ my $content = $_[0]; my @content=(); if (-d "$content"){ opendir Tdir, "$content"; my $dir = readdir(Tdir); while($dir = readdir(Tdir)){chomp $dir; if ($dir eq ".."){}else{push (@content,"$dir");} }close Tdir; }else{ open (FILE,"$content"); while (){chomp $_; push (@content,"$_"); }close FILE; } return @content; }##################################### end ReadContent sub readGet{ my %GET = (); if ($ENV{'QUERY_STRING'} =~ /lastSrc\=(.*)/){$GET{'ZlastSrc'} = $1; $GET{'ZlastSrc'} =~ tr/+/ /; $GET{'ZlastSrc'} =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; } if ($ENV{'QUERY_STRING'}){ my $qstring= $ENV{'QUERY_STRING'}; my @get = split(/\&/,$qstring); foreach (@get){ my ($qname,$qvalue)=split(/=/,$_,2); $qvalue =~ tr/+/ /; $qvalue =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $GET{$qname} = $qvalue; } } if ($ARGV[0] =~ /^\w\:[\\|\/]/){ #print "YO"; $GET{'drop'} = $ARGV[0]; $ARGV[0] = ""; foreach (@ARGV){ my @line = split(/\=/,$_,2); if ($line[0]){ $GET{'drop'} .= ",".$line[0]; } } @ARGV = (); } if (@ARGV){ foreach (@ARGV){ my @line = split(/\=/,$_,2); if ($line[0]){ $GET{$line[0]} = $line[1]; } } } if ($GET{'ZlastSrc'}){$GET{'lastSrc'} = $GET{'ZlastSrc'};} return %GET; }################################ sub initENV{ my %MYENV = (); my $this_dir = cwd."/".$0; if ($0 =~ /^[a-zA-Z]\:/){$this_dir = $0;} $this_dir =~ s/(.*)([\/|\\]+)[^\/|\\]+$/$1$2/; if ($this_dir eq ""){print "Failed to find a working directory path=$this_dir\n";exit;} $this_dir =~ s/[\/|\\]+$//; $this_dir =~ s/\\+/\//g; $MYENV{'this_dir'} = "$this_dir"; if ($ENV{'SERVER_NAME'}){ $MYENV{'this_cgi'} = "http://$ENV{'SERVER_NAME'}$ENV{'SCRIPT_NAME'}"; $MYENV{'this_url'} = $MYENV{'this_cgi'}; $MYENV{'this_url'} =~ s/\/[^\/]+$//; } return %MYENV; }######################################## end initENV