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