2010-12-06, 19:36
I'd like to get started with using the JSON API but I don't know where to start. Has anyone got simple example code (Python would be nice) to show me how to send XBMC an instruction using JSON?
Thanks,
JR
Thanks,
JR
xbmc.executeJSONRPC()
json_album = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "AudioLibrary.GetAlbums", "id": 1}')
print xbmcexecute.JSONRPC('{"jsonrpc": "2.0", "method": "JSONRPC.Introspect", "id": 1}')
{
"id" : 1,
"jsonrpc" : "2.0",
"result" : {
"commands" : [
{
"command" : "JSONRPC.Introspect",
"description" : "Enumerates all actions and descriptions. Parameter example {\"getdescriptions\": true, \"getpermissions\": true, \"filterbytransport\": true }. All parameters optional",
"executable" : true,
"permission" : "ReadData"
},
{
"command" : "JSONRPC.Version",
"description" : "Retrieve the jsonrpc protocol version",
"executable" : true,
"permission" : "ReadData"
},
{
"command" : "JSONRPC.Permission",
"description" : "Retrieve the clients permissions",
"executable" : true,
"permission" : "ReadData"
},
_MYXBMCADDR = "192.168.128.128"
_MYXBMCPORT = 81
import socket
import select
#create an INET, STREAMing socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
#now connect to rattle
s.connect((_MYXBMCADDR, _MYXBMCPORT))
# Send an Introspect command
s.send("POST /jsonrpc HTTP/1.1\x0D\x0A")
s.send("\x0D\x0A")
s.send("{\"jsonrpc\": \"2.0\", \"method\": \"JSONRPC.Introspect\", \"id\": 1}")
# Print the results
while True:
print s.recv(0x4000)
if len(select.select([s], [], [], 0)[0]) == 0:
break;
# Finished
s.shutdown(socket.SHUT_RDWR)
s.close()
_MYXBMCADDR = "192.168.128.128"
_MYXBMCPORT = 9090
import socket
import select
#create an INET, STREAMing socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
#now connect to rattle
s.connect((_MYXBMCADDR, _MYXBMCPORT))
# Send an Introspect command
s.send("{\"jsonrpc\": \"2.0\", \"method\": \"JSONRPC.Introspect\", \"id\": 1}")
# Print the results
while True:
print s.recv(0x4000)
if len(select.select([s], [], [], 0)[0]) == 0:
break;
# Finished
s.shutdown(socket.SHUT_RDWR)
s.close()
(2010-12-31, 09:05)konetzed Wrote: Just asking for clarification, there is currently no python library for using xbmc's json-rpc over http? If one wants to use the json-rpc api over http they have to using a python json-rpc and write the code from scratch?
result = simplejson.load(urllib2.urlopen(url))