2013-03-15, 14:52
(2013-03-15, 13:01)Montellese Wrote: The notifications are sent to any client that has an open two-way connection (TCP socket or WebSocket) to the XBMC client sending the notifications.
Ok thanks again, the penny has finally dropped! For anyone wondering in future, this is a simple code example to initiate a video library scan using sockets and then wait until the OnScanFinished notification is received:
Code:
#!/usr/bin/python
import json, socket
def jsonWaitForScanFinished(id, method, params):
print "Got: id %s, method %s, data %s" % (id, method, params)
if method == "VideoLibrary.OnScanFinished": return False
return True
def sendJSON(request, id, callback):
TCP_IP = '127.0.0.1'
TCP_PORT = 9090
BUFFER_SIZE = 1024
request['jsonrpc'] = '2.0'
request['id'] = id
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((TCP_IP, TCP_PORT))
s.send(json.dumps(request))
while 1:
data = s.recv(BUFFER_SIZE)
# print "received data:", data
if callback:
data = json.loads(data)
id = data["id"] if "id" in data else None
method = data["method"] if "method" in data else data["result"]
params = data["params"] if "params" in data else None
if not callback(id, method, params): break
s.close()
sendJSON({"method": "VideoLibrary.Scan",
"params": {"directory": "nfs://192.168.0.3/mnt/share/media/Video/TV Serials/Arrow/Season 1"}},
1, jsonWaitForScanFinished)
which should return:
Code:
Got: id 1, method OK, data None
Got: id None, method VideoLibrary.OnScanStarted, data {u'data': None, u'sender': u'xbmc'}
Got: id None, method VideoLibrary.OnScanFinished, data {u'data': None, u'sender': u'xbmc'}