]>
Commit | Line | Data |
---|---|---|
a28fdc01 | 1 | #!/usr/bin/perl |
a28fdc01 CS |
2 | |
3 | require '/var/ipfire/general-functions.pl'; | |
4 | require "${General::swroot}/lang.pl"; | |
5 | require "${General::swroot}/header.pl"; | |
6 | ||
7 | my $filename = ""; | |
70ccd4a7 | 8 | my $debug = 0; |
a28fdc01 | 9 | |
70ccd4a7 CS |
10 | if ($ARGV[0] eq 'scan') { |
11 | if ($debug){print "Creating Database\n";} | |
12 | system("mpd --create-db >/dev/null"); | |
13 | } | |
bac7231b | 14 | elsif ($ARGV[0] eq 'play') { |
8050f37b | 15 | &checkmute(); |
70ccd4a7 | 16 | &clearplaylist(); |
a28fdc01 | 17 | if ($debug){print "Yes we are called and we will play $ARGV[1]\n";} |
70ccd4a7 | 18 | system("mpc add \"$ARGV[1]\" >/dev/null && mpc play >/dev/null"); |
a28fdc01 | 19 | } |
70ccd4a7 CS |
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"); | |
8871b9f2 | 29 | } |
70ccd4a7 CS |
30 | elsif ($ARGV[0] eq 'clearplaylist') { |
31 | if ($debug){print "Deleting playlist\n";} | |
32 | &clearplaylist(); | |
8871b9f2 | 33 | } |
70ccd4a7 CS |
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"); | |
a28fdc01 | 38 | } |
bac7231b | 39 | elsif ($ARGV[0] eq 'volup') { |
a28fdc01 CS |
40 | if ($debug){print "Increasing Volume\n";} |
41 | system("/usr/bin/amixer set Master $ARGV[1]%+ 2>/dev/null >/dev/null"); | |
05882fff | 42 | system("/usr/bin/amixer set PCM $ARGV[1]%+ 2>/dev/null >/dev/null"); |
a28fdc01 | 43 | } |
bac7231b | 44 | elsif ($ARGV[0] eq 'voldown') { |
a28fdc01 CS |
45 | if ($debug){print "Decreasing Volume\n";} |
46 | system("/usr/bin/amixer set Master $ARGV[1]%- 2>/dev/null >/dev/null"); | |
05882fff | 47 | system("/usr/bin/amixer set PCM $ARGV[1]%- 2>/dev/null >/dev/null"); |
a28fdc01 | 48 | } |
bac7231b | 49 | elsif ($ARGV[0] eq 'playall') { |
a28fdc01 | 50 | if ($debug){print "Playing everything\n";} |
70ccd4a7 | 51 | system("mpc play >/dev/null"); |
a28fdc01 | 52 | } |
70ccd4a7 CS |
53 | elsif ($ARGV[0] eq 'toggle') { |
54 | system("mpc toggle >/dev/null"); | |
a28fdc01 | 55 | } |
bac7231b | 56 | elsif ($ARGV[0] eq 'next') { |
a28fdc01 | 57 | if ($debug){print "Next Song\n";} |
70ccd4a7 CS |
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"); | |
a28fdc01 | 63 | } |
bac7231b | 64 | elsif ($ARGV[0] eq 'song') { |
70ccd4a7 CS |
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; | |
bac7231b CS |
71 | } |
72 | elsif ($ARGV[0] eq 'playweb') { | |
8050f37b | 73 | &checkmute(); |
9a6214e0 | 74 | &stop(); |
70ccd4a7 CS |
75 | &clearplaylist(); |
76 | if ($debug){print "Playing webstream $ARGV[1] \n";} | |
9a6214e0 | 77 | system("mpc add \"http://$ARGV[1]\" >/dev/null && mpc play >/dev/null && sleep 1"); |
a2d5130f | 78 | } |
8050f37b CS |
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 | } | |
a2d5130f | 86 | |
70ccd4a7 CS |
87 | sub clearplaylist(){ |
88 | system("mpc clear >/dev/null"); | |
a28fdc01 CS |
89 | } |
90 | ||
9a6214e0 CS |
91 | sub stop(){ |
92 | system("mpc stop >/dev/null"); | |
93 | } | |
94 | ||
8871b9f2 | 95 | sub checkplaylist(){ |
70ccd4a7 | 96 | my $Datei = "/var/ipfire/mpfire/playlist.m3u"; |
8871b9f2 | 97 | my @Info = stat($Datei); |
d39a5cb6 | 98 | if ( $Info[7] eq '' || $Info[7] eq '0' ){print "There is no playlist";exit(1);} |
8871b9f2 CS |
99 | } |
100 | ||
8050f37b CS |
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 | } |