12345678910111213141516171819202122232425262728293031 |
- #!/usr/bin/env python2
- import subprocess
- import time
-
-
- def monitor_state():
- mon_state = subprocess.check_output(['/usr/bin/tvservice', '-s'])
- return mon_state.split(' ')[1] in ['0xa', '0x12000a', '0x40002']
-
-
- 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
-
-
-
- prev_state = None
- while True:
- # second count
- curr_state = monitor_state()
- # check if there is a change in the screen state
- if curr_state != prev_state:
- if curr_state is True:
- subprocess.check_output(['sispmctl', '-o', '1'])
- else:
- subprocess.check_output(['sispmctl', '-f', '1'])
- prev_state = curr_state
- time.sleep(1.)
|