]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blobdiff - config/mpfire/mpfire.pl
kernel: disable FW_LOADER_USER_HELPER_FALLBACK
[people/pmueller/ipfire-2.x.git] / config / mpfire / mpfire.pl
index a3bfb9d7fd6c6ea005fa570b88fd8162c38de28c..66413145de61a1545bd4ac992a3801d6f7168f39 100644 (file)
 #!/usr/bin/perl
 
-use MP3::Tag;
-use MP3::Info;
-
 require '/var/ipfire/general-functions.pl';
 require "${General::swroot}/lang.pl";
 require "${General::swroot}/header.pl";
 
 my $filename = "";
-my %songs = "";
-my $debug = 1;
-
-if ($ARGV[0] eq 'scan') {
-my $command = "find ";
-chomp $ARGV[1];
-$command .= "\"$ARGV[1]\"";
-if ($ARGV[2] eq 'off'){$command .= " -maxdepth 1";}
-$command .= " -name *.mp3";
-my @files = `$command`;
+my $debug = 0; 
 
-&getExistingSongs();
-
-foreach (@files){
- $filename = $_;
- chomp($filename)
-  &getSongInfo();
-  }
-open(DATEI, ">${General::swroot}/mpfire/db/songs.db") || die "Kann Datenbank nicht speichern";
-print DATEI %songs;
-close(DATEI);
+if (  `/etc/init.d/mpd status` =~/not running/ ){
+system("/etc/init.d/mpd start >/dev/null");
 }
 
-if ($ARGV[0] eq 'getdb') {
-  &getExistingSongs();
-  print %songs;
-  }
-
-if ($ARGV[0] eq 'play') {
+if ($ARGV[0] eq 'scan') {
+  if ($debug){print "Creating Database\n";}
+  system("mpd --create-db >/dev/null");
+  system("/etc/init.d/mpd restart >/dev/null");
+}
+elsif ($ARGV[0] eq 'play') {
+  &checkmute();
+  &clearplaylist();
   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 &");
+  system("mpc add \"$ARGV[1]\" >/dev/null && mpc play >/dev/null");
   }
-  
-if ($ARGV[0] eq 'stop') {
-  my $PID =  `ps -ef | grep mpg123 | grep playlist | head -1 | awk '{  print \$2 }'`;
-  if ( $PID ne "" ){
-    if ($debug){print "Stopping $PID\n";}
-    system("kill -KILL $PID");
-    }
-  else {&stopweb();}
+elsif ($ARGV[0] eq 'playadd') {
+  if ($debug){print "Yes we are called and we will add $ARGV[1]\n";}
+  system("mpc add \"$ARGV[1]\" >/dev/null && mpc play >/dev/null");
   }
-
-if ($ARGV[0] eq 'volup') {
+elsif ($ARGV[0] eq 'clearplaylist') {
+  if ($debug){print "Deleting playlist\n";}
+  &clearplaylist();
+  }
+elsif ($ARGV[0] eq 'stop') {
+    my $PID = 'cat /var/run/mpd.pid';
+    if ($debug){print "Killing Process $PID\n";}
+    system("mpc stop >/dev/null");
+  }
+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");
   }
-
-if ($ARGV[0] eq 'voldown') {
+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");
   }
-
-if ($ARGV[0] eq 'playall') {
-  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 'toggle') {
+  system("mpc toggle >/dev/null");
   }
-  
-if ($ARGV[0] eq 'pause') {
-  my $PID =  `ps -ef | grep mpg123 | grep playlist | head -1 | awk '{  print \$2 }'`;
-  if ($debug){print "Pausing Process $PID\n";}
-  system("kill -STOP $PID");
+elsif ($ARGV[0] eq 'next') {
+  if ($debug){print "Next Song\n";}
+  system("mpc next >/dev/null[");
   }
-
-if ($ARGV[0] eq 'resume') {
-  my $PID =  `ps -ef | grep mpg123 | grep playlist | head -1 | awk '{  print \$2 }'`;
-  if ($debug){print "Resuming Process $PID\n";}
-  system("kill -CONT $PID");
+elsif ( $ARGV[0] eq 'prev' ) {
+  if ($debug){print "Previous Song\n";}
+  system("mpc prev >/dev/null");  
   }
-  
-if ($ARGV[0] eq 'next') {
-  if ($debug){print "Next Song\n";}
-  my $PID =  `ps -ef | grep mpg123 | grep playlist | head -1 | awk '{  print \$2 }'`;
-  system("kill -SIGINT $PID");
+elsif ($ARGV[0] eq 'song') {
+  my $song = `mpc \| head -2 | grep -v volume`;
+  print $song;
   }
-
-if ($ARGV[0] eq 'song') {
-  my $song = `lsof -nX \| grep mpg123 \| grep REG \| grep mem | grep mp3`;
-  my @song = split(/\//,$song);
-  my $i = @song;
-  print $song[$i-1];
+elsif ($ARGV[0] eq 'stats') {
+  my $song = `mpc stats | grep Songs`;
+  print $song;
   }
-
-if ($ARGV[0] eq 'playweb') {
-  &General::readhash("${General::swroot}/proxy/settings", \%proxysettings);
-  if ($debug){print "Playing webstream\n";}
-                       if ($proxysettings{'UPSTREAM_PROXY'}) {
-                         if ($proxysettings{'UPSTREAM_USER'}) {
-          system("wget -qO - `wget -qO -  $ARGV[1]` | mpg123 -b 1024 --aggressive -Zq - -p $proxysettings{'UPSTREAM_USER'}:$proxysettings{'UPSTREAM_PASSWORD'}@$proxysettings{'UPSTREAM_PROXY'} 2>/dev/null >/dev/null &");
-          }
-          else {          system("wget -qO - `wget -qO -  $ARGV[1]` | mpg123 -b 1024 --aggressive -Zq - -p $proxysettings{'UPSTREAM_PROXY'} 2>/dev/null >/dev/null &");} 
-                       } else {
-        system("wget -qO - `wget -qO -  $ARGV[1]` | mpg123 -b 1024 --aggressive -Zq - 2>/dev/null >/dev/null &"); 
-                       }
+elsif ($ARGV[0] eq 'playweb') {
+  &checkmute();
+  &clearplaylist();
+  if ($debug){print "Playing webstream $ARGV[1] \n";}
+     system("mpc add http://$ARGV[1] >/dev/null && mpc play >/dev/null && sleep 1");
   }
+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;
+}
 
-if ($ARGV[0] eq 'stopweb') {
-  &stopweb();
+sub clearplaylist(){
+  system("mpc clear >/dev/null");  
   }
 
-sub stopweb(){
-  my $PID =  `ps -ef | grep wget | grep EXTM3U | head -1 | awk '{  print \$2 }'`;
-  if ($debug){print "Stopping $PID\n";}
-  system("kill -KILL $PID");
-  my $PID =  `ps -ef | grep "mpg123 -b 1024 --aggressive -Zq -" | head -1 | awk '{  print \$2 }'`;
-  if ($debug){print "Killing Process $PID\n";}
-  system("kill -KILL $PID");
+sub shuffle(){
+  system("mpc random >/dev/null");  
   }
 
-sub getSongInfo(){
-  my $mp3 = MP3::Tag->new($filename);
-  my ($title, $track, $artist, $album, $comment, $year, $genre) = $mp3->autoinfo();
-  my $info = get_mp3info($filename);
-  $mp3->close();
-  $songs{$filename} = "|".$artist."|".$title."|".$track."|".$album."|".$year."|".$genre."|".$info->{MM}."|".$info->{SS}."|".$info->{BITRATE}."|".$info->{FREQUENCY}."|".$info->{MODE}."\n";
-  }
+sub checkplaylist(){
+ my $Datei = "/var/ipfire/mpfire/playlist.m3u";
+ my @Info = stat($Datei);
+ if ( $Info[7] eq '' || $Info[7] eq '0' ){print "There is no playlist";exit(1);}
+}
 
-sub getExistingSongs(){
-  open(DATEI, "<${General::swroot}/mpfire/db/songs.db") || die "Keine Datenbank vorhanden";
-  my @Zeilen = <DATEI>;
-  close(DATEI);
-  foreach (@Zeilen){
-    my @Zeile = split(/\|/,$_);
-    $songs{$Zeile[0]} = "|".$Zeile[1]."|".$Zeile[2]."|".$Zeile[3]."|".$Zeile[4]."|".$Zeile[5]."|".$Zeile[6]."|".$Zeile[7]."|".$Zeile[8]."|".$Zeile[9]."|".$Zeile[10]."|".$Zeile[11]."\n";
-    }
- }
+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 >/dev/null");
+  }
+ if ( $Master[7] =~ /off/ ){
+  if ($debug){print "Master was muted - umuting.\n";}
+  system("amixer set Master toggle >/dev/null");
+  } 
+}