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
import subprocess
import time
from kodijson import Kodi # sudo pip install kodi-json
def monitor_state():
mon_state = subprocess.check_output(['/usr/bin/tvservice', '-s'])
@ -9,18 +9,16 @@ def monitor_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}')
json_txt = response.read()
response.close() # best practice to close the file
response = json.loads(json_txt)
return len(response['result']) > 0
kodi = Kodi("http://tv:8080/jsonrpc")
ap = kodi.Player.GetActivePlayers()
print(ap)
return len(ap['result']) > 0
prev_state = None
while True:
# second count
curr_state = monitor_state()
curr_state = kodi_state()
# check if there is a change in the screen state
if curr_state != prev_state:
if curr_state is True: