]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blame - config/mpfire/mpfire.pl
Fixed some mpfire things
[people/pmueller/ipfire-2.x.git] / config / mpfire / mpfire.pl
CommitLineData
a28fdc01 1#!/usr/bin/perl
a28fdc01
CS
2
3require '/var/ipfire/general-functions.pl';
4require "${General::swroot}/lang.pl";
5require "${General::swroot}/header.pl";
6
7my $filename = "";
70ccd4a7 8my $debug = 0;
a28fdc01 9
931065d0
CS
10if ( `/etc/init.d/mpd status` =~/not running/ ){
11system("/etc/init.d/mpd start >/dev/null");
12}
13
70ccd4a7
CS
14if ($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 19elsif ($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
25elsif ($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 }
70ccd4a7
CS
29elsif ($ARGV[0] eq 'clearplaylist') {
30 if ($debug){print "Deleting playlist\n";}
31 &clearplaylist();
8871b9f2 32 }
70ccd4a7
CS
33elsif ($ARGV[0] eq 'stop') {
34 my $PID = 'cat /var/run/mpd.pid';
35 if ($debug){print "Killing Process $PID\n";}
36 system("mpc stop >/dev/null");
a28fdc01 37 }
bac7231b 38elsif ($ARGV[0] eq 'volup') {
a28fdc01
CS
39 if ($debug){print "Increasing Volume\n";}
40 system("/usr/bin/amixer set Master $ARGV[1]%+ 2>/dev/null >/dev/null");
05882fff 41 system("/usr/bin/amixer set PCM $ARGV[1]%+ 2>/dev/null >/dev/null");
a28fdc01 42 }
bac7231b 43elsif ($ARGV[0] eq 'voldown') {
a28fdc01
CS
44 if ($debug){print "Decreasing Volume\n";}
45 system("/usr/bin/amixer set Master $ARGV[1]%- 2>/dev/null >/dev/null");
05882fff 46 system("/usr/bin/amixer set PCM $ARGV[1]%- 2>/dev/null >/dev/null");
a28fdc01 47 }
70ccd4a7
CS
48elsif ($ARGV[0] eq 'toggle') {
49 system("mpc toggle >/dev/null");
a28fdc01 50 }
bac7231b 51elsif ($ARGV[0] eq 'next') {
a28fdc01 52 if ($debug){print "Next Song\n";}
70ccd4a7
CS
53 system("mpc next >/dev/null[");
54 }
55elsif ( $ARGV[0] eq 'prev' ) {
56 if ($debug){print "Previous Song\n";}
57 system("mpc prev >/dev/null");
a28fdc01 58 }
bac7231b 59elsif ($ARGV[0] eq 'song') {
70ccd4a7
CS
60 my $song = `mpc \| head -2 | grep -v volume`;
61 print $song;
62 }
63elsif ($ARGV[0] eq 'stats') {
64 my $song = `mpc stats | grep Songs`;
65 print $song;
bac7231b
CS
66 }
67elsif ($ARGV[0] eq 'playweb') {
8050f37b 68 &checkmute();
70ccd4a7
CS
69 &clearplaylist();
70 if ($debug){print "Playing webstream $ARGV[1] \n";}
85cedd09 71 system("mpc add http://$ARGV[1] >/dev/null && mpc play >/dev/null && sleep 1");
a2d5130f 72 }
8050f37b
CS
73elsif ($ARGV[0] eq 'volume') {
74 $temp = "Master - ";
75 $temp .= `amixer get Master \| tail -2 \| awk '{ print \$2" "\$5 }'`;
76 $temp .= "<break>PCM -";
77 $temp .= `amixer get PCM \| tail -2 \| awk '{ print \$2" "\$5 }'`;
78 print $temp;
79}
a2d5130f 80
70ccd4a7
CS
81sub clearplaylist(){
82 system("mpc clear >/dev/null");
a28fdc01
CS
83 }
84
85cedd09 85sub shuffle(){
5ad5a6bc 86 system("mpc random >/dev/null");
9a6214e0
CS
87 }
88
8871b9f2 89sub checkplaylist(){
70ccd4a7 90 my $Datei = "/var/ipfire/mpfire/playlist.m3u";
8871b9f2 91 my @Info = stat($Datei);
d39a5cb6 92 if ( $Info[7] eq '' || $Info[7] eq '0' ){print "There is no playlist";exit(1);}
8871b9f2
CS
93}
94
8050f37b
CS
95sub checkmute(){
96 $temp = `amixer get Master \| tail -2`;
97 my @Master = split(/ /,$temp);
98 $temp = `amixer get PCM \| tail -2`;
99 my @PCM = split(/ /,$temp);
100 if ( $PCM[7] =~ /off/ ){
101 if ($debug){print "PCM was muted - umuting.\n";}
96742484 102 system("amixer set PCM toggle >/dev/null");
8050f37b
CS
103 }
104 if ( $Master[7] =~ /off/ ){
105 if ($debug){print "Master was muted - umuting.\n";}
96742484 106 system("amixer set Master toggle >/dev/null");
8050f37b
CS
107 }
108}