In case you want to use a bash script, I would execute something via JSON and "jq". Maybe you have to install jq first according to the distro you are using.
By using:
curl -s -X POST http://127.0.0.1:8080/jsonrpc -H 'Content-Type: application/json' --data '{"jsonrpc":"2.0","method":"Player.GetActivePlayers","id":0}'
you will get a result like:
{"id":0,"jsonrpc":"2.0","result":[{"playerid":1,"playertype":"internal","type":"video"}]}
That's a bit hard to parse and probably a bit meh if you want to store something in a variable to check against. That's where "jq" comes in place. By executing the same command and pipe it through "jq" like:
curl -s -X POST http://127.0.0.1:8080/jsonrpc -H 'Content-Type: application/json' --data '{"jsonrpc":"2.0","method":"Player.GetActivePlayers","id":0}' | jq .
you will receive something like:
Code:
{
"id": 0,
"jsonrpc": "2.0",
"result": [
{
"playerid": 1,
"playertype": "internal",
"type": "video"
}
]
}
And the benefit is, that you are able to access each section of that like for example:
"type": "video"
via:
curl -s -X POST http://127.0.0.1:8080/jsonrpc -H 'Content-Type: application/json' --data '{"jsonrpc":"2.0","method":"Player.GetActivePlayers","id":0}' | jq .result[].type
response:
"video"
To remove the quotes, simply use the "-r" option for jq:
curl -s -X POST http://127.0.0.1:8080/jsonrpc -H 'Content-Type: application/json' --data '{"jsonrpc":"2.0","method":"Player.GetActivePlayers","id":0}' | jq -r .result[].type
response:
video
So, what you get is an active player with the type video. I guess that's what you need
a simple one liner and the result stored in a variable should be enough:
Code:
player=$(curl -s -X POST http://127.0.0.1:8080/jsonrpc -H 'Content-Type: application/json' --data '{"jsonrpc":"2.0","method":"Player.GetActivePlayers","id":0}' | jq -r .result[].type)
if [[ $player = "" ]]; then echo "nothing is playing"; elif [[ $player == "video" ]]; then echo "a video is playing"; elif [[ $player = "audio" ]]; then echo "a song is playing"; fi