]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blame - config/mpfire/mpfire.pl
Control Skripe korrigiert
[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 = "";
a2d5130f 12my $debug = 1;
a28fdc01
CS
13
14if ($ARGV[0] eq 'scan') {
15my $command = "find ";
16chomp $ARGV[1];
17$command .= "\"$ARGV[1]\"";
18if ($ARGV[2] eq 'off'){$command .= " -maxdepth 1";}
19$command .= " -name *.mp3";
20my @files = `$command`;
21
22&getExistingSongs();
23
24foreach (@files){
25 $filename = $_;
26 chomp($filename)
27 &getSongInfo();
28 }
29open(DATEI, ">${General::swroot}/mpfire/db/songs.db") || die "Kann Datenbank nicht speichern";
30print DATEI %songs;
31close(DATEI);
32}
33
34if ($ARGV[0] eq 'getdb') {
35 &getExistingSongs();
36 print %songs;
37 }
bac7231b 38elsif ($ARGV[0] eq 'play') {
a28fdc01
CS
39 if ($debug){print "Yes we are called and we will play $ARGV[1]\n";}
40 system("/usr/bin/mpg123 -b 1024 --aggressive -q \"$ARGV[1]\" 2>/dev/null >/dev/null &");
41 }
bac7231b 42elsif ($ARGV[0] eq 'stop') {
a28fdc01 43 my $PID = `ps -ef | grep mpg123 | grep playlist | head -1 | awk '{ print \$2 }'`;
a2d5130f
CS
44 if ( $PID ne "" ){
45 if ($debug){print "Stopping $PID\n";}
46 system("kill -KILL $PID");
47 }
48 else {&stopweb();}
a28fdc01 49 }
bac7231b 50elsif ($ARGV[0] eq 'volup') {
a28fdc01
CS
51 if ($debug){print "Increasing Volume\n";}
52 system("/usr/bin/amixer set Master $ARGV[1]%+ 2>/dev/null >/dev/null");
53 }
bac7231b 54elsif ($ARGV[0] eq 'voldown') {
a28fdc01
CS
55 if ($debug){print "Decreasing Volume\n";}
56 system("/usr/bin/amixer set Master $ARGV[1]%- 2>/dev/null >/dev/null");
57 }
bac7231b 58elsif ($ARGV[0] eq 'playall') {
a28fdc01
CS
59 if ($debug){print "Playing everything\n";}
60 system("/usr/bin/mpg123 -b 1024 --aggressive -Zq@ /var/ipfire/mpfire/playlist 2>/dev/null >/dev/null &");
61 }
bac7231b 62elsif ($ARGV[0] eq 'pause') {
a28fdc01
CS
63 my $PID = `ps -ef | grep mpg123 | grep playlist | head -1 | awk '{ print \$2 }'`;
64 if ($debug){print "Pausing Process $PID\n";}
65 system("kill -STOP $PID");
66 }
bac7231b 67elsif ($ARGV[0] eq 'resume') {
a28fdc01
CS
68 my $PID = `ps -ef | grep mpg123 | grep playlist | head -1 | awk '{ print \$2 }'`;
69 if ($debug){print "Resuming Process $PID\n";}
70 system("kill -CONT $PID");
71 }
bac7231b 72elsif ($ARGV[0] eq 'next') {
a28fdc01
CS
73 if ($debug){print "Next Song\n";}
74 my $PID = `ps -ef | grep mpg123 | grep playlist | head -1 | awk '{ print \$2 }'`;
75 system("kill -SIGINT $PID");
76 }
bac7231b
CS
77elsif ($ARGV[0] eq 'song') {
78 my $song = `lsof -nX \| grep mpg123 \| grep REG \| grep mem | grep mp3 \| grep -v "sh -c"`;
a2d5130f
CS
79 my @song = split(/\//,$song);
80 my $i = @song;
bac7231b
CS
81 if ( $i == 0 ){
82 my $song = `ps -ef \| grep wget \| grep EXTM3U \| grep -v "sh -c"`;
83 my @song = split(/\//,$song);
84 print $song[2];
a2d5130f 85 }
bac7231b
CS
86 else { print $song[$i-1];}
87 }
88elsif ($ARGV[0] eq 'playweb') {
a2d5130f
CS
89 &General::readhash("${General::swroot}/proxy/settings", \%proxysettings);
90 if ($debug){print "Playing webstream\n";}
91 if ($proxysettings{'UPSTREAM_PROXY'}) {
92 if ($proxysettings{'UPSTREAM_USER'}) {
93 system("wget -qO - `wget -qO - $ARGV[1]` | mpg123 -b 1024 --aggressive -Zq - -p $proxysettings{'UPSTREAM_USER'}:$proxysettings{'UPSTREAM_PASSWORD'}@$proxysettings{'UPSTREAM_PROXY'} 2>/dev/null >/dev/null &");
94 }
95 else { system("wget -qO - `wget -qO - $ARGV[1]` | mpg123 -b 1024 --aggressive -Zq - -p $proxysettings{'UPSTREAM_PROXY'} 2>/dev/null >/dev/null &");}
96 } else {
97 system("wget -qO - `wget -qO - $ARGV[1]` | mpg123 -b 1024 --aggressive -Zq - 2>/dev/null >/dev/null &");
98 }
99 }
bac7231b 100elsif ($ARGV[0] eq 'stopweb') {
a2d5130f
CS
101 &stopweb();
102 }
103
104sub stopweb(){
105 my $PID = `ps -ef | grep wget | grep EXTM3U | head -1 | awk '{ print \$2 }'`;
106 if ($debug){print "Stopping $PID\n";}
107 system("kill -KILL $PID");
108 my $PID = `ps -ef | grep "mpg123 -b 1024 --aggressive -Zq -" | head -1 | awk '{ print \$2 }'`;
109 if ($debug){print "Killing Process $PID\n";}
110 system("kill -KILL $PID");
111 }
112
a28fdc01
CS
113sub getSongInfo(){
114 my $mp3 = MP3::Tag->new($filename);
115 my ($title, $track, $artist, $album, $comment, $year, $genre) = $mp3->autoinfo();
116 my $info = get_mp3info($filename);
117 $mp3->close();
118 $songs{$filename} = "|".$artist."|".$title."|".$track."|".$album."|".$year."|".$genre."|".$info->{MM}."|".$info->{SS}."|".$info->{BITRATE}."|".$info->{FREQUENCY}."|".$info->{MODE}."\n";
119 }
120
121sub getExistingSongs(){
122 open(DATEI, "<${General::swroot}/mpfire/db/songs.db") || die "Keine Datenbank vorhanden";
123 my @Zeilen = <DATEI>;
124 close(DATEI);
125 foreach (@Zeilen){
126 my @Zeile = split(/\|/,$_);
127 $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";
128 }
129 }