Browse Source

kodi_state updated

84582af
Dirk Alders 4 years ago
parent
commit
832d912529
1 changed files with 6 additions and 8 deletions
  1. 6
    8
      amplifier

+ 6
- 8
amplifier View File

@@ -1,7 +1,7 @@
1 1
 #!/usr/bin/env python2
2 2
 import subprocess
3 3
 import time
4
-
4
+from kodijson import Kodi	# sudo pip install kodi-json
5 5
 
6 6
 def monitor_state():
7 7
     mon_state = subprocess.check_output(['/usr/bin/tvservice',  '-s'])
@@ -9,18 +9,16 @@ def monitor_state():
9 9
 
10 10
 
11 11
 def kodi_state():
12
-    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}')
13
-    json_txt = response.read()
14
-    response.close()  # best practice to close the file
15
-    response = json.loads(json_txt)
16
-    return len(response['result']) > 0
17
-
12
+    kodi = Kodi("http://tv:8080/jsonrpc")
13
+    ap = kodi.Player.GetActivePlayers()
14
+    print(ap)
15
+    return len(ap['result']) > 0
18 16
 
19 17
 
20 18
 prev_state = None
21 19
 while True:
22 20
     # second count
23
-    curr_state = monitor_state()
21
+    curr_state = kodi_state()
24 22
     # check if there is a change in the screen state
25 23
     if curr_state != prev_state:
26 24
         if curr_state is True:

Loading…
Cancel
Save