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
 #!/usr/bin/env python2
1
 #!/usr/bin/env python2
2
 import subprocess
2
 import subprocess
3
 import time
3
 import time
4
-
4
+from kodijson import Kodi	# sudo pip install kodi-json
5
 
5
 
6
 def monitor_state():
6
 def monitor_state():
7
     mon_state = subprocess.check_output(['/usr/bin/tvservice',  '-s'])
7
     mon_state = subprocess.check_output(['/usr/bin/tvservice',  '-s'])
9
 
9
 
10
 
10
 
11
 def kodi_state():
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
 prev_state = None
18
 prev_state = None
21
 while True:
19
 while True:
22
     # second count
20
     # second count
23
-    curr_state = monitor_state()
21
+    curr_state = kodi_state()
24
     # check if there is a change in the screen state
22
     # check if there is a change in the screen state
25
     if curr_state != prev_state:
23
     if curr_state != prev_state:
26
         if curr_state is True:
24
         if curr_state is True:

Loading…
Cancel
Save