-
Notifications
You must be signed in to change notification settings - Fork 0
/
isKodiIdle.py
executable file
·40 lines (33 loc) · 971 Bytes
/
isKodiIdle.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/python3
import requests
import sys
def is_kodi_idle(host, idletime):
username = 'kodi'
password = 'kodi'
payload = {
'jsonrpc': '2.0',
'method': 'XBMC.GetInfoBooleans',
'params':
{'booleans': ['System.IdleTime({})'.format(idletime)] },
'id': 1}
try:
r = requests.post('http://{}:8080/jsonrpc'.format(host), json=payload, auth=(username, password))
result = r.json()['result']
return bool(next(iter(result.values())))
except Exception:
return True
def main():
idletime = 7200
hosts = ['libreelec-wohnzimmer', 'libreelec-schlafzimmer']
active_kodis = 0
for host in hosts:
idle = is_kodi_idle(host, idletime)
if not idle:
active_kodis += 1
if active_kodis > 0:
return 1
else:
return 0
if __name__ == '__main__':
# exit with 0 if no kodi is active
sys.exit(main())