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