|
@@ -1,6 +1,7 @@
|
1
|
1
|
#!/usr/bin/env python2
|
2
|
2
|
import subprocess
|
3
|
3
|
import time
|
|
4
|
+from requests.exceptions import ConnectionError
|
4
|
5
|
from kodijson import Kodi # sudo pip install kodi-json
|
5
|
6
|
|
6
|
7
|
def monitor_state():
|
|
@@ -9,10 +10,12 @@ def monitor_state():
|
9
|
10
|
|
10
|
11
|
|
11
|
12
|
def kodi_state():
|
12
|
|
- kodi = Kodi("http://tv:8080/jsonrpc")
|
13
|
|
- ap = kodi.Player.GetActivePlayers()
|
14
|
|
- print(ap)
|
15
|
|
- return len(ap['result']) > 0
|
|
13
|
+ try:
|
|
14
|
+ kodi = Kodi("http://tv:8080/jsonrpc")
|
|
15
|
+ ap = kodi.Player.GetActivePlayers()
|
|
16
|
+ return len(ap['result']) > 0
|
|
17
|
+ except ConnectionError: # This is a dirty trick, if kodi is not yet ready to answer requests
|
|
18
|
+ return False
|
16
|
19
|
|
17
|
20
|
|
18
|
21
|
prev_state = None
|