=================================================================== RCS file: /cvs/mp3/daemon/playmp3s.pl,v retrieving revision 1.1.1.1 retrieving revision 1.7 diff -u -r1.1.1.1 -r1.7 --- mp3/daemon/playmp3s.pl 2006/03/02 23:20:48 1.1.1.1 +++ mp3/daemon/playmp3s.pl 2010/10/28 20:21:29 1.7 @@ -1,4 +1,5 @@ #!/usr/bin/perl +# $RedRiver: playmp3s.pl,v 1.6 2007/02/08 23:02:30 andrew Exp $ ######################################################################## # PlayMP3.pl *** play's MP3s off a playlist using mp3play # @@ -12,16 +13,14 @@ use vars qw/ %cfgs /; -#use strict qw/ $cfgs{list} @playlist $cfgs{mp3play} $filename $cfgs{basedir} $cfgs{htmldir} /; -#use diagnostics; - my $config_file = shift || "/etc/playmp3s.conf"; +my %cfgs = readconfig($config_file); + my $err_log = $cfgs{errors} || "/var/log/playmp3s.log"; -my %cfgs = readconfig($config_file); +my $Num_History = 0; - Print_PlayLog("Beginning playtime\n\n"); my %Full_Playlist; @@ -65,9 +64,13 @@ Print_PlayLog("\tGot $song - filename is\n\t$filename\n"); Print_PlayLog("displaying file that is playing . . . "); - DisplayPlaying($cfgs{htmldir},$filename); + DisplayPlaying($cfgs{currenthtml},$filename); Print_PlayLog("done\n"); + Print_PlayLog("Adding Last. . ."); + AddLast($filename, $cfgs{playedlist}, $Num_History, $cfgs{playedhtml}, $cfgs{addurl}); + Print_PlayLog("done\n"); + if ($save_playlist) { Print_PlayLog("Saving Playlist. . ."); save_playlist($cfgs{list},@playlist) || bail("Unable to save playlist!: $!"); @@ -76,15 +79,20 @@ Print_PlayLog("Playing: $filename . . .\n"); + my $player; + my $play = "$cfgs{basedir}$filename"; if (defined $filename && $filename =~ /\.mp3$/i) { - `$cfgs{mp3play} \"$cfgs{basedir}$filename\"`; + $player = $cfgs{mp3play}; } elsif ($filename =~ /\.ogg$/i) { - my $play = "$cfgs{basedir}$filename"; - $play =~ s/(\(|\)|&|"|'| |-)/\\$1/g; - print "\n\n$play\n\n"; - `$cfgs{oggplay} $play`; + $player = $cfgs{oggplay}; + #$play =~ s/(\(|\)|&|"|'| |-)/\\$1/g; } + if (not $player =~ s/\{\}/"$play"/g) { + $player .= ' "' . $play . '"'; + } + Print_PlayLog("$player\n"); + `$player`; # my $kid = 0; # while ($kid ne -1 && ContinueRun()) { @@ -95,16 +103,8 @@ # } - if ($song) { - Print_PlayLog("Adding Last. . ."); - delete ${ $Full_Playlist{list} }{$song}; - - AddLast($filename, $cfgs{playedlist}, $cfgs{numhistory}, $cfgs{htmldir}, $cfgs{addurl}); - Print_PlayLog("done\n"); - } - Print_PlayLog("Displaying Nothing . . ."); - DisplayPlaying($cfgs{htmldir},"Nothing"); + DisplayPlaying($cfgs{currenthtml},"Nothing"); Print_PlayLog("done\n"); #@playlist = (); @@ -166,13 +166,19 @@ my %played; @played{@played_list} = (); - delete $Full_Playlist{list}; + my $list_size = 0; foreach my $song (@list) { + $list_size++; $Full_Playlist{list}{$song} = 1 unless (exists $played{$song}); } + my $history = int $list_size * 0.1; + if ($history) { + Print_PlayLog("New history is $history\n"); + $Num_History = $history; + } $Full_Playlist{last_mod} = $last_mod; } @@ -225,10 +231,10 @@ # Prints a webpage with the currently playing song sub DisplayPlaying { - my $htmldir = shift; - my $playing = shift; + my $htmlfile = shift; + my $playing = shift; - open BLANK, ">$htmldir/current.htm" or bail("Unable to open current.htm: $!"); + open BLANK, ">$htmlfile" or bail("Unable to open $htmlfile: $!"); print BLANK "\n\n\t' . $playing . '\n"; print BLANK "\n"; print BLANK "\n"; @@ -252,19 +258,24 @@ ####################################################################### # Prints a webpage with the previously played song -# AddLast($filename, $cfgs{playedlist}, $cfgs{numhistory}, $cfgs{htmldir}, $cfgs{addurl}); +# AddLast($filename, $cfgs{playedlist}, $Num_History, $cfgs{playedhtml}, $cfgs{addurl}); sub AddLast { my $lastsong = shift; my $lastlist = shift; - my $history = shift; - my $htmldir = shift; - my $addurl = shift; + my $history = shift; + my $htmlfile = shift; + my $addurl = shift; my @LIST = get_playlist($lastlist); + + DisplayPrevious($htmlfile, $addurl, @LIST) if $htmlfile; + unshift @LIST, $lastsong; - splice (@LIST, $history); + splice (@LIST, $history) if $history; save_playlist($lastlist,@LIST); - DisplayPrevious($htmldir, $addurl, @LIST); + + # Remove song from full list so we don't play it again. + delete $Full_Playlist{list}{$lastsong}; } @@ -274,11 +285,11 @@ # Prints a webpage with the previously played song sub DisplayPrevious { - my $htmldir = shift; - my $addurl = shift; + my $htmlfile = shift; + my $addurl = shift; my $lastplay = shift; - my @played = @_; - open BLANK, ">$htmldir/played.htm" or bail("Unable to open $htmldir/played.htm: $!"); + my @played = @_; + open BLANK, ">$htmlfile" or bail("Unable to open $htmlfile: $!"); print BLANK "\n\n\t' . $lastplay . '\n"; print BLANK "\n"; print BLANK "\n";