]>
git.ipfire.org Git - people/ummeegge/ipfire-2.x.git/blob - config/mpfire/mpfire.pl
2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007 Michael Tremer & Christian Schmidt #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
20 ###############################################################################
25 require '/var/ipfire/general-functions.pl';
26 require "${General::swroot}/lang.pl";
27 require "${General::swroot}/header.pl";
34 if ($ARGV[0] eq 'scan') {
35 my $command = "find ";
37 $command .= "\"$ARGV[1]\"";
38 if ($ARGV[2] eq 'off'){$command .= " -maxdepth 1";}
39 $command .= " -name *.mp3";
40 my @files = `$command`;
49 open(DATEI
, ">${General::swroot}/mpfire/db/songs.db") || die "Kann Datenbank nicht speichern";
54 if ($ARGV[0] eq 'getdb') {
58 elsif ($ARGV[0] eq 'play') {
61 if ($debug){print "Yes we are called and we will play $ARGV[1]\n";}
62 system("/usr/bin/mpg123 -b 1024 --aggressive -q \"$ARGV[1]\" 2>/dev/null >/dev/null &");
64 elsif ($ARGV[0] eq 'stop') {
65 my $PID = `ps -ef \| grep "wget -qO" \| head -1 \| grep -v "sh -c" \| awk '{ print \$2 }'`;
67 if ($debug){print "Stopping $PID\n";}
68 system("kill -KILL $PID");
69 my $PID = `ps -ef \| grep "mpg123 -b 1024 --aggressive -Zq -" \| head -1 \| grep -v "sh -c" \| awk '{ print \$2 }'`;
70 if ($debug){print "Killing Process $PID\n";}
71 system("kill -KILL $PID");
74 my $PID = `ps -ef \| grep mpg123 \| grep playlist \| head -1 \| grep -v "sh -c" \| awk '{ print \$2 }'`;
75 if ($debug){print "Stopping $PID\n";}
76 system("kill -KILL $PID");
79 elsif ($ARGV[0] eq 'volup') {
80 if ($debug){print "Increasing Volume\n";}
81 system("/usr/bin/amixer set Master $ARGV[1]%+ 2>/dev/null >/dev/null");
82 system("/usr/bin/amixer set PCM $ARGV[1]%+ 2>/dev/null >/dev/null");
84 elsif ($ARGV[0] eq 'voldown') {
85 if ($debug){print "Decreasing Volume\n";}
86 system("/usr/bin/amixer set Master $ARGV[1]%- 2>/dev/null >/dev/null");
87 system("/usr/bin/amixer set PCM $ARGV[1]%- 2>/dev/null >/dev/null");
89 elsif ($ARGV[0] eq 'playall') {
92 if ($debug){print "Playing everything\n";}
93 system("/usr/bin/mpg123 -b 1024 --aggressive -Zq@ /var/ipfire/mpfire/playlist 2>/dev/null >/dev/null &");
95 elsif ($ARGV[0] eq 'pause') {
96 my $PID = `ps -ef \| grep mpg123 \| grep playlist \| head -1 \| grep -v "sh -c" \| grep -v "grep" \| awk '{ print \$2 }'`;
97 if ($debug){print "Pausing Process $PID\n";}
98 system("kill -STOP $PID");
100 elsif ($ARGV[0] eq 'resume') {
101 my $PID = `ps -ef \| grep mpg123 \| grep playlist \| head -1 \| grep -v "sh -c" \| grep -v "grep" \| awk '{ print \$2 }'`;
102 if ($debug){print "Resuming Process $PID\n";}
103 system("kill -CONT $PID");
105 elsif ($ARGV[0] eq 'next') {
106 if ($debug){print "Next Song\n";}
107 my $PID = `ps -ef | grep mpg123 | grep playlist | head -1 | awk '{ print \$2 }'`;
108 system("kill -SIGINT $PID");
110 elsif ($ARGV[0] eq 'song') {
112 my $song = `lsof -nX \| grep mpg123 \| grep REG \| grep mem | grep mp3 \| grep -v "sh -c" \| grep -v "grep"`;
113 my @song = split(/\//,$song);
116 my $song = `ps -ef \| grep "wget -qO" \| grep -v "sh -c" \| grep -v "grep"`;
117 my @song = split(/http\:\/\
//,$song);
119 my @song = split(/ /,$temp);
122 else { print $song[$i-1];}
124 elsif ($ARGV[0] eq 'playweb') {
125 &General
::readhash
("${General::swroot}/proxy/settings", \
%proxysettings);
128 if ($proxysettings{'UPSTREAM_PROXY'}) {
129 if ($proxysettings{'UPSTREAM_USER'}) {
131 if ($debug){print "Playing webstream\n";}
132 system("wget -qO - `wget -qO - http://$proxysettings{'UPSTREAM_USER'}:$proxysettings{'UPSTREAM_PASSWORD'}@$proxysettings{'UPSTREAM_PROXY'}$ARGV[1]` | mpg123 -b 1024 --aggressive -Zq - 2>/dev/null >/dev/null &");
135 &checkm3uproxyuser
();
136 if ($debug){print "Playing webstream\n";}
137 system("wget -qO - `wget -qO - http://$proxysettings{'UPSTREAM_PROXY'}$ARGV[1]` | mpg123 -b 1024 --aggressive -Zq - 2>/dev/null >/dev/null &");}
140 if ($debug){print "Playing webstream\n";}
141 system("wget -qO - `wget -qO - http://$ARGV[1]` | mpg123 -b 1024 --aggressive -Zq - 2>/dev/null >/dev/null &");
144 elsif ($ARGV[0] eq 'volume') {
146 $temp .= `amixer get Master \| tail -2 \| awk '{ print \$2" "\$5 }'`;
147 $temp .= "<break>PCM -";
148 $temp .= `amixer get PCM \| tail -2 \| awk '{ print \$2" "\$5 }'`;
153 my $mp3 = MP3
::Tag
->new($filename);
154 my ($title, $track, $artist, $album, $comment, $year, $genre) = $mp3->autoinfo();
155 my $info = get_mp3info
($filename);
157 $songs{$filename} = "|".$artist."|".$title."|".$track."|".$album."|".$year."|".$genre."|".$info->{MM
}."|".$info->{SS
}."|".$info->{BITRATE
}."|".$info->{FREQUENCY
}."|".$info->{MODE
}."\n";
160 sub getExistingSongs
(){
161 open(DATEI
, "<${General::swroot}/mpfire/db/songs.db") || die "Keine Datenbank vorhanden";
162 my @Zeilen = <DATEI
>;
165 my @Zeile = split(/\|/,$_);
166 $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";
171 my $Datei = "/var/ipfire/mpfire/playlist";
172 my @Info = stat($Datei);
173 if ( $Info[7] eq '' || $Info[7] eq '0' ){print "There is no playlist";exit(1);}
177 $temp = `amixer get Master \| tail -2`;
178 my @Master = split(/ /,$temp);
179 $temp = `amixer get PCM \| tail -2`;
180 my @PCM = split(/ /,$temp);
181 if ( $PCM[7] =~ /off/ ){
182 if ($debug){print "PCM was muted - umuting.\n";}
183 system("amixer set PCM toggle");
185 if ( $Master[7] =~ /off/ ){
186 if ($debug){print "Master was muted - umuting.\n";}
187 system("amixer set Master toggle");
192 my $Datei = system("wget -q --spider http://$ARGV[1]");
193 if ( $Datei ne '0' ){print "We are unable to get the stream";exit(1);}
197 my $Datei = system("wget -q --spider http://$ARGV[1]");
198 if ( $Datei ne '0' ){print "We are unable to get the stream";exit(1);}
201 sub checkm3uproxyuser
(){
202 my $Datei = system("wget -q --spider http://$ARGV[1]");
203 if ( $Datei ne '0' ){print "We are unable to get the stream";exit(1);}