]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blame - config/mpfire/mpfire.pl
MPFire Copyright korrigiert
[people/pmueller/ipfire-2.x.git] / config / mpfire / mpfire.pl
CommitLineData
a28fdc01 1#!/usr/bin/perl
a28fdc01
CS
2
3require '/var/ipfire/general-functions.pl';
4require "${General::swroot}/lang.pl";
5require "${General::swroot}/header.pl";
6
7my $filename = "";
70ccd4a7 8my $debug = 0;
a28fdc01 9
70ccd4a7
CS
10if ( ! -e /var/run/mpd.pid){
11 system("mpd >/dev/null");
a28fdc01
CS
12}
13
70ccd4a7
CS
14if ($ARGV[0] eq 'scan') {
15 if ($debug){print "Creating Database\n";}
16 system("mpd --create-db >/dev/null");
17}
bac7231b 18elsif ($ARGV[0] eq 'play') {
8050f37b 19 &checkmute();
70ccd4a7 20 &clearplaylist();
a28fdc01 21 if ($debug){print "Yes we are called and we will play $ARGV[1]\n";}
70ccd4a7 22 system("mpc add \"$ARGV[1]\" >/dev/null && mpc play >/dev/null");
a28fdc01 23 }
70ccd4a7
CS
24elsif ($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 }
28elsif ($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");
8871b9f2 33 }
70ccd4a7
CS
34elsif ($ARGV[0] eq 'clearplaylist') {
35 if ($debug){print "Deleting playlist\n";}
36 &clearplaylist();
8871b9f2 37 }
70ccd4a7
CS
38elsif ($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");
a28fdc01 42 }
bac7231b 43elsif ($ARGV[0] eq 'volup') {
a28fdc01
CS
44 if ($debug){print "Increasing Volume\n";}
45 system("/usr/bin/amixer set Master $ARGV[1]%+ 2>/dev/null >/dev/null");
05882fff 46 system("/usr/bin/amixer set PCM $ARGV[1]%+ 2>/dev/null >/dev/null");
a28fdc01 47 }
bac7231b 48elsif ($ARGV[0] eq 'voldown') {
a28fdc01
CS
49 if ($debug){print "Decreasing Volume\n";}
50 system("/usr/bin/amixer set Master $ARGV[1]%- 2>/dev/null >/dev/null");
05882fff 51 system("/usr/bin/amixer set PCM $ARGV[1]%- 2>/dev/null >/dev/null");
a28fdc01 52 }
bac7231b 53elsif ($ARGV[0] eq 'playall') {
a28fdc01 54 if ($debug){print "Playing everything\n";}
70ccd4a7 55 system("mpc play >/dev/null");
a28fdc01 56 }
70ccd4a7
CS
57elsif ($ARGV[0] eq 'toggle') {
58 system("mpc toggle >/dev/null");
a28fdc01 59 }
bac7231b 60elsif ($ARGV[0] eq 'next') {
a28fdc01 61 if ($debug){print "Next Song\n";}
70ccd4a7
CS
62 system("mpc next >/dev/null[");
63 }
64elsif ( $ARGV[0] eq 'prev' ) {
65 if ($debug){print "Previous Song\n";}
66 system("mpc prev >/dev/null");
a28fdc01 67 }
bac7231b 68elsif ($ARGV[0] eq 'song') {
70ccd4a7
CS
69 my $song = `mpc \| head -2 | grep -v volume`;
70 print $song;
71 }
72elsif ($ARGV[0] eq 'stats') {
73 my $song = `mpc stats | grep Songs`;
74 print $song;
bac7231b
CS
75 }
76elsif ($ARGV[0] eq 'playweb') {
8050f37b 77 &checkmute();
70ccd4a7
CS
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");
a2d5130f 81 }
8050f37b
CS
82elsif ($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}
a2d5130f 89
70ccd4a7
CS
90sub clearplaylist(){
91 system("mpc clear >/dev/null");
a28fdc01
CS
92 }
93
8871b9f2 94sub checkplaylist(){
70ccd4a7 95 my $Datei = "/var/ipfire/mpfire/playlist.m3u";
8871b9f2 96 my @Info = stat($Datei);
d39a5cb6 97 if ( $Info[7] eq '' || $Info[7] eq '0' ){print "There is no playlist";exit(1);}
8871b9f2
CS
98}
99
8050f37b
CS
100sub 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}