X-Git-Url: http://git.ipfire.org/?a=blobdiff_plain;f=html%2Fcgi-bin%2Fmpfire.cgi;h=6cec8ff338c06e8458e77796e3d24e08ff53e10c;hb=4715ddb3f0d6119c7e5e4df74126a84dab5ab756;hp=cc2237ab01566f34212907c2138ea8681dc6e576;hpb=19f5a6cc72e1c8d72f11994474da03a9a56d0455;p=ipfire-2.x.git
diff --git a/html/cgi-bin/mpfire.cgi b/html/cgi-bin/mpfire.cgi
index cc2237ab01..6cec8ff338 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,361 +44,598 @@ 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 "
Database is updating, please be patient.
";
+ &Header::closebox();
+ &Header::closebigbox();
+ &Header::closepage();
+ exit;
+}
-my @artist; my @album; my @genre; my @year; my $linecount = 0; my @currentsong = ""; my %songs;
-foreach (@songdb){
-
- if ( $_ =~ /mtime: / ){
- $songs{$currentsong[1]}="$currentsong[2]|$currentsong[3]|$currentsong[4]|$currentsong[5]|$currentsong[6]|$currentsong[7]|$currentsong[8]|$currentsong[9]";
- push(@artist,$currentsong[4]);
- push(@album,$currentsong[6]);
- push(@year,$currentsong[8]);
- push(@genre,$currentsong[9]);
- @currentsong = "";
- }
- elsif ( $_ =~ /key: / || $_ =~ /file: / || $_ =~ /Time: / || $_ =~ /Artist: / || $_ =~ /Title: / || $_ =~ /Album: / || $_ =~ /Track: / || $_ =~ /Date: / || $_ =~ /Genre: / ){
- my @temp = split(/: /,$_);
- push(@currentsong,$temp[1]);
- }
- else {
- next;
- }
- }
-
- my %hash = map{ $_, 1 }@artist;
- @artist = sort keys %hash;
- my %hash = map{ $_, 1 }@album;
- @album = sort keys %hash;
- my %hash = map{ $_, 1 }@year;
- @year = sort keys %hash;
- my %hash = map{ $_, 1 }@genre;
- @genre = sort keys %hash;
-
- my $artistcount = $#artist+1;
- my $albumcount = $#album+1;
- my $yearcount = $#year+1;
- my $genrecount = $#genre+1;
+if ( $mpfiresettings{'PAGE'} eq "" ){ $mpfiresettings{'PAGE'} = "1";};
+if ( $mpfiresettings{'FRAME'} eq "" ){$mpfiresettings{'FRAME'} = "webradio";};
&Header::getcgihash(\%mpfiresettings);
-&Header::openpage($Lang::tr{'mpfire'}, 1, "");
+&Header::openpage($Lang::tr{'mpfire'}, 1,);
&Header::openbigbox('100%', 'left', '', $errormessage);
############################################################################################################################
######################################## Scanne Verzeichnisse nach Mp3 Dateien #############################################
-if ( $mpfiresettings{'ACTION'} eq "scan" )
-{
-delete $mpfiresettings{'__CGI__'};delete $mpfiresettings{'x'};delete $mpfiresettings{'y'};delete $mpfiresettings{'PAGE'};
-&General::writehash("${General::swroot}/mpfire/settings", \%mpfiresettings);
-open(DATEI, "<${General::swroot}/mpfire/mpd.conf") || die "Datei nicht gefunden";
-my @Zeilen = ;
-close(DATEI);
-open(DATEI, ">${General::swroot}/mpfire/mpd.conf") || die "Datei nicht gefunden";
-foreach (@Zeilen){
-if ( $_ =~ /music_directory/){print DATEI "music_directory \"".$mpfiresettings{'MUSICDIR'}."\"\n";}
-else {print DATEI $_;}
-}
-close(DATEI);
-
-$message=system("/usr/local/bin/mpfirectrl scan");
-refreshpage();
-}
-elsif ( $mpfiresettings{'ACTION'} eq ">" ){$message=system("/usr/local/bin/mpfirectrl","play","\"$mpfiresettings{'FILE'}\"");}
-elsif ( $mpfiresettings{'ACTION'} eq "x" ){$message=system("/usr/local/bin/mpfirectrl stop");}
-elsif ( $mpfiresettings{'ACTION'} eq "|>" ){$message=system("/usr/local/bin/mpfirectrl toggle");}
-elsif ( $mpfiresettings{'ACTION'} eq "<<" ){$message=system("/usr/local/bin/mpfirectrl prev");}
-elsif ( $mpfiresettings{'ACTION'} eq ">>" ){$message=system("/usr/local/bin/mpfirectrl next");}
-elsif ( $mpfiresettings{'ACTION'} eq "+" ){$message=system("/usr/local/bin/mpfirectrl volup 5");}
-elsif ( $mpfiresettings{'ACTION'} eq "-" ){$message=system("/usr/local/bin/mpfirectrl voldown 5");}
-elsif ( $mpfiresettings{'ACTION'} eq "++" ){$message=system("/usr/local/bin/mpfirectrl volup 10");}
-elsif ( $mpfiresettings{'ACTION'} eq "--" ){$message=system("/usr/local/bin/mpfirectrl voldown 10");}
-elsif ( $mpfiresettings{'ACTION'} eq "playweb" ){$message=system("/usr/local/bin/mpfirectrl","playweb","\"$mpfiresettings{'FILE'}\"");}
-elsif ( $mpfiresettings{'ACTION'} eq "playlist" ){$message=system("/usr/local/bin/mpfirectrl playlist");}
-elsif ( $mpfiresettings{'ACTION'} eq "emptyplaylist" ){$message=system("/usr/local/bin/mpfirectrl clearplaylist");}
-elsif ( $mpfiresettings{'ACTION'} eq "addtoplaylist" ){$message=system("/usr/local/bin/mpfirectrl","playadd","\"$mpfiresettings{'FILE'}\"");}
-elsif ( $mpfiresettings{'ACTION'} eq "playall" ){$message=system("/usr/local/bin/mpfirectrl playall");}
-elsif ( $mpfiresettings{'ACTION'} eq "playalbum" )
-{
-my @temp = ""; my @song = ""; my @select = split(/\|/,$mpfiresettings{'album'});
-
-foreach (keys(%songs)){
- @song = split(/\|/,$songs{$_});$song[4] =~ s/\W/ /g;
-
- foreach (@select){
- $_ =~ s/\W/ /g;
- if ( $song[4] =~ /$_/ ){push(@temp,$song[0]);}
- }
-}
-
-open(DATEI, ">${General::swroot}/mpfire/playlist.m3u") || die "Could not add playlist";
-print DATEI @temp;
-close(DATEI);
-$message=system("/usr/local/bin/mpfirectrl playlist");
-}
-elsif ( $mpfiresettings{'ACTION'} eq "playartist" )
-{
-my @temp = ""; my @song = ""; my @select = split(/\|/,$mpfiresettings{'artist'});
-
-foreach (keys(%songs)){
- @song = split(/\|/,$songs{$_});$song[2] =~ s/\W/ /g;
-
- foreach (@select){
- $_ =~ s/\W/ /g;
- if ( $song[2] =~ /$_/ ){push(@temp,$song[0]);}
- }
-}
-
-open(DATEI, ">${General::swroot}/mpfire/playlist.m3u") || die "Could not add playlist";
-print DATEI @temp;
-close(DATEI);
-$message=system("/usr/local/bin/mpfirectrl playlist");
-}
-elsif ( $mpfiresettings{'ACTION'} eq "playyear" )
-{
-my @temp = ""; my @song = ""; my @select = split(/\|/,$mpfiresettings{'year'});
-
-foreach (keys(%songs)){
- @song = split(/\|/,$songs{$_});$song[6] =~ s/\W/ /g;
-
- foreach (@select){
- $_ =~ s/\W/ /g;
- if ( $song[6] =~ /$_/ ){push(@temp,$song[0]);}
- }
-}
-
-open(DATEI, ">${General::swroot}/mpfire/playlist.m3u") || die "Could not add playlist";
-print DATEI @temp;
-close(DATEI);
-$message=system("/usr/local/bin/mpfirectrl playlist");
-}
-elsif ( $mpfiresettings{'ACTION'} eq "playgenre" )
-{
-my @temp = ""; my @song = ""; my @select = split(/\|/,$mpfiresettings{'genre'});
-
-foreach (keys(%songs)){
- @song = split(/\|/,$songs{$_});$song[7] =~ s/\W/ /g;
-
- foreach (@select){
- $_ =~ s/\W/ /g;
- if ( $song[7] =~ /$_/ ){push(@temp,$song[0]);}
- }
+if ( $mpfiresettings{'ACTION'} eq "scan" ){
+
+# on keypress scan the given directory and store the path to the mpd config
+ &General::readhash("${General::swroot}/mpfire/settings", \%mpfiresettings);
+ &Header::getcgihash(\%mpfiresettings);
+ delete $mpfiresettings{'__CGI__'};delete $mpfiresettings{'x'};delete $mpfiresettings{'y'};
+ delete $mpfiresettings{'PAGE'}; delete $mpfiresettings{'FRAME'};
+ &General::writehash("${General::swroot}/mpfire/settings", \%mpfiresettings);
+
+ open(DATEI, "<${General::swroot}/mpfire/mpd.conf") || die "Datei nicht gefunden";
+ my @Zeilen = ;
+ close(DATEI);
+
+ open(DATEI, ">${General::swroot}/mpfire/mpd.conf") || die "Datei nicht gefunden";
+ foreach (@Zeilen){
+ if ( $_ =~ /music_directory/){
+ print DATEI "music_directory \"".$mpfiresettings{'MUSICDIR'}."\"\n";
+ }else {
+ print DATEI $_;
+ }
+ }
+ close(DATEI);
+
+ $mpd->updatedb();
+ refreshpage();
+}elsif ( $mpfiresettings{'ACTION'} eq "playweb" ){
+ $message=system("/usr/local/bin/mpfirectrl","playweb","\"$mpfiresettings{'FILE'}\"","2>/dev/null");
+}elsif ( $mpfiresettings{'ACTION'} eq "playlist" ){
+ $mpd->play();
+}elsif ( $mpfiresettings{'ACTION'} eq "emptyplaylist" ){
+# on keypress clear the playlist
+ $mpd->playlist->clear();
+}elsif ( $mpfiresettings{'ACTION'} eq "addtoplaylist" ){
+ $mpd->playlist->add($mpfiresettings{'FILE'});
+}elsif ( $mpfiresettings{'ACTION'} eq "playalbum" ){
+# on keypress play the selected albums
+ my @select = split(/\|/,$mpfiresettings{'album'});
+ $mpd->playlist->clear();
+ foreach (@select){
+ foreach ($mpd->collection->filenames_by_album($_)){
+ if ( $_ ne "" ){
+ $mpd->playlist->add($_);
+ }
+ }
+ }
+ $mpd->play();
+}elsif ( $mpfiresettings{'ACTION'} eq "playartist" ){
+# on keypress play the selected artist
+ my @select = split(/\|/,$mpfiresettings{'artist'});
+ $mpd->playlist->clear();
+ foreach (@select){
+ foreach ($mpd->collection->filenames_by_artist($_)){
+ if ( $_ ne "" ){
+ $mpd->playlist->add($_);
+ }
+ }
+ }
+ $mpd->play();
+}elsif ( $mpfiresettings{'ACTION'} eq "playyear" ){
+# on keypress play the selected year
+ my @select = split(/\|/,$mpfiresettings{'year'});
+ $mpd->playlist->clear();
+ foreach (@select){
+ foreach ($mpd->collection->filenames_by_year($_)){
+ if ( $_ ne "" ){
+ $mpd->playlist->add($_);
+ }
+ }
+ }
+ $mpd->play();
+}elsif ( $mpfiresettings{'ACTION'} eq "playgenre" ){
+# on keypress play the selected genre
+ my @select = split(/\|/,$mpfiresettings{'genre'});
+ $mpd->playlist->clear();
+ foreach (@select){
+ foreach ($mpd->collection->filenames_by_genre($_)){
+ if ( $_ ne "" ){
+ $mpd->playlist->add($_);
+ }
+ }
+ }
+ $mpd->play();
+}elsif ( $mpfiresettings{'ACTION'} eq ">" ){
+ $mpd->playlist->clear();
+ $mpd->playlist->add($mpfiresettings{'FILE'});
+ $mpd->play();
}
-open(DATEI, ">${General::swroot}/mpfire/playlist.m3u") || die "Could not add playlist";
-print DATEI @temp;
-close(DATEI);
-$message=system("/usr/local/bin/mpfirectrl playlist");
-}
-elsif ( $mpfiresettings{'SHOWLIST'} ){delete $mpfiresettings{'__CGI__'};delete $mpfiresettings{'x'};delete $mpfiresettings{'y'};delete $mpfiresettings{'PAGE'};&General::writehash("${General::swroot}/mpfire/settings", \%mpfiresettings);refreshpage();}
+ if ( $mpfiresettings{'SEARCH'} eq "artist" && $mpfiresettings{'SEARCHITEM'} ne "" ){
+ foreach ($mpd->collection->songs_with_artist_partial_filename($mpfiresettings{'SEARCHITEM'})){
+ if ( $_ ne "" ){
+ push(@songs,$_);
+ }
+ }
+ }elsif ( $mpfiresettings{'SEARCH'} eq "title" && $mpfiresettings{'SEARCHITEM'} ne "" ){
+ foreach ($mpd->collection->songs_with_title_partial_filename($mpfiresettings{'SEARCHITEM'})){
+ if ( $_ ne "" ){
+ push(@songs,$_);
+ }
+ }
+ }elsif ( $mpfiresettings{'SEARCH'} eq "album" && $mpfiresettings{'SEARCHITEM'} ne "" ){
+ foreach ($mpd->collection->songs_with_album_partial_filename($mpfiresettings{'SEARCHITEM'})){
+ if ( $_ ne "" ){
+ push(@songs,$_);
+ }
+ }
+ }else{
+ @songs = $mpd->collection->all_items_simple();
+ shift(@songs);
+ }
############################################################################################################################
################################### Aufbau der HTML Seite fr globale Sambaeinstellungen ####################################
-$mpfiresettings{'MUSICDIR'} = "/";
-
+$mpfiresettings{'MUSICDIR'} = "/var/mp3";
&General::readhash("${General::swroot}/mpfire/settings", \%mpfiresettings);
############################################################################################################################
########################################### rekursiv nach neuen Mp3s Scannen ##############################################ä
-if ( $message ne '0' ) { print "An Error occured while launching the command"; }
-elsif ( $message ne "" && $message ne '0' ) { print "$message"; }
+if ( $message ne '0' ){
+ print "An Error occured while launching the command";
+}elsif ( $message ne "" && $message ne '0' ){
+ print "$message";
+}
&Header::openbox('100%', 'center', $Lang::tr{'mpfire scanning'});
-
+# box to enter the music directory and initiate the scan process
print <
$Lang::tr{'Scan for Files'}
$Lang::tr{'Scan from Directory'}
-
-
+
END
;
&Header::closebox();
-my $song = qx(/usr/local/bin/mpfirectrl song);
-if ( $song eq "" ){$song = "None";}
-
-my $Volume = `/usr/local/bin/mpfirectrl volume`;
-$Volume=~s// /g;
-my $stats = `mpc stats | tail -4`;
-$stats=~s/\\/ /g
-
&Header::openbox('100%', 'center', $Lang::tr{'mpfire controls'});
+# box for the two iframes showing the current playbar and the control buttons
print <
-
+
+
END
;
-my $countsongs=`/usr/local/bin/mpfirectrl stats`;
-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 <
+