[BACK]Return to playmp3s.pl CVS log [TXT][DIR] Up to [local] / mp3 / daemon

Diff for /mp3/daemon/playmp3s.pl between version 1.1 and 1.6

version 1.1, 2006/03/02 23:20:48 version 1.6, 2007/02/08 23:02:30
Line 1 
Line 1 
 #!/usr/bin/perl  #!/usr/bin/perl
   # $RedRiver: playmp3s.pl,v 1.5 2007/02/08 18:13:33 andrew Exp $
 ########################################################################  ########################################################################
 # PlayMP3.pl *** play's MP3s off a playlist using mp3play  # PlayMP3.pl *** play's MP3s off a playlist using mp3play
 #  #
Line 12 
Line 13 
   
 use vars qw/ %cfgs /;  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 $config_file = shift || "/etc/playmp3s.conf";
   
   my %cfgs = readconfig($config_file);
   
 my $err_log = $cfgs{errors} || "/var/log/playmp3s.log";  my $err_log = $cfgs{errors} || "/var/log/playmp3s.log";
   
 my %cfgs = readconfig($config_file);  my $Num_History = 0;
   
   
 Print_PlayLog("Beginning playtime\n\n");  Print_PlayLog("Beginning playtime\n\n");
   
 my %Full_Playlist;  my %Full_Playlist;
Line 65 
Line 64 
                 Print_PlayLog("\tGot $song - filename is\n\t$filename\n");                  Print_PlayLog("\tGot $song - filename is\n\t$filename\n");
   
                 Print_PlayLog("displaying file that is playing . . . ");                  Print_PlayLog("displaying file that is playing . . . ");
                 DisplayPlaying($cfgs{htmldir},$filename);                  DisplayPlaying($cfgs{currenthtml},$filename);
                 Print_PlayLog("done\n");                  Print_PlayLog("done\n");
   
                 if ($save_playlist) {                  if ($save_playlist) {
Line 76 
Line 75 
   
                 Print_PlayLog("Playing: $filename . . .\n");                  Print_PlayLog("Playing: $filename . . .\n");
   
                   my $player;
                   my $play = "$cfgs{basedir}$filename";
                 if (defined $filename && $filename =~ /\.mp3$/i) {                  if (defined $filename && $filename =~ /\.mp3$/i) {
                         `$cfgs{mp3play} \"$cfgs{basedir}$filename\"`;                          $player = $cfgs{mp3play};
                 } elsif ($filename =~ /\.ogg$/i) {                  } elsif ($filename =~ /\.ogg$/i) {
                         my $play = "$cfgs{basedir}$filename";                          $player = $cfgs{oggplay};
                         $play =~ s/(\(|\)|&|"|'| |-)/\\$1/g;                          #$play =~ s/(\(|\)|&|"|'| |-)/\\$1/g;
                         print "\n\n$play\n\n";  
                         `$cfgs{oggplay} $play`;  
                 }                  }
   
                   if (not $player =~ s/\{\}/"$play"/g) {
                           $player .= ' "' . $play . '"';
                   }
                   Print_PlayLog("$player\n");
                   `$player`;
   
   
 #       my $kid = 0;  #       my $kid = 0;
 #    while ($kid ne -1 && ContinueRun()) {  #    while ($kid ne -1 && ContinueRun()) {
 #     while ($kid ne -1) {  #     while ($kid ne -1) {
Line 99 
Line 104 
                         Print_PlayLog("Adding Last. . .");                          Print_PlayLog("Adding Last. . .");
                         delete ${ $Full_Playlist{list} }{$song};                          delete ${ $Full_Playlist{list} }{$song};
   
                         AddLast($filename, $cfgs{playedlist}, $cfgs{numhistory}, $cfgs{htmldir}, $cfgs{addurl});                          AddLast($filename, $cfgs{playedlist}, $Num_History, $cfgs{playedhtml}, $cfgs{addurl});
                         Print_PlayLog("done\n");                          Print_PlayLog("done\n");
                 }                  }
   
                 Print_PlayLog("Displaying Nothing . . .");                  Print_PlayLog("Displaying Nothing . . .");
                 DisplayPlaying($cfgs{htmldir},"Nothing");                  DisplayPlaying($cfgs{currenthtml},"Nothing");
                 Print_PlayLog("done\n");                  Print_PlayLog("done\n");
   
                 #@playlist = ();                  #@playlist = ();
Line 169 
Line 174 
   
                 delete $Full_Playlist{list};                  delete $Full_Playlist{list};
   
                   my $list_size = 0;
                 foreach my $song (@list) {                  foreach my $song (@list) {
                           $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;
                   if ($history) {
                           Print_PlayLog("New history is $history\n");
                           $Num_History = $history;
                   }
   
                 $Full_Playlist{last_mod} = $last_mod;                  $Full_Playlist{last_mod} = $last_mod;
         }          }
Line 225 
Line 237 
 # Prints a webpage with the currently playing song  # Prints a webpage with the currently playing song
 sub DisplayPlaying {  sub DisplayPlaying {
   
         my $htmldir = shift;          my $htmlfile = shift;
         my $playing = 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 "<html>\n<head>\n\t<title>' . $playing . '</title>\n";          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=\"REFRESH\" CONTENT=\"5\">\n";
         print BLANK "<meta HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\">\n";          print BLANK "<meta HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\">\n";
Line 252 
Line 264 
   
 #######################################################################  #######################################################################
 # Prints a webpage with the previously played song  # 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 {  sub AddLast {
         my $lastsong = shift;          my $lastsong = shift;
         my $lastlist = shift;          my $lastlist = shift;
         my $history = shift;          my $history  = shift;
         my $htmldir = shift;          my $htmlfile = shift;
         my $addurl = shift;          my $addurl   = shift;
   
         my @LIST = get_playlist($lastlist);          my @LIST = get_playlist($lastlist);
         unshift @LIST, $lastsong;          unshift @LIST, $lastsong;
         splice (@LIST, $history);          splice (@LIST, $history) if $history;
         save_playlist($lastlist,@LIST);          save_playlist($lastlist,@LIST);
         DisplayPrevious($htmldir, $addurl, @LIST);          DisplayPrevious($htmlfile, $addurl, @LIST);
 }  }
   
   
Line 274 
Line 286 
 # Prints a webpage with the previously played song  # Prints a webpage with the previously played song
 sub DisplayPrevious {  sub DisplayPrevious {
   
         my $htmldir = shift;          my $htmlfile = shift;
         my $addurl = shift;          my $addurl   = shift;
         my $lastplay = shift;          my $lastplay = shift;
         my @played = @_;          my @played   = @_;
         open BLANK, ">$htmldir/played.htm" or bail("Unable to open $htmldir/played.htm: $!");          open BLANK, ">$htmlfile" or bail("Unable to open $htmlfile: $!");
         print BLANK "<html>\n<head>\n\t<title>' . $lastplay . '</title>\n";          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=\"REFRESH\" CONTENT=\"30\">\n";
         print BLANK "<meta HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\">\n";          print BLANK "<meta HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\">\n";

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.6

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