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