]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blame - config/mpfire/mpfire.pl
Kleiner Glibc-Fehler vom Detlef entdeckt.
[people/pmueller/ipfire-2.x.git] / config / mpfire / mpfire.pl
CommitLineData
a28fdc01
CS
1#!/usr/bin/perl
2
3use MP3::Tag;
4use MP3::Info;
5
6require '/var/ipfire/general-functions.pl';
7require "${General::swroot}/lang.pl";
8require "${General::swroot}/header.pl";
9
10my $filename = "";
11my %songs = "";
d39a5cb6 12my $debug = 1;
8050f37b 13my $temp;
a28fdc01
CS
14
15if ($ARGV[0] eq 'scan') {
16my $command = "find ";
17chomp $ARGV[1];
18$command .= "\"$ARGV[1]\"";
19if ($ARGV[2] eq 'off'){$command .= " -maxdepth 1";}
20$command .= " -name *.mp3";
21my @files = `$command`;
22
23&getExistingSongs();
24
25foreach (@files){
26 $filename = $_;
27 chomp($filename)
28 &getSongInfo();
29 }
30open(DATEI, ">${General::swroot}/mpfire/db/songs.db") || die "Kann Datenbank nicht speichern";
31print DATEI %songs;
32close(DATEI);
33}
34
35if ($ARGV[0] eq 'getdb') {
36 &getExistingSongs();
37 print %songs;
38 }
bac7231b 39elsif ($ARGV[0] eq 'play') {
8871b9f2 40 &checkplaylist();
8050f37b 41 &checkmute();
a28fdc01
CS
42 if ($debug){print "Yes we are called and we will play $ARGV[1]\n";}
43 system("/usr/bin/mpg123 -b 1024 --aggressive -q \"$ARGV[1]\" 2>/dev/null >/dev/null &");
44 }
bac7231b 45elsif ($ARGV[0] eq 'stop') {
12a2f2ec 46 my $PID = `ps -ef \| grep "wget -qO" \| head -1 \| grep -v "sh -c" \| awk '{ print \$2 }'`;
8871b9f2
CS
47 if ( $PID ne '' ){
48 if ($debug){print "Stopping $PID\n";}
49 system("kill -KILL $PID");
50 my $PID = `ps -ef \| grep "mpg123 -b 1024 --aggressive -Zq -" \| head -1 \| grep -v "sh -c" \| awk '{ print \$2 }'`;
51 if ($debug){print "Killing Process $PID\n";}
52 system("kill -KILL $PID");
53 }
54 else{
55 my $PID = `ps -ef \| grep mpg123 \| grep playlist \| head -1 \| grep -v "sh -c" \| awk '{ print \$2 }'`;
56 if ($debug){print "Stopping $PID\n";}
57 system("kill -KILL $PID");
58 }
a28fdc01 59 }
bac7231b 60elsif ($ARGV[0] eq 'volup') {
a28fdc01
CS
61 if ($debug){print "Increasing Volume\n";}
62 system("/usr/bin/amixer set Master $ARGV[1]%+ 2>/dev/null >/dev/null");
63 }
bac7231b 64elsif ($ARGV[0] eq 'voldown') {
a28fdc01
CS
65 if ($debug){print "Decreasing Volume\n";}
66 system("/usr/bin/amixer set Master $ARGV[1]%- 2>/dev/null >/dev/null");
67 }
bac7231b 68elsif ($ARGV[0] eq 'playall') {
8871b9f2 69 &checkplaylist();
8050f37b 70 &checkmute();
a28fdc01
CS
71 if ($debug){print "Playing everything\n";}
72 system("/usr/bin/mpg123 -b 1024 --aggressive -Zq@ /var/ipfire/mpfire/playlist 2>/dev/null >/dev/null &");
73 }
bac7231b 74elsif ($ARGV[0] eq 'pause') {
12a2f2ec 75 my $PID = `ps -ef \| grep mpg123 \| grep playlist \| head -1 \| grep -v "sh -c" \| grep -v "grep" \| awk '{ print \$2 }'`;
a28fdc01
CS
76 if ($debug){print "Pausing Process $PID\n";}
77 system("kill -STOP $PID");
78 }
bac7231b 79elsif ($ARGV[0] eq 'resume') {
12a2f2ec 80 my $PID = `ps -ef \| grep mpg123 \| grep playlist \| head -1 \| grep -v "sh -c" \| grep -v "grep" \| awk '{ print \$2 }'`;
a28fdc01
CS
81 if ($debug){print "Resuming Process $PID\n";}
82 system("kill -CONT $PID");
83 }
bac7231b 84elsif ($ARGV[0] eq 'next') {
a28fdc01
CS
85 if ($debug){print "Next Song\n";}
86 my $PID = `ps -ef | grep mpg123 | grep playlist | head -1 | awk '{ print \$2 }'`;
87 system("kill -SIGINT $PID");
88 }
bac7231b 89elsif ($ARGV[0] eq 'song') {
8050f37b 90 &checkmute();
12a2f2ec 91 my $song = `lsof -nX \| grep mpg123 \| grep REG \| grep mem | grep mp3 \| grep -v "sh -c" \| grep -v "grep"`;
a2d5130f
CS
92 my @song = split(/\//,$song);
93 my $i = @song;
bac7231b 94 if ( $i == 0 ){
12a2f2ec
CS
95 my $song = `ps -ef \| grep "wget -qO" \| grep -v "sh -c" \| grep -v "grep"`;
96 my @song = split(/http\:\/\//,$song);
97 my $temp = $song[1];
98 my @song = split(/ /,$temp);
99 print $song[0];
a2d5130f 100 }
bac7231b
CS
101 else { print $song[$i-1];}
102 }
103elsif ($ARGV[0] eq 'playweb') {
a2d5130f 104 &General::readhash("${General::swroot}/proxy/settings", \%proxysettings);
8050f37b 105 &checkmute();
8871b9f2 106
a2d5130f
CS
107 if ($proxysettings{'UPSTREAM_PROXY'}) {
108 if ($proxysettings{'UPSTREAM_USER'}) {
8871b9f2
CS
109 &checkm3uproxy();
110 if ($debug){print "Playing webstream\n";}
111 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 112 }
8871b9f2
CS
113 else {
114 &checkm3uproxyuser();
115 if ($debug){print "Playing webstream\n";}
116 system("wget -qO - `wget -qO - http://$proxysettings{'UPSTREAM_PROXY'}$ARGV[1]` | mpg123 -b 1024 --aggressive -Zq - 2>/dev/null >/dev/null &");}
a2d5130f 117 } else {
8871b9f2
CS
118 &checkm3u();
119 if ($debug){print "Playing webstream\n";}
120 system("wget -qO - `wget -qO - http://$ARGV[1]` | mpg123 -b 1024 --aggressive -Zq - 2>/dev/null >/dev/null &");
a2d5130f
CS
121 }
122 }
8050f37b
CS
123elsif ($ARGV[0] eq 'volume') {
124 $temp = "Master - ";
125 $temp .= `amixer get Master \| tail -2 \| awk '{ print \$2" "\$5 }'`;
126 $temp .= "<break>PCM -";
127 $temp .= `amixer get PCM \| tail -2 \| awk '{ print \$2" "\$5 }'`;
128 print $temp;
129}
a2d5130f 130
a28fdc01
CS
131sub getSongInfo(){
132 my $mp3 = MP3::Tag->new($filename);
133 my ($title, $track, $artist, $album, $comment, $year, $genre) = $mp3->autoinfo();
134 my $info = get_mp3info($filename);
135 $mp3->close();
136 $songs{$filename} = "|".$artist."|".$title."|".$track."|".$album."|".$year."|".$genre."|".$info->{MM}."|".$info->{SS}."|".$info->{BITRATE}."|".$info->{FREQUENCY}."|".$info->{MODE}."\n";
137 }
138
139sub getExistingSongs(){
140 open(DATEI, "<${General::swroot}/mpfire/db/songs.db") || die "Keine Datenbank vorhanden";
141 my @Zeilen = <DATEI>;
142 close(DATEI);
143 foreach (@Zeilen){
144 my @Zeile = split(/\|/,$_);
145 $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";
146 }
147 }
8871b9f2
CS
148
149sub checkplaylist(){
150 my $Datei = "/var/ipfire/mpfire/playlist";
151 my @Info = stat($Datei);
d39a5cb6 152 if ( $Info[7] eq '' || $Info[7] eq '0' ){print "There is no playlist";exit(1);}
8871b9f2
CS
153}
154
8050f37b
CS
155sub checkmute(){
156 $temp = `amixer get Master \| tail -2`;
157 my @Master = split(/ /,$temp);
158 $temp = `amixer get PCM \| tail -2`;
159 my @PCM = split(/ /,$temp);
160 if ( $PCM[7] =~ /off/ ){
161 if ($debug){print "PCM was muted - umuting.\n";}
162 system("amixer set PCM toggle");
163 }
164 if ( $Master[7] =~ /off/ ){
165 if ($debug){print "Master was muted - umuting.\n";}
166 system("amixer set Master toggle");
167 }
168}
169
8871b9f2
CS
170sub checkm3u(){
171 my $Datei = system("wget -q --spider http://$ARGV[1]");
172 if ( $Datei ne '0' ){print "We are unable to get the stream";exit(1);}
173}
174
175sub checkm3uproxy(){
176 my $Datei = system("wget -q --spider http://$ARGV[1]");
177 if ( $Datei ne '0' ){print "We are unable to get the stream";exit(1);}
178}
179
180sub checkm3uproxyuser(){
181 my $Datei = system("wget -q --spider http://$ARGV[1]");
182 if ( $Datei ne '0' ){print "We are unable to get the stream";exit(1);}
183}