A bin folder, holding helpfull scripts and commands
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

1234567891011121314151617181920212223242526272829303132
  1. #!/usr/bin/env python2
  2. import subprocess
  3. import time
  4. from requests.exceptions import ConnectionError
  5. from kodijson import Kodi # sudo pip install kodi-json
  6. def monitor_state():
  7. mon_state = subprocess.check_output(['/usr/bin/tvservice', '-s'])
  8. return mon_state.split(' ')[1] in ['0xa', '0x12000a', '0x40002']
  9. def kodi_state():
  10. try:
  11. kodi = Kodi("http://tv:8080/jsonrpc")
  12. ap = kodi.Player.GetActivePlayers()
  13. return len(ap['result']) > 0
  14. except ConnectionError: # This is a dirty trick, if kodi is not yet ready to answer requests
  15. return False
  16. prev_state = None
  17. while True:
  18. # second count
  19. curr_state = kodi_state()
  20. # check if there is a change in the screen state
  21. if curr_state != prev_state:
  22. if curr_state is True:
  23. subprocess.check_output(['sispmctl', '-o', '1'])
  24. else:
  25. subprocess.check_output(['sispmctl', '-f', '1'])
  26. prev_state = curr_state
  27. time.sleep(1.)