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