| version 1.7, 2010/10/28 20:21:29 |
version 1.8, 2011/06/14 16:53:27 |
|
|
| #!/usr/bin/perl |
#!/usr/bin/perl |
| # $RedRiver: playmp3s.pl,v 1.6 2007/02/08 23:02:30 andrew Exp $ |
# $RedRiver: playmp3s.pl,v 1.7 2010/10/28 19:21:29 andrew Exp $ |
| ######################################################################## |
######################################################################## |
| # PlayMP3.pl *** play's MP3s off a playlist using mp3play |
# PlayMP3.pl *** play's MP3s off a playlist using mp3play |
| # |
# |
|
|
| |
|
| my @playlist; |
my @playlist; |
| |
|
| for(;;) { |
for ( ;; ) { |
| # while(1) { |
|
| my $save_playlist; |
|
| |
|
| my ($last_mod) = (stat($cfgs{list}))[9]; |
# while(1) { |
| if ($playlist_last_mod != $last_mod) { |
my $save_playlist; |
| @playlist = (); |
|
| $playlist_last_mod = $last_mod; |
|
| } |
|
| |
|
| while (! @playlist) { |
my ($last_mod) = ( stat( $cfgs{list} ) )[9]; |
| Print_PlayLog("Getting Playlist . . .\n"); |
if ( $playlist_last_mod != $last_mod ) { |
| # bail("getting playlist"); |
@playlist = (); |
| @playlist = get_playlist($cfgs{list}); |
$playlist_last_mod = $last_mod; |
| unless (@playlist) { |
} |
| # bail("getting full playlist"); |
|
| @playlist = get_full_playlist($cfgs{fulllist}); |
|
| |
|
| |
|
| Print_PlayLog("Got full playlist\n"); |
while ( !@playlist ) { |
| $save_playlist = 0; |
Print_PlayLog("Getting Playlist . . .\n"); |
| } else { |
|
| Print_PlayLog("Got normal playlist\n"); |
|
| $save_playlist = 1; |
|
| } |
|
| unless (@playlist) { sleep 10; } |
|
| } |
|
| Print_PlayLog("Got playlist\n"); |
|
| |
|
| Print_PlayLog("getting song to play . . .\n"); |
# bail("getting playlist"); |
| my $song = int rand(scalar(@playlist)); |
@playlist = get_playlist( $cfgs{list} ); |
| my $filename = splice(@playlist,$song,1); |
unless (@playlist) { |
| Print_PlayLog("\tGot $song - filename is\n\t$filename\n"); |
|
| |
|
| Print_PlayLog("displaying file that is playing . . . "); |
# bail("getting full playlist"); |
| DisplayPlaying($cfgs{currenthtml},$filename); |
@playlist = get_full_playlist( $cfgs{fulllist} ); |
| Print_PlayLog("done\n"); |
|
| |
|
| Print_PlayLog("Adding Last. . ."); |
Print_PlayLog("Got full playlist\n"); |
| AddLast($filename, $cfgs{playedlist}, $Num_History, $cfgs{playedhtml}, $cfgs{addurl}); |
$save_playlist = 0; |
| Print_PlayLog("done\n"); |
} |
| |
else { |
| |
Print_PlayLog("Got normal playlist\n"); |
| |
$save_playlist = 1; |
| |
} |
| |
unless (@playlist) { sleep 10; } |
| |
} |
| |
Print_PlayLog("Got playlist\n"); |
| |
|
| if ($save_playlist) { |
Print_PlayLog("getting song to play . . .\n"); |
| Print_PlayLog("Saving Playlist. . ."); |
my $song = int rand( scalar(@playlist) ); |
| save_playlist($cfgs{list},@playlist) || bail("Unable to save playlist!: $!"); |
my $filename = splice( @playlist, $song, 1 ); |
| Print_PlayLog("done\n"); |
Print_PlayLog("\tGot $song - filename is\n\t$filename\n"); |
| } |
|
| |
|
| Print_PlayLog("Playing: $filename . . .\n"); |
Print_PlayLog("displaying file that is playing . . . "); |
| |
DisplayPlaying( $cfgs{currenthtml}, $filename ); |
| my $player; |
Print_PlayLog("done\n"); |
| my $play = "$cfgs{basedir}$filename"; |
|
| if (defined $filename && $filename =~ /\.mp3$/i) { |
|
| $player = $cfgs{mp3play}; |
|
| } elsif ($filename =~ /\.ogg$/i) { |
|
| $player = $cfgs{oggplay}; |
|
| #$play =~ s/(\(|\)|&|"|'| |-)/\\$1/g; |
|
| } |
|
| |
|
| if (not $player =~ s/\{\}/"$play"/g) { |
Print_PlayLog("Adding Last. . ."); |
| $player .= ' "' . $play . '"'; |
AddLast( |
| } |
$filename, $cfgs{playedlist}, $Num_History, |
| Print_PlayLog("$player\n"); |
$cfgs{playedhtml}, $cfgs{addurl} |
| `$player`; |
); |
| |
Print_PlayLog("done\n"); |
| |
|
| # my $kid = 0; |
if ($save_playlist) { |
| # while ($kid ne -1 && ContinueRun()) { |
Print_PlayLog("Saving Playlist. . ."); |
| # while ($kid ne -1) { |
save_playlist( $cfgs{list}, @playlist ) |
| # print "waiting to end . . . "; |
|| bail("Unable to save playlist!: $!"); |
| # my $kid = waitpid(-1,&WNOHANG); |
Print_PlayLog("done\n"); |
| # print "done.\n"; |
} |
| # } |
|
| |
|
| |
Print_PlayLog("Playing: $filename . . .\n"); |
| |
|
| Print_PlayLog("Displaying Nothing . . ."); |
my $player; |
| DisplayPlaying($cfgs{currenthtml},"Nothing"); |
my $play = "$cfgs{basedir}$filename"; |
| Print_PlayLog("done\n"); |
if ( defined $filename && $filename =~ /\.mp3$/i ) { |
| |
$player = $cfgs{mp3play}; |
| |
} |
| |
elsif ( $filename =~ /\.ogg$/i ) { |
| |
$player = $cfgs{oggplay}; |
| |
|
| #@playlist = (); |
#$play =~ s/(\(|\)|&|"|'| |-)/\\$1/g; |
| |
} |
| sleep 1; |
|
| } |
|
| |
|
| |
if ( not $player =~ s/\{\}/"$play"/g ) { |
| |
$player .= ' "' . $play . '"'; |
| |
} |
| |
Print_PlayLog("$player\n"); |
| |
`$player`; |
| |
|
| |
# my $kid = 0; |
| |
# while ($kid ne -1 && ContinueRun()) { |
| |
# while ($kid ne -1) { |
| |
# print "waiting to end . . . "; |
| |
# my $kid = waitpid(-1,&WNOHANG); |
| |
# print "done.\n"; |
| |
# } |
| |
|
| |
Print_PlayLog("Displaying Nothing . . ."); |
| |
DisplayPlaying( $cfgs{currenthtml}, "Nothing" ); |
| |
Print_PlayLog("done\n"); |
| |
|
| |
#@playlist = (); |
| |
|
| |
sleep 1; |
| |
} |
| |
|
| sub Install { |
sub Install { |
| |
|
| # add your additional install messages or functions here |
# add your additional install messages or functions here |
| print "\nThank you for installing this file\n"; |
print "\nThank you for installing this file\n"; |
| } |
} |
| |
|
| sub Remove { |
sub Remove { |
| |
|
| # add your additional remove messages or functions here |
# add your additional remove messages or functions here |
| print "\nSorry you had to leave\n"; |
print "\nSorry you had to leave\n"; |
| } |
} |
| |
|
| sub Help { |
sub Help { |
| |
|
| # add your additional help messages or functions here |
# add your additional help messages or functions here |
| print "\nYou don't really need help do you??\n"; |
print "\nYou don't really need help do you??\n"; |
| } |
} |
|
|
| ######################################################################### |
######################################################################### |
| # GetTime |
# GetTime |
| sub GetTime { |
sub GetTime { |
| my $hours = shift || 0; |
my $hours = shift || 0; |
| my ($sec,$min,$hour,$mday,$mon,$year,,,) = localtime(time - (3600 * $hours)); # 86400 seconds is one day |
my ( $sec, $min, $hour, $mday, $mon, $year,,, ) |
| |
= localtime( time - ( 3600 * $hours ) ); # 86400 seconds is one day |
| if ($min < 10) { $min = "0$min"} |
|
| if ($sec < 10) { $sec = "0$sec"} |
if ( $min < 10 ) { $min = "0$min" } |
| if ($hour < 10) { $hour = "0$hour"} |
if ( $sec < 10 ) { $sec = "0$sec" } |
| if ($mday < 10) { $mday = "0$mday"} |
if ( $hour < 10 ) { $hour = "0$hour" } |
| if ($mon < 10) { $mon = "0$mon"} |
if ( $mday < 10 ) { $mday = "0$mday" } |
| |
if ( $mon < 10 ) { $mon = "0$mon" } |
| my $time = ($year + 1900) . '-' . ++$mon . '-' . $mday . ' ' . $hour . ':' . $min . ':' . $sec; |
|
| return $time; |
my $time |
| |
= ( $year + 1900 ) . '-' |
| |
. ++$mon . '-' |
| |
. $mday . ' ' |
| |
. $hour . ':' |
| |
. $min . ':' |
| |
. $sec; |
| |
return $time; |
| } |
} |
| ######################################################################### |
######################################################################### |
| |
|
| |
|
| |
|
| |
|
| |
|
| ####################################################################### |
####################################################################### |
| # read in the Playlist |
# read in the Playlist |
| sub get_full_playlist { |
sub get_full_playlist { |
| my $FILE = shift; |
my $FILE = shift; |
| my ($last_mod) = (stat($FILE))[9]; |
my ($last_mod) = ( stat($FILE) )[9]; |
| |
|
| if ($Full_Playlist{last_mod} != $last_mod) { |
if ( $Full_Playlist{last_mod} != $last_mod ) { |
| my @list; |
my @list; |
| @list = get_playlist($FILE); |
@list = get_playlist($FILE); |
| |
|
| @list = grep !m#$cfgs{skipregex}#io, @list; |
@list = grep !m#$cfgs{skipregex}#io, @list; |
| |
|
| my @played_list = get_playlist($cfgs{playedlist}); |
my @played_list = get_playlist( $cfgs{playedlist} ); |
| |
|
| my %played; |
my %played; |
| @played{@played_list} = (); |
@played{@played_list} = (); |
| |
|
| delete $Full_Playlist{list}; |
delete $Full_Playlist{list}; |
| |
|
| my $list_size = 0; |
my $list_size = 0; |
| foreach my $song (@list) { |
foreach my $song (@list) { |
| $list_size++; |
$list_size++; |
| $Full_Playlist{list}{$song} = 1 |
$Full_Playlist{list}{$song} = 1 |
| unless (exists $played{$song}); |
unless ( exists $played{$song} ); |
| } |
} |
| my $history = int $list_size * 0.1; |
my $history = int $list_size * 0.1; |
| if ($history) { |
if ($history) { |
| Print_PlayLog("New history is $history\n"); |
Print_PlayLog("New history is $history\n"); |
| $Num_History = $history; |
$Num_History = $history; |
| } |
} |
| |
|
| $Full_Playlist{last_mod} = $last_mod; |
$Full_Playlist{last_mod} = $last_mod; |
| } |
} |
| |
|
| return keys %{ $Full_Playlist{list} }; |
return keys %{ $Full_Playlist{list} }; |
| } |
} |
| ####################################################################### |
####################################################################### |
| |
|
| ####################################################################### |
####################################################################### |
| # read in the Playlist |
# read in the Playlist |
| sub get_playlist { |
sub get_playlist { |
| my $FILE = shift; |
my $FILE = shift; |
| my @lines; |
my @lines; |
| # open PLAYlistLOG, ">c:/ps/playlistlog.txt"; |
|
| |
|
| # print PLAYlistLOG "Getting Playlist from file: $FILE\n"; |
|
| # close PLAYlistLOG; |
|
| if (-e $FILE) { |
|
| open (FILE, $FILE) || bail ("Couldn't open $FILE: $!"); |
|
| chomp (@lines = <FILE>); |
|
| close (FILE) || bail ("Couldn't close $FILE: $!"); |
|
| } else { |
|
| open (FILE, ">$FILE") || return @lines; |
|
| close (FILE) || bail ("Couldn't close $FILE: $!"); |
|
| return @lines; |
|
| } |
|
| return @lines; |
|
| } |
|
| |
|
| |
# open PLAYlistLOG, ">c:/ps/playlistlog.txt"; |
| |
|
| |
# print PLAYlistLOG "Getting Playlist from file: $FILE\n"; |
| |
# close PLAYlistLOG; |
| |
if ( -e $FILE ) { |
| |
open( FILE, $FILE ) || bail("Couldn't open $FILE: $!"); |
| |
chomp( @lines = <FILE> ); |
| |
close(FILE) || bail("Couldn't close $FILE: $!"); |
| |
} |
| |
else { |
| |
open( FILE, ">$FILE" ) || return @lines; |
| |
close(FILE) || bail("Couldn't close $FILE: $!"); |
| |
return @lines; |
| |
} |
| |
return @lines; |
| |
} |
| |
|
| |
|
| ####################################################################### |
####################################################################### |
| # writes back the new playlist |
# writes back the new playlist |
| sub save_playlist { |
sub save_playlist { |
| my $FILE = shift; |
my $FILE = shift; |
| my @lines = @_; |
my @lines = @_; |
| open (FILE, ">$FILE") || bail ("Couldn\'t open playlist to save $FILE: $!"); |
open( FILE, ">$FILE" ) |
| foreach (@lines) { |
|| bail("Couldn\'t open playlist to save $FILE: $!"); |
| print FILE "$_\n"; |
foreach (@lines) { |
| } |
print FILE "$_\n"; |
| close (FILE) || bail ("Couldn't close $FILE: $!"); |
} |
| return 1; |
close(FILE) || bail("Couldn't close $FILE: $!"); |
| |
return 1; |
| } |
} |
| |
|
| |
|
| |
|
| |
|
| ####################################################################### |
####################################################################### |
| # Prints a webpage with the currently playing song |
# Prints a webpage with the currently playing song |
| sub DisplayPlaying { |
sub DisplayPlaying { |
| |
|
| my $htmlfile = shift; |
|
| my $playing = shift; |
|
| |
|
| open BLANK, ">$htmlfile" or bail("Unable to open $htmlfile: $!"); |
my $htmlfile = shift; |
| print BLANK "<html>\n<head>\n\t<title>' . $playing . '</title>\n"; |
my $playing = shift; |
| print BLANK "<meta HTTP-EQUIV=\"REFRESH\" CONTENT=\"5\">\n"; |
|
| print BLANK "<meta HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\">\n"; |
|
| print BLANK "</head>\n"; |
|
| print BLANK '<body leftmargin="0" topmargin="0" ', |
|
| 'marginwidth="0" marginheight="0">', "\n\n"; |
|
| print BLANK "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">\n"; |
|
| print BLANK " <tr>\n"; |
|
| print BLANK " <td align=\"left\"><b><i>Currently playing:</i> $playing</b></td>\n"; |
|
| print BLANK " <td align=\"right\">Started at: " . GetTime() . "</td>\n"; |
|
| print BLANK " </tr>\n"; |
|
| print BLANK "</table>\n"; |
|
| |
|
| |
open BLANK, ">$htmlfile" or bail("Unable to open $htmlfile: $!"); |
| |
print BLANK "<html>\n<head>\n\t<title>' . $playing . '</title>\n"; |
| |
print BLANK "<meta HTTP-EQUIV=\"REFRESH\" CONTENT=\"5\">\n"; |
| |
print BLANK "<meta HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\">\n"; |
| |
print BLANK "</head>\n"; |
| |
print BLANK '<body leftmargin="0" topmargin="0" ', |
| |
'marginwidth="0" marginheight="0">', "\n\n"; |
| |
print BLANK |
| |
"<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">\n"; |
| |
print BLANK " <tr>\n"; |
| |
print BLANK |
| |
" <td align=\"left\"><b><i>Currently playing:</i> $playing</b></td>\n"; |
| |
print BLANK " <td align=\"right\">Started at: " |
| |
. GetTime() |
| |
. "</td>\n"; |
| |
print BLANK " </tr>\n"; |
| |
print BLANK "</table>\n"; |
| |
|
| # print BLANK "<center><b>Currently playing: $playing</b><br>\nStarted at: " . GetTime() . "</center>"; |
# print BLANK "<center><b>Currently playing: $playing</b><br>\nStarted at: " . GetTime() . "</center>"; |
| |
|
| print BLANK "</body>\n</head>\n</html>\n"; |
print BLANK "</body>\n</head>\n</html>\n"; |
| close BLANK || bail("Unable to close BLANK: $!"); |
close BLANK || bail("Unable to close BLANK: $!"); |
| } |
} |
| |
|
| |
|
| |
|
| ####################################################################### |
####################################################################### |
| # Prints a webpage with the previously played song |
# Prints a webpage with the previously played song |
| # AddLast($filename, $cfgs{playedlist}, $Num_History, $cfgs{playedhtml}, $cfgs{addurl}); |
# AddLast($filename, $cfgs{playedlist}, $Num_History, $cfgs{playedhtml}, $cfgs{addurl}); |
| sub AddLast { |
sub AddLast { |
| my $lastsong = shift; |
my $lastsong = shift; |
| my $lastlist = shift; |
my $lastlist = shift; |
| my $history = shift; |
my $history = shift; |
| my $htmlfile = shift; |
my $htmlfile = shift; |
| my $addurl = shift; |
my $addurl = shift; |
| |
|
| my @LIST = get_playlist($lastlist); |
|
| |
|
| DisplayPrevious($htmlfile, $addurl, @LIST) if $htmlfile; |
|
| |
|
| unshift @LIST, $lastsong; |
my @LIST = get_playlist($lastlist); |
| splice (@LIST, $history) if $history; |
|
| save_playlist($lastlist,@LIST); |
|
| |
|
| # Remove song from full list so we don't play it again. |
DisplayPrevious( $htmlfile, $addurl, @LIST ) if $htmlfile; |
| delete $Full_Playlist{list}{$lastsong}; |
|
| } |
|
| |
|
| |
unshift @LIST, $lastsong; |
| |
splice( @LIST, $history ) if $history; |
| |
save_playlist( $lastlist, @LIST ); |
| |
|
| |
# Remove song from full list so we don't play it again. |
| |
delete $Full_Playlist{list}{$lastsong}; |
| |
} |
| |
|
| |
|
| ####################################################################### |
####################################################################### |
| # Prints a webpage with the previously played song |
# Prints a webpage with the previously played song |
| sub DisplayPrevious { |
sub DisplayPrevious { |
| |
|
| my $htmlfile = shift; |
|
| my $addurl = shift; |
|
| my $lastplay = shift; |
|
| my @played = @_; |
|
| open BLANK, ">$htmlfile" or bail("Unable to open $htmlfile: $!"); |
|
| print BLANK "<html>\n<head>\n\t<title>' . $lastplay . '</title>\n"; |
|
| print BLANK "<meta HTTP-EQUIV=\"REFRESH\" CONTENT=\"30\">\n"; |
|
| print BLANK "<meta HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\">\n"; |
|
| print BLANK "<body>\n\n"; |
|
| |
|
| print BLANK "<p>[ <a href=\"bin/ShowFiles.pl\">Beginning</a> | \n"; |
|
| print BLANK "<a href=\"bin/ShowAll.pl\">All MP3's</a> |\n"; |
|
| print BLANK "<a href=\"bin/ShowPlaylist.pl\">Playlist</a> |\n"; |
|
| print BLANK "<a href=\"ShowPlaylist.pl?newlist.lst\">New Files</a> |\n"; |
|
| print BLANK "<a href=\"played.htm\">Previously played</a> ]<p>\n"; |
|
| |
|
| |
my $htmlfile = shift; |
| |
my $addurl = shift; |
| |
my $lastplay = shift; |
| |
my @played = @_; |
| |
open BLANK, ">$htmlfile" or bail("Unable to open $htmlfile: $!"); |
| |
print BLANK "<html>\n<head>\n\t<title>' . $lastplay . '</title>\n"; |
| |
print BLANK "<meta HTTP-EQUIV=\"REFRESH\" CONTENT=\"30\">\n"; |
| |
print BLANK "<meta HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\">\n"; |
| |
print BLANK "<body>\n\n"; |
| |
|
| |
print BLANK "<p>[ <a href=\"bin/ShowFiles.pl\">Beginning</a> | \n"; |
| |
print BLANK "<a href=\"bin/ShowAll.pl\">All MP3's</a> |\n"; |
| |
print BLANK "<a href=\"bin/ShowPlaylist.pl\">Playlist</a> |\n"; |
| |
print BLANK "<a href=\"ShowPlaylist.pl?newlist.lst\">New Files</a> |\n"; |
| |
print BLANK "<a href=\"played.htm\">Previously played</a> ]<p>\n"; |
| |
|
| |
print BLANK "<center><b>Last played: <a href=\"$addurl\?" |
| |
. EncodeURL("$lastplay") |
| |
. "\" target=\"bottom\">$lastplay</a></b><br>\nStarted at: " |
| |
. GetTime() |
| |
. "</center><p>\n"; |
| |
|
| |
print BLANK "before that:<br>\n"; |
| |
|
| print BLANK "<center><b>Last played: <a href=\"$addurl\?" . EncodeURL("$lastplay") . "\" target=\"bottom\">$lastplay</a></b><br>\nStarted at: " . GetTime() . "</center><p>\n"; |
print BLANK "<UL>\n"; |
| |
|
| print BLANK "before that:<br>\n"; |
|
| |
|
| print BLANK "<UL>\n"; |
|
| |
|
| foreach my $song (@played) { |
|
| print BLANK "\t<li>Song: <a href=\"$addurl\?" . EncodeURL("$song") . "\" target=\"bottom\">$song</a></li>\n"; |
|
| } |
|
| |
|
| print BLANK "</UL>\n"; |
|
| |
|
| |
|
| print BLANK "</body>\n</head>\n</html>\n"; |
|
| close BLANK || bail("Unable to close played.htm: $!"); |
|
| } |
|
| |
|
| |
foreach my $song (@played) { |
| |
print BLANK "\t<li>Song: <a href=\"$addurl\?" |
| |
. EncodeURL("$song") |
| |
. "\" target=\"bottom\">$song</a></li>\n"; |
| |
} |
| |
|
| |
print BLANK "</UL>\n"; |
| |
|
| |
print BLANK "</body>\n</head>\n</html>\n"; |
| |
close BLANK || bail("Unable to close played.htm: $!"); |
| |
} |
| |
|
| ######################################################################## |
######################################################################## |
| # *** EncodeURL: %encodes the parameters of the URL |
# *** EncodeURL: %encodes the parameters of the URL |
| sub EncodeURL { |
sub EncodeURL { |
| my $strURL = shift; |
my $strURL = shift; |
| $strURL =~ s/(\W)/sprintf("%%%x", ord($1))/eg; |
$strURL =~ s/(\W)/sprintf("%%%x", ord($1))/eg; |
| return $strURL; |
return $strURL; |
| } |
} |
| |
|
| |
|
| |
|
| ######################################################################## |
######################################################################## |
| # read in config file. |
# read in config file. |
| sub readconfig { |
sub readconfig { |
| my $CONFIG = shift; |
my $CONFIG = shift; |
| my $delimter = shift || '='; |
my $delimter = shift || '='; |
| my %configs; |
my %configs; |
| if (-e $CONFIG) { |
if ( -e $CONFIG ) { |
| open (CONFIG, $CONFIG) or bail ("Couldn\'t open $CONFIG: $!"); |
open( CONFIG, $CONFIG ) or bail("Couldn\'t open $CONFIG: $!"); |
| while (<CONFIG>) { |
while (<CONFIG>) { |
| chomp; # no newline |
chomp; # no newline |
| s/#.*//; # no comments |
s/#.*//; # no comments |
| s/^\s+//; # no leading white space |
s/^\s+//; # no leading white space |
| s/\s+$//; # no trailing white space |
s/\s+$//; # no trailing white space |
| next unless length; # anything left? |
next unless length; # anything left? |
| my ($var, $value) = split(/\s*$delimter\s*/, $_, 2); |
my ( $var, $value ) = split( /\s*$delimter\s*/, $_, 2 ); |
| # $var =~ tr/A-Za-z0-9_\.\,\/\\ / /cd; # delete all the non alphanumerics |
|
| # $value =~ tr/A-Za-z0-9_\/\.\,\\ / /cd; # delete all the non alphanumerics |
# $var =~ tr/A-Za-z0-9_\.\,\/\\ / /cd; # delete all the non alphanumerics |
| $var =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; |
# $value =~ tr/A-Za-z0-9_\/\.\,\\ / /cd; # delete all the non alphanumerics |
| $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; |
$var =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; |
| $configs{$var}=$value; |
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; |
| } |
$configs{$var} = $value; |
| close CONFIG or bail ("Couldn't close $CONFIG: $!"); |
} |
| } else { print '<!-- No config file: ' . $CONFIG; print ' -->'; print "\n"; } |
close CONFIG or bail("Couldn't close $CONFIG: $!"); |
| return %configs; |
} |
| |
else { |
| |
print '<!-- No config file: ' . $CONFIG; |
| |
print ' -->'; |
| |
print "\n"; |
| |
} |
| |
return %configs; |
| } |
} |
| ######################################################################## |
######################################################################## |
| |
|
| |
#sub ForkMP3Player { # This forks the MP3 player. |
| #sub ForkMP3Player { # This forks the MP3 player. |
|
| ## KillPlaying(0); |
## KillPlaying(0); |
| # |
# |
| # my $player = shift; |
# my $player = shift; |
| # my $song = shift; |
# my $song = shift; |
| # |
# |
| # $player =! s/%%f%%/\"$song\"/ig; |
# $player =! s/%%f%%/\"$song\"/ig; |
| # |
# |
| # |
# |
| # FORK: { |
# FORK: { |
| # if ($Mp3Playerpid = fork) { |
# if ($Mp3Playerpid = fork) { |
| # # parent here |
# # parent here |
|
|
| # exec("$player"); |
# exec("$player"); |
| # exit(0); |
# exit(0); |
| # # parent process pid is available with getppid |
# # parent process pid is available with getppid |
| # } elsif ($! =~ /No more process/) { |
# } elsif ($! =~ /No more process/) { |
| # # EAGAIN, supposedly recoverable fork error |
# # EAGAIN, supposedly recoverable fork error |
| # sleep 5; |
# sleep 5; |
| # redo FORK; |
# redo FORK; |
|
|
| # } |
# } |
| #} |
#} |
| |
|
| |
|
| |
|
| |
|
| ####################################################################### |
####################################################################### |
| # Bail: this subrouting dies and displays the error to the browser. |
# Bail: this subrouting dies and displays the error to the browser. |
| # gotten from the example in the O'Reilly |
# gotten from the example in the O'Reilly |
| # _Learning_Perl_on_Win32_Systems_ |
# _Learning_Perl_on_Win32_Systems_ |
| sub bail { |
sub bail { |
| open ERR, '>>$err_log'; |
open ERR, '>>$err_log'; |
| # open ERR, ">>c:/ps/error.txt"; |
|
| |
|
| my $error = "@_"; |
# open ERR, ">>c:/ps/error.txt"; |
| print "Unexpected Error: $error\n"; |
|
| print ERR "Unexpected Error: $error\n"; |
my $error = "@_"; |
| close ERR; |
print "Unexpected Error: $error\n"; |
| # exit; |
print ERR "Unexpected Error: $error\n"; |
| |
close ERR; |
| |
|
| |
# exit; |
| } |
} |
| |
|
| sub Print_PlayLog |
sub Print_PlayLog { |
| { |
open PLAYLOG, ">>/tmp/playlog" or bail("Unable to open PLAYLOG"); |
| open PLAYLOG, ">>/tmp/playlog" or bail("Unable to open PLAYLOG"); |
print GetTime(), "\t", @_; |
| print GetTime(), "\t", @_; |
print PLAYLOG GetTime(), "\t", @_; |
| print PLAYLOG GetTime(), "\t", @_; |
close PLAYLOG; |
| close PLAYLOG; |
|
| } |
} |