kodi_state updated

This commit is contained in:
Dirk Alders 2020-02-02 19:56:01 +00:00
parent 6f61f0dfea
commit 832d912529

View File

@ -1,7 +1,7 @@
#!/usr/bin/env python2 #!/usr/bin/env python2
import subprocess import subprocess
import time import time
from kodijson import Kodi # sudo pip install kodi-json
def monitor_state(): def monitor_state():
mon_state = subprocess.check_output(['/usr/bin/tvservice', '-s']) mon_state = subprocess.check_output(['/usr/bin/tvservice', '-s'])
@ -9,18 +9,16 @@ def monitor_state():
def kodi_state(): def kodi_state():
response = urllib2.urlopen('http://music:8080/jsonrpc?request={%22jsonrpc%22:%20%222.0%22,%20%22method%22:%20%22Player.GetActivePlayers%22,%20%22id%22:%201}') kodi = Kodi("http://tv:8080/jsonrpc")
json_txt = response.read() ap = kodi.Player.GetActivePlayers()
response.close() # best practice to close the file print(ap)
response = json.loads(json_txt) return len(ap['result']) > 0
return len(response['result']) > 0
prev_state = None prev_state = None
while True: while True:
# second count # second count
curr_state = monitor_state() curr_state = kodi_state()
# check if there is a change in the screen state # check if there is a change in the screen state
if curr_state != prev_state: if curr_state != prev_state:
if curr_state is True: if curr_state is True: