Last active
June 30, 2017 21:23
-
-
Save subzero79/5c0272f87fbe2ecfb83cb423d0f938b5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
status=${1} | |
echo $status | |
KODI_URL="http://[email protected]:8080/jsonrpc" | |
#set -x | |
_get_audio_device () { | |
curl -s -H "Content-type: application/json" \ | |
--data-binary '{ "jsonrpc" : "2.0", | |
"params" : { "setting": "audiooutput.audiodevice" }, | |
"method" : "Settings.GetSettingValue", | |
"id" : 1 }' \ | |
${KODI_URL} | |
} | |
_set_audio_device () { | |
curl -s -H "Content-type: application/json" \ | |
--data-binary '{ "jsonrpc" : "2.0", | |
"method" : "Settings.SetSettingValue", | |
"params" : { "setting" : "audiooutput.audiodevice", | |
"value" : "'"${1}"'" }, | |
"id" : 1 }' \ | |
${KODI_URL} | |
} | |
_set_mute_kodi () { | |
curl -s -H "Content-type: application/json" \ | |
--data-binary '{ "jsonrpc" : "2.0", | |
"params" : { "mute" : "toggle" }, | |
"method" : "Application.SetMute", | |
"id" : 1 }' \ | |
${KODI_URL} | |
} | |
_get_mute_kodi () { | |
curl -s -H "Content-type: application/json" \ | |
--data-binary '{ "jsonrpc" : "2.0", | |
"params" : { "properties" : [ "muted" ] }, | |
"method" : "Application.GetProperties", | |
"id" : 1 }' \ | |
${KODI_URL} | |
} | |
_send_kodi_notification () { | |
curl -s -H "Content-type: application/json" \ | |
--data-binary '{ "jsonrpc" : "2.0", | |
"params" : { "title" : "Audio" , | |
"message" : "'"${1}"'" }, | |
"method" : "GUI.ShowNotification", | |
"id" : 1 }' \ | |
${KODI_URL} | |
} | |
_process () { | |
if [ ! -z $status ]; then | |
case $status in | |
'disconnected') | |
echo "HDMI" | |
new_device="ALSA:hdmi:CARD=AMLM8AUDIO,DEV=0" | |
_set_audio_device "${new_device}" | |
_send_kodi_notification "HDMI" | |
mute_state=$(_get_mute_kodi | jq -sr '.[]|.result.muted') | |
if [ $mute_state = "false" ];then | |
_set_mute_kodi | |
fi | |
;; | |
'connected') | |
echo "PULSE" | |
new_device="PULSE:Default" | |
_set_audio_device "${new_device}" | |
_send_kodi_notification "PULSE" | |
;; | |
esac | |
fi | |
} | |
_process |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment