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