]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blobdiff - config/mpfire/mpfire.pl
Ein Paar Dateien fuer die GPLv3 angepasst.
[people/pmueller/ipfire-2.x.git] / config / mpfire / mpfire.pl
index b0de0e1f1365379abfe692a506f26f958e50e0fd..ec7f2920108662b7c80255e09a76148ea4d61c8f 100644 (file)
@@ -1,4 +1,23 @@
 #!/usr/bin/perl
+###############################################################################
+#                                                                             #
+# IPFire.org - A linux based firewall                                         #
+# Copyright (C) 2007  Michael Tremer & Christian Schmidt                      #
+#                                                                             #
+# This program is free software: you can redistribute it and/or modify        #
+# it under the terms of the GNU General Public License as published by        #
+# the Free Software Foundation, either version 3 of the License, or           #
+# (at your option) any later version.                                         #
+#                                                                             #
+# This program is distributed in the hope that it will be useful,             #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of              #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
+# GNU General Public License for more details.                                #
+#                                                                             #
+# You should have received a copy of the GNU General Public License           #
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+###############################################################################
 
 use MP3::Tag;
 use MP3::Info;
@@ -10,6 +29,7 @@ require "${General::swroot}/header.pl";
 my $filename = "";
 my %songs = "";
 my $debug = 0;
+my $temp;
 
 if ($ARGV[0] eq 'scan') {
 my $command = "find ";
@@ -37,11 +57,12 @@ if ($ARGV[0] eq 'getdb') {
   }
 elsif ($ARGV[0] eq 'play') {
   &checkplaylist();
+  &checkmute();
   if ($debug){print "Yes we are called and we will play $ARGV[1]\n";}
   system("/usr/bin/mpg123 -b 1024 --aggressive -q \"$ARGV[1]\" 2>/dev/null >/dev/null &");
   }
 elsif ($ARGV[0] eq 'stop') {
-  my $PID = `ps -ef \| grep wget \| grep EXTM3U \| head -1 \| grep -v "sh -c" \| awk '{  print \$2 }'`;
+  my $PID = `ps -ef \| grep "wget -qO" \| head -1 \| grep -v "sh -c" \| awk '{  print \$2 }'`;
   if ( $PID ne '' ){
    if ($debug){print "Stopping $PID\n";}
    system("kill -KILL $PID");
@@ -58,23 +79,26 @@ elsif ($ARGV[0] eq 'stop') {
 elsif ($ARGV[0] eq 'volup') {
   if ($debug){print "Increasing Volume\n";}
   system("/usr/bin/amixer set Master $ARGV[1]%+ 2>/dev/null >/dev/null");
+  system("/usr/bin/amixer set PCM $ARGV[1]%+ 2>/dev/null >/dev/null");
   }
 elsif ($ARGV[0] eq 'voldown') {
   if ($debug){print "Decreasing Volume\n";}
   system("/usr/bin/amixer set Master $ARGV[1]%- 2>/dev/null >/dev/null");
+  system("/usr/bin/amixer set PCM $ARGV[1]%- 2>/dev/null >/dev/null");
   }
 elsif ($ARGV[0] eq 'playall') {
   &checkplaylist();
+  &checkmute();
   if ($debug){print "Playing everything\n";}
   system("/usr/bin/mpg123 -b 1024 --aggressive -Zq@ /var/ipfire/mpfire/playlist 2>/dev/null >/dev/null &"); 
   }
 elsif ($ARGV[0] eq 'pause') {
-  my $PID =  `ps -ef \| grep mpg123 \| grep playlist \| head -1 \| grep -v "sh -c" \| awk '{  print \$2 }'`;
+  my $PID =  `ps -ef \| grep mpg123 \| grep playlist \| head -1 \| grep -v "sh -c" \| grep -v "grep" \| awk '{  print \$2 }'`;
   if ($debug){print "Pausing Process $PID\n";}
   system("kill -STOP $PID");
   }
 elsif ($ARGV[0] eq 'resume') {
-  my $PID =  `ps -ef \| grep mpg123 \| grep playlist \| head -1 \| grep -v "sh -c" \| awk '{  print \$2 }'`;
+  my $PID =  `ps -ef \| grep mpg123 \| grep playlist \| head -1 \| grep -v "sh -c" \| grep -v "grep" \| awk '{  print \$2 }'`;
   if ($debug){print "Resuming Process $PID\n";}
   system("kill -CONT $PID");
   }
@@ -84,18 +108,22 @@ elsif ($ARGV[0] eq 'next') {
   system("kill -SIGINT $PID");
   }
 elsif ($ARGV[0] eq 'song') {
-  my $song = `lsof -nX \| grep mpg123 \| grep REG \| grep mem | grep mp3 \| grep -v "sh -c"`;
+  &checkmute();
+  my $song = `lsof -nX \| grep mpg123 \| grep REG \| grep mem | grep mp3 \| grep -v "sh -c" \| grep -v "grep"`;
   my @song = split(/\//,$song);
   my $i = @song;
   if ( $i == 0 ){
-  my $song = `ps -ef \| grep wget \| grep EXTM3U \| grep -v "sh -c"`;
-  my @song = split(/,/,$song);
-  print $song[1];
+  my $song = `ps -ef \| grep "wget -qO" \| grep -v "sh -c" \| grep -v "grep"`;
+  my @song = split(/http\:\/\//,$song);
+  my $temp = $song[1];
+  my @song = split(/ /,$temp);
+  print $song[0];
   }
   else { print $song[$i-1];}
   }
 elsif ($ARGV[0] eq 'playweb') {
   &General::readhash("${General::swroot}/proxy/settings", \%proxysettings);
+  &checkmute();
 
                        if ($proxysettings{'UPSTREAM_PROXY'}) {
                          if ($proxysettings{'UPSTREAM_USER'}) {
@@ -113,6 +141,13 @@ elsif ($ARGV[0] eq 'playweb') {
         system("wget -qO - `wget -qO - http://$ARGV[1]` | mpg123 -b 1024 --aggressive -Zq - 2>/dev/null >/dev/null &");
                        }
   }
+elsif ($ARGV[0] eq 'volume') {
+ $temp = "Master - ";
+ $temp .= `amixer get Master \| tail -2 \| awk '{ print \$2" "\$5 }'`;
+ $temp .= "<break>PCM -";
+ $temp .= `amixer get PCM \| tail -2 \| awk '{ print \$2" "\$5 }'`;
+ print $temp;
+}
 
 sub getSongInfo(){
   my $mp3 = MP3::Tag->new($filename);
@@ -135,7 +170,22 @@ sub getExistingSongs(){
 sub checkplaylist(){
  my $Datei = "/var/ipfire/mpfire/playlist";
  my @Info = stat($Datei);
- if ( $Info[7] eq '' ){print "There is no playlist";exit(1);}
+ if ( $Info[7] eq '' || $Info[7] eq '0' ){print "There is no playlist";exit(1);}
+}
+
+sub checkmute(){
+ $temp = `amixer get Master \| tail -2`;
+  my @Master = split(/ /,$temp);
+ $temp = `amixer get PCM \| tail -2`;
+  my @PCM = split(/ /,$temp);
+ if ( $PCM[7] =~  /off/ ){
+  if ($debug){print "PCM was muted - umuting.\n";}
+  system("amixer set PCM toggle");
+  }
+ if ( $Master[7] =~ /off/ ){
+  if ($debug){print "Master was muted - umuting.\n";}
+  system("amixer set Master toggle");
+  } 
 }
 
 sub checkm3u(){