-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmedia-mux-action.sh
More file actions
executable file
·74 lines (70 loc) · 2.63 KB
/
media-mux-action.sh
File metadata and controls
executable file
·74 lines (70 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/sh
#./media-mux-action.sh -i 192.168.8.5 -p passwd -a [status/stop]
USAGE="usage:$0 -i <ipaddr/hostname> -p <passwd> -a <stop/status/volume/custom> -v <value>"
IPADDR="127.0.0.1"
PASSWD="OmJyYjB4" #default-pw: brb0x
ACTION="status"
VALUE="none"
APIPORT=8080
while getopts i:p:a:v: f
do
case $f in
i) IPADDR=$OPTARG ;;
p) PASSWD=$OPTARG ;;
a) ACTION=$OPTARG ;;
v) VALUE=$OPTARG ;;
esac
done
if [ $# -lt 2 ]; then
echo $USAGE
exit 1
fi
#echo "IPADDR=$IPADDR";echo "PASSWD=$PASSWD";echo "ACTION=$ACTION"
if [ $PASSWD = "none" ]; then
echo "Error: missing password argument"
echo $USAGE
exit 1
fi
IP=$(printf "%-15s" $IPADDR)
if [ $ACTION = "status" ]; then
RES=$(curl -s -G -H "Authorization: Basic $PASSWD" "http://$IPADDR:$APIPORT/requests/status.xml" | grep state)
[ $? != "0" ] && echo "$IP:Error: action failed! unable to read player status (check if password is correct)" && exit 1
if [ $RES = "<state>stopped</state>" ]; then
echo "$IP:Player-state: Stopped"
elif [ $RES = "<state>stopped</state><information>" ]; then
echo "$IP:Player-state: Stopped"
elif [ $RES = "<state>playing</state>" ]; then
echo "$IP:Player-state: Playing"
elif [ $RES = "<state>playing</state><information>" ]; then
echo "$IP:Player-state: Playing"
else
echo "$IP:Player-state: $RES"
fi
elif [ $ACTION = "volume" ]; then
if [ $VALUE = "none" ]; then
RES=$(curl -s -G -H "Authorization: Basic $PASSWD" "http://$IPADDR:$APIPORT/requests/status.xml" | grep volume)
[ $? != "0" ] && echo "$IP:Error: action failed! unable to read volume (check if password is correct)" && exit 1
echo "$IP:$RES"
else
RES=$(curl -s -G -H "Authorization: Basic $PASSWD" "http://$IPADDR:$APIPORT/requests/status.xml" --data-urlencode "command=volume" --data-urlencode "val=$VALUE")
[ $? != "0" ] && echo "$IP:Error: action failed! unable set volume (check if password/volume-value is correct)" && exit 1
fi
elif [ $ACTION = "custom" ]; then
if [ $VALUE = "none" ]; then
echo "$IP:Error: custom action needs value argument"
echo $USAGE
exit 1
else
RES=$(curl -s -G -H "Authorization: Basic $PASSWD" "http://$IPADDR:$APIPORT/requests/status.xml" | grep $VALUE)
[ $? != "0" ] && echo "$IP:Error: action failed! unable to read custom value (check if password is correct)" && exit 1
echo "$IP:$RES"
fi
elif [ $ACTION = "stop" ]; then
RES=$(curl -s -G -H "Authorization: Basic $PASSWD" "http://$IPADDR:$APIPORT/requests/status.xml?command=pl_stop")
[ $? != "0" ] && echo "$IP:Error: action failed! unable to stop player (check if password is correct)" && exit 1
else
echo "$IP:Error: invalid action argument ==> $ACTION"
echo $USAGE
exit 1
fi
exit 0