]>
git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - config/mpfire/mpfire.pl
6 require '/var/ipfire/general-functions.pl';
7 require "${General::swroot}/lang.pl";
8 require "${General::swroot}/header.pl";
14 if ($ARGV[0] eq 'scan') {
15 my $command = "find ";
17 $command .= "\"$ARGV[1]\"";
18 if ($ARGV[2] eq 'off'){$command .= " -maxdepth 1";}
19 $command .= " -name *.mp3";
20 my @files = `$command`;
29 open(DATEI
, ">${General::swroot}/mpfire/db/songs.db") || die "Kann Datenbank nicht speichern";
34 if ($ARGV[0] eq 'getdb') {
38 elsif ($ARGV[0] eq 'play') {
40 if ($debug){print "Yes we are called and we will play $ARGV[1]\n";}
41 system("/usr/bin/mpg123 -b 1024 --aggressive -q \"$ARGV[1]\" 2>/dev/null >/dev/null &");
43 elsif ($ARGV[0] eq 'stop') {
44 my $PID = `ps -ef \| grep "wget -qO" \| head -1 \| grep -v "sh -c" \| awk '{ print \$2 }'`;
46 if ($debug){print "Stopping $PID\n";}
47 system("kill -KILL $PID");
48 my $PID = `ps -ef \| grep "mpg123 -b 1024 --aggressive -Zq -" \| head -1 \| grep -v "sh -c" \| awk '{ print \$2 }'`;
49 if ($debug){print "Killing Process $PID\n";}
50 system("kill -KILL $PID");
53 my $PID = `ps -ef \| grep mpg123 \| grep playlist \| head -1 \| grep -v "sh -c" \| awk '{ print \$2 }'`;
54 if ($debug){print "Stopping $PID\n";}
55 system("kill -KILL $PID");
58 elsif ($ARGV[0] eq 'volup') {
59 if ($debug){print "Increasing Volume\n";}
60 system("/usr/bin/amixer set Master $ARGV[1]%+ 2>/dev/null >/dev/null");
62 elsif ($ARGV[0] eq 'voldown') {
63 if ($debug){print "Decreasing Volume\n";}
64 system("/usr/bin/amixer set Master $ARGV[1]%- 2>/dev/null >/dev/null");
66 elsif ($ARGV[0] eq 'playall') {
68 if ($debug){print "Playing everything\n";}
69 system("/usr/bin/mpg123 -b 1024 --aggressive -Zq@ /var/ipfire/mpfire/playlist 2>/dev/null >/dev/null &");
71 elsif ($ARGV[0] eq 'pause') {
72 my $PID = `ps -ef \| grep mpg123 \| grep playlist \| head -1 \| grep -v "sh -c" \| grep -v "grep" \| awk '{ print \$2 }'`;
73 if ($debug){print "Pausing Process $PID\n";}
74 system("kill -STOP $PID");
76 elsif ($ARGV[0] eq 'resume') {
77 my $PID = `ps -ef \| grep mpg123 \| grep playlist \| head -1 \| grep -v "sh -c" \| grep -v "grep" \| awk '{ print \$2 }'`;
78 if ($debug){print "Resuming Process $PID\n";}
79 system("kill -CONT $PID");
81 elsif ($ARGV[0] eq 'next') {
82 if ($debug){print "Next Song\n";}
83 my $PID = `ps -ef | grep mpg123 | grep playlist | head -1 | awk '{ print \$2 }'`;
84 system("kill -SIGINT $PID");
86 elsif ($ARGV[0] eq 'song') {
87 my $song = `lsof -nX \| grep mpg123 \| grep REG \| grep mem | grep mp3 \| grep -v "sh -c" \| grep -v "grep"`;
88 my @song = split(/\//,$song);
91 my $song = `ps -ef \| grep "wget -qO" \| grep -v "sh -c" \| grep -v "grep"`;
92 my @song = split(/http\:\/\
//,$song);
94 my @song = split(/ /,$temp);
97 else { print $song[$i-1];}
99 elsif ($ARGV[0] eq 'playweb') {
100 &General
::readhash
("${General::swroot}/proxy/settings", \
%proxysettings);
102 if ($proxysettings{'UPSTREAM_PROXY'}) {
103 if ($proxysettings{'UPSTREAM_USER'}) {
105 if ($debug){print "Playing webstream\n";}
106 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 &");
109 &checkm3uproxyuser
();
110 if ($debug){print "Playing webstream\n";}
111 system("wget -qO - `wget -qO - http://$proxysettings{'UPSTREAM_PROXY'}$ARGV[1]` | mpg123 -b 1024 --aggressive -Zq - 2>/dev/null >/dev/null &");}
114 if ($debug){print "Playing webstream\n";}
115 system("wget -qO - `wget -qO - http://$ARGV[1]` | mpg123 -b 1024 --aggressive -Zq - 2>/dev/null >/dev/null &");
120 my $mp3 = MP3
::Tag
->new($filename);
121 my ($title, $track, $artist, $album, $comment, $year, $genre) = $mp3->autoinfo();
122 my $info = get_mp3info
($filename);
124 $songs{$filename} = "|".$artist."|".$title."|".$track."|".$album."|".$year."|".$genre."|".$info->{MM
}."|".$info->{SS
}."|".$info->{BITRATE
}."|".$info->{FREQUENCY
}."|".$info->{MODE
}."\n";
127 sub getExistingSongs
(){
128 open(DATEI
, "<${General::swroot}/mpfire/db/songs.db") || die "Keine Datenbank vorhanden";
129 my @Zeilen = <DATEI
>;
132 my @Zeile = split(/\|/,$_);
133 $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";
138 my $Datei = "/var/ipfire/mpfire/playlist";
139 my @Info = stat($Datei);
140 if ( $Info[7] eq '' || $Info[7] eq '0' ){print "There is no playlist";exit(1);}
144 my $Datei = system("wget -q --spider http://$ARGV[1]");
145 if ( $Datei ne '0' ){print "We are unable to get the stream";exit(1);}
149 my $Datei = system("wget -q --spider http://$ARGV[1]");
150 if ( $Datei ne '0' ){print "We are unable to get the stream";exit(1);}
153 sub checkm3uproxyuser
(){
154 my $Datei = system("wget -q --spider http://$ARGV[1]");
155 if ( $Datei ne '0' ){print "We are unable to get the stream";exit(1);}