Kodi Community Forum
JSON-RPC (JSON Remote Procedure Call) interface protocol in development for XBMC - Printable Version

+- Kodi Community Forum (https://forum.kodi.tv)
+-- Forum: Development (https://forum.kodi.tv/forumdisplay.php?fid=32)
+--- Forum: Kodi Application (https://forum.kodi.tv/forumdisplay.php?fid=93)
+---- Forum: JSON-RPC (https://forum.kodi.tv/forumdisplay.php?fid=174)
+---- Thread: JSON-RPC (JSON Remote Procedure Call) interface protocol in development for XBMC (/showthread.php?tid=68263)



Consider that... - ncarthy - 2011-01-19

... if you're writing a regular expression bear in mind that the order of the fields can change... filename might not always be the first field you encounter


- topfs2 - 2011-01-19

Aouch, I missed that. I'd suggest you looking at some of the many parsers for json out there already, why reinvent the wheel Smile


- Xedar - 2011-01-19

Do you mean JSON output from XBMC sometime exchange the fileds or the "client" exchenge them?

so far it has never happend, i think iviewer read the whole output then parse it from top to bottom.

@topfs2
save the ID variable somewhere in the memory is not possible in iviewer in a good way...
well I may endup having a parser server in the middle, but it feels clener to have ipad talk to XBMC by it self.

Regards


- Fiasco - 2011-01-19

Xedar Wrote:Do you mean JSON output from XBMC sometime exchange the fileds or the "client" exchenge them?

so far it has never happend, i think iviewer read the whole output then parse it from top to bottom.

@topfs2
save the ID variable somewhere in the memory is not possible in iviewer in a good way...
well I may endup having a parser server in the middle, but it feels clener to have ipad talk to XBMC by it self.

Regards


JSON is a layer of crap you don't want for iViewer. Install an apache webserver and use Perl to query the xbmc databases directly. You can format your query responses in nice flat easily parseable delimited text.

In addition, xbmc doesn't have to be running to query.


- topfs2 - 2011-01-19

Fiasco Wrote:JSON is a layer of crap you don't want for iViewer. Install an apache webserver and use Perl to query the xbmc databases directly. You can format your query responses in nice flat easily parseable delimited text.

In addition, xbmc doesn't have to be running to query.

This is deprecated and will be removed eventually..

Xeder, read the json specification. It is an object
Code:
{ "jsonrpc": "2.0", "method": "JSONRPC.Ping", "id": 1 }
Is exactly the same as
Code:
{"method": "JSONRPC.Ping", "id": 1,  "jsonrpc": "2.0" }
etc. You can switch around any of the members in the object.

And XBMC will always follow jsonrpc 2.0 specification, what you are suggesting is not technically in violation but it is real unnecessary and will never be added.


- panos_k75 - 2011-01-19

i would like to initiate a video library scan from my client. Is there a way for my client to be notified when the scan is complete?


- Fiasco - 2011-01-19

topfs2 Wrote:This is deprecated and will be removed eventually..

Xeder, read the json specification. It is an object
Code:
{ "jsonrpc": "2.0", "method": "JSONRPC.Ping", "id": 1 }
Is exactly the same as
Code:
{"method": "JSONRPC.Ping", "id": 1,  "jsonrpc": "2.0" }
etc. You can switch around any of the members in the object.

And XBMC will always follow jsonrpc 2.0 specification, what you are suggesting is not technically in violation but it is real unnecessary and will never be added.


How can external queries of the database be deprecated?


- jmarshall - 2011-01-20

We'll arbitrarily rearrange the tables :p


- topfs2 - 2011-01-20

Fiasco Wrote:How can external queries of the database be deprecated?

Because its silly and not sane at all to assume one table layout. Also its a giant security failure Smile


- topfs2 - 2011-01-20

panos_k75 Wrote:i would like to initiate a video library scan from my client. Is there a way for my client to be notified when the scan is complete?

IIRC there is no way, please add a feature request ticket because its for sure a sane feature.


- Fiasco - 2011-01-20

jmarshall Wrote:We'll arbitrarily rearrange the tables :p

Bwahhahahahah touché!


- Fiasco - 2011-01-20

topfs2 Wrote:Because its silly and not sane at all to assume one table layout. Also its a giant security failure Smile

You lost me. How is it a giant security failure?

Yes, the table layout could change but tweaking a select statement is pretty straightforward.


- wuench - 2011-01-20

Xedar Wrote:Hi!

is there a way to get the id tag in every { } ?
when i parse the JSON i must use an } as EOM otherwise iam not able to fetch everything.
eg.

Best regards Mikael

JSON parsing from scratch IS difficult. My solution is probably going to be to give up on the raw socket interface and switch to HTTP, then you should only get a single response (or maybe limited number of responses) per request so it is easier to delineate messages, rather than an endless stream.

With no unique EOM, the socket interface seems like it has a high risk of getting out of sync if something gets mangled, even with a proper JSON parser. It will take a lot of extra code to protect against those issues.


- topfs2 - 2011-01-20

wuench Wrote:JSON parsing from scratch IS difficult. My solution is probably going to be to give up on the raw socket interface and switch to HTTP, then you should only get a single response (or maybe limited number of responses) per request so it is easier to delineate messages, rather than an endless stream.

With no unique EOM, the socket interface seems like it has a high risk of getting out of sync if something gets mangled, even with a proper JSON parser. It will take a lot of extra code to protect against those issues.

TCP guarantees packet order and packet arrival, if it looses packets it will be resent and if it looses the entire stream it will give you a proper error for that. There exist proper stream parsers or you can use a proper jsonrpc client and it should work. That being said, http is usually simpler if you want to just use a parser.

Fiasco Wrote:You lost me. How is it a giant security failure?

Anyone having access to the database can both read, edit and completely destroy the database at a there leisure. This is something which is not at all good, something which should be sandboxed and impossible for a client to do unless explicitly allowed to do, which is what jsonrpc sets out the fix.

Fiasco Wrote:Yes, the table layout could change but tweaking a select statement is pretty straightforward.

It is, but why should a client need to do this at every release. i.e. it needs to first parse out what version XBMC is then it needs to create the select statement. XBMC handles this perfectly in the GUI code and a client should ideally be able to just ask "Get all movies" and the it should get them, no matter what version the database is. This is why jsonrpc is design how it is.

Cheers,
Tobias


- Pr.Sinister - 2011-01-20

Hey guys...

Super noob here...please be gentle...

I am trying a few things using the python script from the 1st page and i have 2 problems :

#1) When running the python script, it takes about 15 seconds before the urlopen executes... any idea why?

This is the source :

Code:
import json
import httplib, urllib
import sys

url = 'http://username:password@hostname:80'
jsonrpcurl = url + '/jsonrpc'

postdata = '{"jsonrpc": "2.0", "method": "VideoPlayer.SmallSkipForward", "id": "1"}'

print postdata

urllib.urlopen(jsonrpcurl, postdata)

#2) What is the proper syntax for VideoPlayer.SeekPercentage ? I have tried pretty much everything i can think of including :

Code:
{"jsonrpc": "2.0", "method": "VideoPlayer.SeekPercentage", "params": {"": "50"}, "id": "1"}

{"jsonrpc": "2.0", "method": "VideoPlayer.SeekPercentage", "params": {"": 50}, "id": "1"}

{"jsonrpc": "2.0", "method": "VideoPlayer.SeekPercentage", "params": {"parameter": "50"}, "id": "1"}

{"jsonrpc": "2.0", "method": "VideoPlayer.SeekPercentage", "params": [50], "id": "1"}

{"jsonrpc": "2.0", "method": "VideoPlayer.SeekPercentage", ["50"], "id": "1"}

Help! Big Grin