X-Git-Url: http://git.ipfire.org/?a=blobdiff_plain;f=html%2Fcgi-bin%2Fmpfire.cgi;h=6cec8ff338c06e8458e77796e3d24e08ff53e10c;hb=81da1b01e95ec7a99513116f816b1fc9ef500b2a;hp=b7ac0ccba879144d950c07fa38fe57b1b97fdf14;hpb=8c384f979d49e282c05f72eafdfae0cf20814b88;p=people%2Fteissler%2Fipfire-2.x.git
diff --git a/html/cgi-bin/mpfire.cgi b/html/cgi-bin/mpfire.cgi
index b7ac0ccba..6cec8ff33 100644
--- a/html/cgi-bin/mpfire.cgi
+++ b/html/cgi-bin/mpfire.cgi
@@ -20,10 +20,20 @@
###############################################################################
use strict;
+
# enable only the following on debugging purpose
#use warnings;
#use CGI::Carp 'fatalsToBrowser';
+# use the special mpd POD and the encode POD to handle the utf8 scalars
+use Audio::MPD;
+use Encode;
+
+# initiate the connector for the mpd POD, mpd must be running on locahost
+# port 6600 without authentication
+my $mpd = Audio::MPD->new('localhost',6600,'','$REUSE');
+my $work = $mpd->status()->updating_db();
+
require '/var/ipfire/general-functions.pl';
require "${General::swroot}/lang.pl";
require "${General::swroot}/header.pl";
@@ -34,373 +44,597 @@ my %mpfiresettings = ();
my %checked = ();
my $message = '0';
my $errormessage = "";
+my @songs;
&General::readhash("${General::swroot}/main/settings", \%mainsettings);
&General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
&Header::showhttpheaders();
-sub refreshpage{&Header::openbox( 'Waiting', 1, "" );print "
$Lang::tr{'pagerefresh'}
";&Header::closebox();}
+if ( $ENV{'QUERY_STRING'} =~ /title/){
+
+################################################################################
+# $ENV{'QUERY_STRING'} =~ /title/ is used to handle the inline iframe used to
+# display the current song playing ( artist - title - album aso )
+# the cgi call´s itself with a parameter and the iframe refreshes itself without
+# reloading the whole page
+################################################################################
+
+ my $number = $mpd->status()->song()+1;
+ my $volume = $mpd->status()->volume();
+ my $random = $mpd->status()->random();
+
+ if ($random eq "0" ){
+ $random="off";
+ }else{
+ $random="on";
+ }
+
+ my $repeat = $mpd->status()->repeat();
+ if ($repeat eq "0" ){
+ $repeat="off";
+ }else{
+ $repeat="on";
+ }
+
+ my $song = "";
+ if ( $mpd->current() )
+ {
+ $song = substr("-= ".$mpd->current()->Artist()." | ".$mpd->current()->Title(),0,85)." =- ";
+ if ( $song eq "-= | =- " ){
+ $song = "None "
+ };
+ $song .= $mpd->current()->Track()."# ".substr($mpd->current()->Album(),0,90)." ";
+ }else{
+ $song = "None
";
+ exit;
+}elsif ( $ENV{'QUERY_STRING'} =~ /control/){
+
+################################################################################
+# $ENV{'QUERY_STRING'} =~ /control/ is used to handle the inline iframe used to
+# display the control button ( prev play skip stop toggle aso )
+# the cgi call´s itself with a parameter and only the iframe is reloaded on click
+################################################################################
+
+ &Header::getcgihash(\%mpfiresettings);
+ if ( $mpfiresettings{'ACTION'} eq "playall" ){
+ $mpd->playlist->clear();
+ foreach ($mpd->collection->all_pathes){
+ $mpd->playlist->add($_);
+ }
+ $mpd->play();
+ }elsif ($mpfiresettings{'ACTION'} eq "x" ){
+ $mpd->stop();
+ }elsif ( $mpfiresettings{'ACTION'} eq "|>" ){
+ $mpd->pause();
+ }elsif ( $mpfiresettings{'ACTION'} eq "<<" ){
+ $mpd->prev();
+ }elsif ( $mpfiresettings{'ACTION'} eq ">>" ){
+ $mpd->next();
+ }elsif ( $mpfiresettings{'ACTION'} eq "+" ){
+ $mpd->volume('+5');
+ }elsif ( $mpfiresettings{'ACTION'} eq "-" ){
+ $mpd->volume('-5');
+ }elsif ( $mpfiresettings{'ACTION'} eq "++" ){
+ $mpd->volume('+10');
+ }elsif ( $mpfiresettings{'ACTION'} eq "--" ){
+ $mpd->volume('-10');
+ }elsif ( $mpfiresettings{'ACTION'} eq ">" ){
+ $mpd->play();
+ }elsif ( $mpfiresettings{'ACTION'} eq "repeat" ){
+ $mpd->repeat();
+ }elsif ( $mpfiresettings{'ACTION'} eq "shuffle" ){
+ $mpd->random();
+ }
+ print <
+
+
+
+
+
+
+
+
+
+
+
+END
+;
+ print <
+
+
+
+
+
+
+
+
+
+END
+;
+ exit;
+}
-$mpfiresettings{'PAGE'} = "1";
+# just a little subpage to handle automatic page refresh on demand ( 1 sec )
+sub refreshpage{
+ &Header::openbox( 'Waiting', 1, "" );
+ print "
$Lang::tr{'pagerefresh'}
";
+ &Header::closebox();
+}
-open(DATEI, "<${General::swroot}/mpfire/db/mpd.db") || die "No Database found";
-my @songdb = ;
-close(DATEI);
+# if the mpd is updating his database because of user interaction then the cgi
+# should display that the mpd is unavailable, and refresh the status every 5 seconds
+if ($work ne ""){
+ &Header::openpage($Lang::tr{'mpfire'}, 1,);
+ &Header::openbigbox('100%', 'left', '', $errormessage);
+ &Header::openbox( 'Waiting', 5, "" );
+ print "
END
;
&Header::closebox();
+if ( $mpfiresettings{'FRAME'} eq "quick playlist" )
+{
&Header::openbox('100%', 'center', $Lang::tr{'quick playlist'});
-
+# box to quickly select artist, album, year or genre and play the selection
print "
";
+&Header::closebox();
+}
+
+if ( $mpfiresettings{'FRAME'} eq "webradio" )
+{
+&Header::openbox('100%', 'center', $Lang::tr{'mpfire webradio'});
+# box to select some webradio´s to be played by one click
+open(DATEI, "<${General::swroot}/mpfire/webradio") || die "Could not open playlist";
+my @webradio = ;
+close(DATEI);
+
+print <
+
";
}
-foreach (keys(%songs)){
- if (!($i >= $begin && $i <= $end)){
-# print $begin."->".$i."<-".$end."\n";
- $i++;next;}
- my @song = split(/\|/,$songs{$_});
- my $minutes = sprintf ("%.0f", $song[1] / 60 );
- my $seconds = $song[1] % 60;
-
- if ($lines % 2) {print "
";} else {print "
";}
- print <
-
$song[2] $song[3]
-
$song[5]
-
$song[4]
-
$song[6]
-
$song[7]
-
$minutes:$seconds
+
+print <
http://
+
+
+
+
END
;
- $lines++;
- $i++;
- }
print "
";
&Header::closebox();
}
&Header::openbox('100%', 'center', $Lang::tr{'mpfire playlist'});
-
+# box to show the current playlist given from mpc system command
my @playlist = `mpc playlist 2>/dev/null`;
print <
-
-
-
-
+
+
+
+
+
-
-
-
-
-
+
+
+
+
+
+
END
;
-&Header::closebox();
-
-&Header::openbox('100%', 'center', $Lang::tr{'mpfire webradio'});
-open(DATEI, "<${General::swroot}/mpfire/webradio") || die "Could not open playlist";
-my @webradio = ;
-close(DATEI);
-
-print <
-