]>
Commit | Line | Data |
---|---|---|
a28fdc01 | 1 | #!/usr/bin/perl |
70df8302 MT |
2 | ############################################################################### |
3 | # # | |
4 | # IPFire.org - A linux based firewall # | |
5 | # Copyright (C) 2007 Michael Tremer & Christian Schmidt # | |
6 | # # | |
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. # | |
11 | # # | |
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. # | |
16 | # # | |
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/>. # | |
19 | # # | |
20 | ############################################################################### | |
a28fdc01 CS |
21 | |
22 | use MP3::Tag; | |
23 | use MP3::Info; | |
24 | ||
25 | require '/var/ipfire/general-functions.pl'; | |
26 | require "${General::swroot}/lang.pl"; | |
27 | require "${General::swroot}/header.pl"; | |
28 | ||
29 | my $filename = ""; | |
30 | my %songs = ""; | |
70db8683 | 31 | my $debug = 0; |
8050f37b | 32 | my $temp; |
a28fdc01 CS |
33 | |
34 | if ($ARGV[0] eq 'scan') { | |
35 | my $command = "find "; | |
36 | chomp $ARGV[1]; | |
37 | $command .= "\"$ARGV[1]\""; | |
38 | if ($ARGV[2] eq 'off'){$command .= " -maxdepth 1";} | |
39 | $command .= " -name *.mp3"; | |
40 | my @files = `$command`; | |
41 | ||
42 | &getExistingSongs(); | |
43 | ||
44 | foreach (@files){ | |
45 | $filename = $_; | |
46 | chomp($filename) | |
47 | &getSongInfo(); | |
48 | } | |
49 | open(DATEI, ">${General::swroot}/mpfire/db/songs.db") || die "Kann Datenbank nicht speichern"; | |
50 | print DATEI %songs; | |
51 | close(DATEI); | |
52 | } | |
53 | ||
54 | if ($ARGV[0] eq 'getdb') { | |
55 | &getExistingSongs(); | |
56 | print %songs; | |
57 | } | |
bac7231b | 58 | elsif ($ARGV[0] eq 'play') { |
8871b9f2 | 59 | &checkplaylist(); |
8050f37b | 60 | &checkmute(); |
a28fdc01 CS |
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 &"); | |
63 | } | |
bac7231b | 64 | elsif ($ARGV[0] eq 'stop') { |
12a2f2ec | 65 | my $PID = `ps -ef \| grep "wget -qO" \| head -1 \| grep -v "sh -c" \| awk '{ print \$2 }'`; |
8871b9f2 CS |
66 | if ( $PID ne '' ){ |
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"); | |
72 | } | |
73 | else{ | |
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"); | |
77 | } | |
a28fdc01 | 78 | } |
bac7231b | 79 | elsif ($ARGV[0] eq 'volup') { |
a28fdc01 CS |
80 | if ($debug){print "Increasing Volume\n";} |
81 | system("/usr/bin/amixer set Master $ARGV[1]%+ 2>/dev/null >/dev/null"); | |
05882fff | 82 | system("/usr/bin/amixer set PCM $ARGV[1]%+ 2>/dev/null >/dev/null"); |
a28fdc01 | 83 | } |
bac7231b | 84 | elsif ($ARGV[0] eq 'voldown') { |
a28fdc01 CS |
85 | if ($debug){print "Decreasing Volume\n";} |
86 | system("/usr/bin/amixer set Master $ARGV[1]%- 2>/dev/null >/dev/null"); | |
05882fff | 87 | system("/usr/bin/amixer set PCM $ARGV[1]%- 2>/dev/null >/dev/null"); |
a28fdc01 | 88 | } |
bac7231b | 89 | elsif ($ARGV[0] eq 'playall') { |
8871b9f2 | 90 | &checkplaylist(); |
8050f37b | 91 | &checkmute(); |
a28fdc01 CS |
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 &"); | |
94 | } | |
bac7231b | 95 | elsif ($ARGV[0] eq 'pause') { |
12a2f2ec | 96 | my $PID = `ps -ef \| grep mpg123 \| grep playlist \| head -1 \| grep -v "sh -c" \| grep -v "grep" \| awk '{ print \$2 }'`; |
a28fdc01 CS |
97 | if ($debug){print "Pausing Process $PID\n";} |
98 | system("kill -STOP $PID"); | |
99 | } | |
bac7231b | 100 | elsif ($ARGV[0] eq 'resume') { |
12a2f2ec | 101 | my $PID = `ps -ef \| grep mpg123 \| grep playlist \| head -1 \| grep -v "sh -c" \| grep -v "grep" \| awk '{ print \$2 }'`; |
a28fdc01 CS |
102 | if ($debug){print "Resuming Process $PID\n";} |
103 | system("kill -CONT $PID"); | |
104 | } | |
bac7231b | 105 | elsif ($ARGV[0] eq 'next') { |
a28fdc01 CS |
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"); | |
109 | } | |
bac7231b | 110 | elsif ($ARGV[0] eq 'song') { |
8050f37b | 111 | &checkmute(); |
12a2f2ec | 112 | my $song = `lsof -nX \| grep mpg123 \| grep REG \| grep mem | grep mp3 \| grep -v "sh -c" \| grep -v "grep"`; |
a2d5130f CS |
113 | my @song = split(/\//,$song); |
114 | my $i = @song; | |
bac7231b | 115 | if ( $i == 0 ){ |
12a2f2ec CS |
116 | my $song = `ps -ef \| grep "wget -qO" \| grep -v "sh -c" \| grep -v "grep"`; |
117 | my @song = split(/http\:\/\//,$song); | |
118 | my $temp = $song[1]; | |
119 | my @song = split(/ /,$temp); | |
120 | print $song[0]; | |
a2d5130f | 121 | } |
bac7231b CS |
122 | else { print $song[$i-1];} |
123 | } | |
124 | elsif ($ARGV[0] eq 'playweb') { | |
a2d5130f | 125 | &General::readhash("${General::swroot}/proxy/settings", \%proxysettings); |
8050f37b | 126 | &checkmute(); |
8871b9f2 | 127 | |
a2d5130f CS |
128 | if ($proxysettings{'UPSTREAM_PROXY'}) { |
129 | if ($proxysettings{'UPSTREAM_USER'}) { | |
8871b9f2 CS |
130 | &checkm3uproxy(); |
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 &"); | |
a2d5130f | 133 | } |
8871b9f2 CS |
134 | else { |
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 &");} | |
a2d5130f | 138 | } else { |
8871b9f2 CS |
139 | &checkm3u(); |
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 &"); | |
a2d5130f CS |
142 | } |
143 | } | |
8050f37b CS |
144 | elsif ($ARGV[0] eq 'volume') { |
145 | $temp = "Master - "; | |
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 }'`; | |
149 | print $temp; | |
150 | } | |
a2d5130f | 151 | |
a28fdc01 CS |
152 | sub getSongInfo(){ |
153 | my $mp3 = MP3::Tag->new($filename); | |
154 | my ($title, $track, $artist, $album, $comment, $year, $genre) = $mp3->autoinfo(); | |
155 | my $info = get_mp3info($filename); | |
156 | $mp3->close(); | |
157 | $songs{$filename} = "|".$artist."|".$title."|".$track."|".$album."|".$year."|".$genre."|".$info->{MM}."|".$info->{SS}."|".$info->{BITRATE}."|".$info->{FREQUENCY}."|".$info->{MODE}."\n"; | |
158 | } | |
159 | ||
160 | sub getExistingSongs(){ | |
161 | open(DATEI, "<${General::swroot}/mpfire/db/songs.db") || die "Keine Datenbank vorhanden"; | |
162 | my @Zeilen = <DATEI>; | |
163 | close(DATEI); | |
164 | foreach (@Zeilen){ | |
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"; | |
167 | } | |
168 | } | |
8871b9f2 CS |
169 | |
170 | sub checkplaylist(){ | |
171 | my $Datei = "/var/ipfire/mpfire/playlist"; | |
172 | my @Info = stat($Datei); | |
d39a5cb6 | 173 | if ( $Info[7] eq '' || $Info[7] eq '0' ){print "There is no playlist";exit(1);} |
8871b9f2 CS |
174 | } |
175 | ||
8050f37b CS |
176 | sub checkmute(){ |
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"); | |
184 | } | |
185 | if ( $Master[7] =~ /off/ ){ | |
186 | if ($debug){print "Master was muted - umuting.\n";} | |
187 | system("amixer set Master toggle"); | |
188 | } | |
189 | } | |
190 | ||
8871b9f2 CS |
191 | sub checkm3u(){ |
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);} | |
194 | } | |
195 | ||
196 | sub checkm3uproxy(){ | |
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);} | |
199 | } | |
200 | ||
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);} | |
204 | } |