version 1.5, 2007/02/08 18:13:33 |
version 1.7, 2010/10/28 20:21:29 |
|
|
#!/usr/bin/perl |
#!/usr/bin/perl |
# $RedRiver: playmp3s.pl,v 1.4 2007/02/08 17:54:38 andrew Exp $ |
# $RedRiver: playmp3s.pl,v 1.6 2007/02/08 23:02:30 andrew Exp $ |
######################################################################## |
######################################################################## |
# PlayMP3.pl *** play's MP3s off a playlist using mp3play |
# PlayMP3.pl *** play's MP3s off a playlist using mp3play |
# |
# |
|
|
|
|
my $err_log = $cfgs{errors} || "/var/log/playmp3s.log"; |
my $err_log = $cfgs{errors} || "/var/log/playmp3s.log"; |
|
|
|
my $Num_History = 0; |
|
|
Print_PlayLog("Beginning playtime\n\n"); |
Print_PlayLog("Beginning playtime\n\n"); |
|
|
|
|
DisplayPlaying($cfgs{currenthtml},$filename); |
DisplayPlaying($cfgs{currenthtml},$filename); |
Print_PlayLog("done\n"); |
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) { |
if ($save_playlist) { |
Print_PlayLog("Saving Playlist. . ."); |
Print_PlayLog("Saving Playlist. . ."); |
save_playlist($cfgs{list},@playlist) || bail("Unable to save playlist!: $!"); |
save_playlist($cfgs{list},@playlist) || bail("Unable to save playlist!: $!"); |
|
|
|
|
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()) { |
|
|
# } |
# } |
|
|
|
|
if ($song) { |
|
Print_PlayLog("Adding Last. . ."); |
|
delete ${ $Full_Playlist{list} }{$song}; |
|
|
|
AddLast($filename, $cfgs{playedlist}, $cfgs{numhistory}, $cfgs{playedhtml}, $cfgs{addurl}); |
|
Print_PlayLog("done\n"); |
|
} |
|
|
|
Print_PlayLog("Displaying Nothing . . ."); |
Print_PlayLog("Displaying Nothing . . ."); |
DisplayPlaying($cfgs{currenthtml},"Nothing"); |
DisplayPlaying($cfgs{currenthtml},"Nothing"); |
Print_PlayLog("done\n"); |
Print_PlayLog("done\n"); |
|
|
my %played; |
my %played; |
@played{@played_list} = (); |
@played{@played_list} = (); |
|
|
|
|
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; |
} |
} |
|
|
|
|
####################################################################### |
####################################################################### |
# Prints a webpage with the previously played song |
# Prints a webpage with the previously played song |
# AddLast($filename, $cfgs{playedlist}, $cfgs{numhistory}, $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 $addurl = shift; |
my $addurl = shift; |
|
|
my @LIST = get_playlist($lastlist); |
my @LIST = get_playlist($lastlist); |
|
|
|
DisplayPrevious($htmlfile, $addurl, @LIST) if $htmlfile; |
|
|
unshift @LIST, $lastsong; |
unshift @LIST, $lastsong; |
splice (@LIST, $history); |
splice (@LIST, $history) if $history; |
save_playlist($lastlist,@LIST); |
save_playlist($lastlist,@LIST); |
DisplayPrevious($htmlfile, $addurl, @LIST); |
|
|
# Remove song from full list so we don't play it again. |
|
delete $Full_Playlist{list}{$lastsong}; |
} |
} |
|
|
|
|