-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathkodi_play_pause.py
35 lines (26 loc) · 997 Bytes
/
kodi_play_pause.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
import httplib
import json
class KodiPlayPause:
def __init__(self, config):
self._config = config
def _switch_play_pause(self):
conn = httplib.HTTPConnection(self._config.KODI_ADDR, timeout=60)
conn.request("POST", "/jsonrpc",
'{"jsonrpc": "2.0", "method": "Player.PlayPause", "params": { "playerid": 1 }, "id": 1}')
r1 = conn.getresponse()
if r1.status != 200:
raise Exception("Not 200 status in Kodi API: " + str(r1.status))
data1 = r1.read()
decoded_json = json.loads(data1)
if 'result' in decoded_json:
if 'speed' in decoded_json['result']:
return decoded_json['result']['speed'] == 1
return False
def play(self):
result = self._switch_play_pause()
if not result:
self._switch_play_pause()
def pause(self):
result = self._switch_play_pause()
if result:
self._switch_play_pause()