]>
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"); | |
85cedd09 | 13 | system("/etc/init.d/mpd restart"); |
70ccd4a7 | 14 | } |
bac7231b | 15 | elsif ($ARGV[0] eq 'play') { |
8050f37b | 16 | &checkmute(); |
70ccd4a7 | 17 | &clearplaylist(); |
a28fdc01 | 18 | if ($debug){print "Yes we are called and we will play $ARGV[1]\n";} |
70ccd4a7 | 19 | system("mpc add \"$ARGV[1]\" >/dev/null && mpc play >/dev/null"); |
a28fdc01 | 20 | } |
70ccd4a7 CS |
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(); | |
85cedd09 | 27 | &shuffle(); |
70ccd4a7 CS |
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"); | |
8871b9f2 | 31 | } |
70ccd4a7 CS |
32 | elsif ($ARGV[0] eq 'clearplaylist') { |
33 | if ($debug){print "Deleting playlist\n";} | |
34 | &clearplaylist(); | |
8871b9f2 | 35 | } |
70ccd4a7 CS |
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"); | |
a28fdc01 | 40 | } |
bac7231b | 41 | elsif ($ARGV[0] eq 'volup') { |
a28fdc01 CS |
42 | if ($debug){print "Increasing Volume\n";} |
43 | system("/usr/bin/amixer set Master $ARGV[1]%+ 2>/dev/null >/dev/null"); | |
05882fff | 44 | system("/usr/bin/amixer set PCM $ARGV[1]%+ 2>/dev/null >/dev/null"); |
a28fdc01 | 45 | } |
bac7231b | 46 | elsif ($ARGV[0] eq 'voldown') { |
a28fdc01 CS |
47 | if ($debug){print "Decreasing Volume\n";} |
48 | system("/usr/bin/amixer set Master $ARGV[1]%- 2>/dev/null >/dev/null"); | |
05882fff | 49 | system("/usr/bin/amixer set PCM $ARGV[1]%- 2>/dev/null >/dev/null"); |
a28fdc01 | 50 | } |
70ccd4a7 CS |
51 | elsif ($ARGV[0] eq 'toggle') { |
52 | system("mpc toggle >/dev/null"); | |
a28fdc01 | 53 | } |
bac7231b | 54 | elsif ($ARGV[0] eq 'next') { |
a28fdc01 | 55 | if ($debug){print "Next Song\n";} |
70ccd4a7 CS |
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"); | |
a28fdc01 | 61 | } |
bac7231b | 62 | elsif ($ARGV[0] eq 'song') { |
70ccd4a7 CS |
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; | |
bac7231b CS |
69 | } |
70 | elsif ($ARGV[0] eq 'playweb') { | |
8050f37b | 71 | &checkmute(); |
70ccd4a7 CS |
72 | &clearplaylist(); |
73 | if ($debug){print "Playing webstream $ARGV[1] \n";} | |
85cedd09 | 74 | system("mpc add http://$ARGV[1] >/dev/null && mpc play >/dev/null && sleep 1"); |
a2d5130f | 75 | } |
8050f37b CS |
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 | } | |
a2d5130f | 83 | |
70ccd4a7 CS |
84 | sub clearplaylist(){ |
85 | system("mpc clear >/dev/null"); | |
a28fdc01 CS |
86 | } |
87 | ||
85cedd09 CS |
88 | sub shuffle(){ |
89 | system("mpc shuffle >/dev/null"); | |
9a6214e0 CS |
90 | } |
91 | ||
8871b9f2 | 92 | sub checkplaylist(){ |
70ccd4a7 | 93 | my $Datei = "/var/ipfire/mpfire/playlist.m3u"; |
8871b9f2 | 94 | my @Info = stat($Datei); |
d39a5cb6 | 95 | if ( $Info[7] eq '' || $Info[7] eq '0' ){print "There is no playlist";exit(1);} |
8871b9f2 CS |
96 | } |
97 | ||
8050f37b CS |
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 | } |