bin/amplifier

30 lines
800 B
Plaintext
Raw Normal View History

2020-01-26 17:28:29 +01:00
#!/usr/bin/env python2
import subprocess
import time
2020-02-02 19:56:01 +00:00
from kodijson import Kodi # sudo pip install kodi-json
2020-01-26 17:28:29 +01:00
def monitor_state():
mon_state = subprocess.check_output(['/usr/bin/tvservice', '-s'])
return mon_state.split(' ')[1] in ['0xa', '0x12000a', '0x40002']
def kodi_state():
2020-02-02 19:56:01 +00:00
kodi = Kodi("http://tv:8080/jsonrpc")
ap = kodi.Player.GetActivePlayers()
print(ap)
return len(ap['result']) > 0
2020-01-26 17:28:29 +01:00
prev_state = None
while True:
# second count
2020-02-02 19:56:01 +00:00
curr_state = kodi_state()
2020-01-26 17:28:29 +01:00
# 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.)