MPFire Version 2 begonnen
[people/pmueller/ipfire-2.x.git] / config / mpfire / mpfire.pl
1 #!/usr/bin/perl
2
3 require '/var/ipfire/general-functions.pl';
4 require "${General::swroot}/lang.pl";
5 require "${General::swroot}/header.pl";
6
7 my $filename = "";
8 my $debug = 0;
9
10 if ( ! -e /var/run/mpd.pid){
11 system("mpd >/dev/null");
12 }
13
14 if ($ARGV[0] eq 'scan') {
15 if ($debug){print "Creating Database\n";}
16 system("mpd --create-db >/dev/null");
17 }
18 elsif ($ARGV[0] eq 'play') {
19 &checkmute();
20 &clearplaylist();
21 if ($debug){print "Yes we are called and we will play $ARGV[1]\n";}
22 system("mpc add \"$ARGV[1]\" >/dev/null && mpc play >/dev/null");
23 }
24 elsif ($ARGV[0] eq 'playadd') {
25 if ($debug){print "Yes we are called and we will add $ARGV[1]\n";}
26 system("mpc add \"$ARGV[1]\" >/dev/null && mpc play >/dev/null");
27 }
28 elsif ($ARGV[0] eq 'playlist') {
29 &checkmute();
30 &clearplaylist();
31 if ($debug){print "Yes we are called and we will play your Playlist\n";}
32 system("mpc load playlist >/dev/null && mpc play >/dev/null");
33 }
34 elsif ($ARGV[0] eq 'clearplaylist') {
35 if ($debug){print "Deleting playlist\n";}
36 &clearplaylist();
37 }
38 elsif ($ARGV[0] eq 'stop') {
39 my $PID = 'cat /var/run/mpd.pid';
40 if ($debug){print "Killing Process $PID\n";}
41 system("mpc stop >/dev/null");
42 }
43 elsif ($ARGV[0] eq 'volup') {
44 if ($debug){print "Increasing Volume\n";}
45 system("/usr/bin/amixer set Master $ARGV[1]%+ 2>/dev/null >/dev/null");
46 system("/usr/bin/amixer set PCM $ARGV[1]%+ 2>/dev/null >/dev/null");
47 }
48 elsif ($ARGV[0] eq 'voldown') {
49 if ($debug){print "Decreasing Volume\n";}
50 system("/usr/bin/amixer set Master $ARGV[1]%- 2>/dev/null >/dev/null");
51 system("/usr/bin/amixer set PCM $ARGV[1]%- 2>/dev/null >/dev/null");
52 }
53 elsif ($ARGV[0] eq 'playall') {
54 if ($debug){print "Playing everything\n";}
55 system("mpc play >/dev/null");
56 }
57 elsif ($ARGV[0] eq 'toggle') {
58 system("mpc toggle >/dev/null");
59 }
60 elsif ($ARGV[0] eq 'next') {
61 if ($debug){print "Next Song\n";}
62 system("mpc next >/dev/null[");
63 }
64 elsif ( $ARGV[0] eq 'prev' ) {
65 if ($debug){print "Previous Song\n";}
66 system("mpc prev >/dev/null");
67 }
68 elsif ($ARGV[0] eq 'song') {
69 my $song = `mpc \| head -2 | grep -v volume`;
70 print $song;
71 }
72 elsif ($ARGV[0] eq 'stats') {
73 my $song = `mpc stats | grep Songs`;
74 print $song;
75 }
76 elsif ($ARGV[0] eq 'playweb') {
77 &checkmute();
78 &clearplaylist();
79 if ($debug){print "Playing webstream $ARGV[1] \n";}
80 system("mpc add http://$ARGV[1] >/dev/null && mpc play >/dev/null && sleep 1");
81 }
82 elsif ($ARGV[0] eq 'volume') {
83 $temp = "Master - ";
84 $temp .= `amixer get Master \| tail -2 \| awk '{ print \$2" "\$5 }'`;
85 $temp .= "<break>PCM -";
86 $temp .= `amixer get PCM \| tail -2 \| awk '{ print \$2" "\$5 }'`;
87 print $temp;
88 }
89
90 sub clearplaylist(){
91 system("mpc clear >/dev/null");
92 }
93
94 sub checkplaylist(){
95 my $Datei = "/var/ipfire/mpfire/playlist.m3u";
96 my @Info = stat($Datei);
97 if ( $Info[7] eq '' || $Info[7] eq '0' ){print "There is no playlist";exit(1);}
98 }
99
100 sub checkmute(){
101 $temp = `amixer get Master \| tail -2`;
102 my @Master = split(/ /,$temp);
103 $temp = `amixer get PCM \| tail -2`;
104 my @PCM = split(/ /,$temp);
105 if ( $PCM[7] =~ /off/ ){
106 if ($debug){print "PCM was muted - umuting.\n";}
107 system("amixer set PCM toggle");
108 }
109 if ( $Master[7] =~ /off/ ){
110 if ($debug){print "Master was muted - umuting.\n";}
111 system("amixer set Master toggle");
112 }
113 }