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