JSON-RPC (JSON Remote Procedure Call) interface protocol in development for XBMC

  Thread Rating:
  • 7 Votes - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
Nuka1195 Online
Skilled Python Coder
Posts: 3,914
Joined: Dec 2004
Reputation: 17
Post: #41
ok i tried the example from the introspective listing

VideoLibrary.GetMovieInfo
Parameter example { "movieid": 0, "fields": ["plot"] }

i get the parse error

For python coding questions first see http://mirrors.xbmc.org/docs/python-docs/
find quote
topfs2 Offline
Team-XBMC Developer
Posts: 3,825
Joined: Dec 2007
Reputation: 8
Post: #42
Frack, those GetInfo shouldn't be there Smile They don't do anything, still you shouldn't get parse error.

Although it could be because you mix ' ' and " " but the dump should serialize it correctly afaik. Could you pastebin a debug log when you get the errors?

the correct call should be { "jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", "params": { "foo": "bar" }, "id": 1 }

as for 1, nope it does not except urlencoded nor will it since its not really needed and outside jsonrpc specification. The postdata is seperate from the url your calling, I mean the post data is binary data you send to a certain location, your actually uploading a json to the server.

The dump just takes a json python type and serialize it afaik, I'm not extremely good with python but in my example I didn't use dump even though it can be used.
I'm not entirely sure I understand the map question but root json object is a map { "foo": "bar" } is a map were foo is key and bar is value. check here for more info

nbr 2. Right! jsonrpc has no dependency that the webserver is running so yeah an executejsonapi wouldn't need the webserver running so a clear benefit having it in python scripts then. Although if scripters use the web one (or tcp which is always active) the script can be run outside xbmc.

I'll add the executejsonrpc call to python ASAP, will do it to take a serialized json and return a serialized json, hope thats enough for most uses.

Cheers,
Tobias

If you have problems please read this before posting

Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.


[Image: badge.gif]

"Well Im gonna download the code and look at it a bit but I'm certainly not a really good C/C++ programer but I'd help as much as I can, I mostly write in C#."
find quote
Tolriq Online
Donor
Posts: 1,822
Joined: Jun 2009
Reputation: 52
Location: France
Post: #43
You always need the "jsonrpc": "2.0" don't know why Smile

Do you use a recent build ? some of previous build had problems with multi paquets requests.

Yatse 2 : Media Center Remote Control for Touch Screens
Yatse, the Xbmc Remote and Widgets for Android
find quote
Nuka1195 Online
Skilled Python Coder
Posts: 3,914
Joined: Dec 2004
Reputation: 17
Post: #44
topsf2, no debug log, i'm just running it from python not xbmc.

my build is pre addons merge, so if things are fixed after that, then could be an issue. but it sounds like the getInfo calls aren't hooked in yet, so that was my issue.

as for urlencoding the data, that's a python spec i guess. not important as long as i don't need json.dump() unless xbmc includes the package.

Quote:
urlopen(url[, data[, proxies]])

If the url uses the http: scheme identifier, the optional data argument may be given to specify a POST request (normally the request type is GET). The data argument must be in standard application/x-www-form-urlencoded format; see the urlencode() function below

look forward to executejsonapi Smile

For python coding questions first see http://mirrors.xbmc.org/docs/python-docs/
find quote
topfs2 Offline
Team-XBMC Developer
Posts: 3,825
Joined: Dec 2007
Reputation: 8
Post: #45
Pre addon merge should be plenty if its the latest one. I've altered some calls after but nothing major.

Hmm, weird that the python states that the post data should be urlencoded, I'll take a better look into it but afaik the spec for jsonrpc is non encoded.

We log the calls a client makes in xbmc.log so if you get parse error it will state exactly how it recieved the data, so could be good for debugging.

Afaik json.dump should be safe to use, http://docs.python.org/library/json.html shows some examples and none of them are urlencoded?

If you have problems please read this before posting

Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.


[Image: badge.gif]

"Well Im gonna download the code and look at it a bit but I'm certainly not a really good C/C++ programer but I'd help as much as I can, I mostly write in C#."
find quote
Nuka1195 Online
Skilled Python Coder
Posts: 3,914
Joined: Dec 2004
Reputation: 17
Post: #46
debug log

http://pastebin.com/T7RPQZZX

first call success:
PHP Code:
postdata '{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", "id": "1"}' 

second call error:
PHP Code:
postdata '{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovieInfo", "movieid": 11}' 

you're right json.dumps() is not necessary, i must have formatted the string incorrectly.

i haven't played with the File.Download, so it may do it. but i use httpapi's File.Copy. it's very useful for copying to smb:// shares.

edit:
PHP Code:
postdata '{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovieInfo", "params": {"movieid": 11}}'
postdata '{"jsonrpc": "2.0", "method": "Files.GetDirectory", "params": {"type": "files", "directory": "c:\\"}, "id": "1"}' 

these also give parse errors. do yo9u have an example of Files.GetDirectory, looking thru the source i came up with the above.

For python coding questions first see http://mirrors.xbmc.org/docs/python-docs/
(This post was last modified: 2010-03-21 19:36 by Nuka1195.)
find quote
Tolriq Online
Donor
Posts: 1,822
Joined: Jun 2009
Reputation: 52
Location: France
Post: #47
Request must always have :

"jsonrpc": "2.0"
"method": "VideoLibrary.GetMovies"
"id": 1 (or other number )

Then for params you add the params

PHP Code:
postdata '{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovieInfo", "params": {"movieid": 11}}' 

should be
PHP Code:
postdata '{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovieInfo", "params": {"movieid": 11} , "id" : 1}' 


But :
PHP Code:
postdata '{"jsonrpc": "2.0", "method": "Files.GetDirectory", "params": {"type": "files", "directory": "c:\\"}, "id": "1"}' 

Should work.
Since type default to files try without it.

And since you use ' for escapsluating postdata you should not double the \ for the directory.

Yatse 2 : Media Center Remote Control for Touch Screens
Yatse, the Xbmc Remote and Widgets for Android
find quote
Nuka1195 Online
Skilled Python Coder
Posts: 3,914
Joined: Dec 2004
Reputation: 17
Post: #48
thanks, but

your should be example, i get params error with the "id": 1

the example lists it as "id": "1", which also gives params error

the double \\ is a python thing. it's escaping the \ not the ", so it is correct. the log shows it correctly.

For python coding questions first see http://mirrors.xbmc.org/docs/python-docs/
find quote
Tolriq Online
Donor
Posts: 1,822
Joined: Jun 2009
Reputation: 52
Location: France
Post: #49
Sorry for the \\ you use phpcode tag i misunderstand Smile

For the id in my .net implementation i use int i works well , and it's int also in the webinterface and the jsonrpc standard too it refer to the query id.

Quote:http_request.send("{\"jsonrpc\": \"2.0\", \"method\": \"Files.GetShares\", \"params\": { \"type\": \"music\" }, \"id\": 1}");

Looking at the jsonrpc code :
Quote:postdata = '{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovieInfo", "params": {"movieid": 11} , "id" : 1}'

Can only send back a OK, so the problem seems not be tied to the method but to the way the server receive the full request.
Since no param check in the code the simple method :
Quote:postdata = '{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovieInfo", "id" : 1}'
Should work but it don"t Smile

In the log i got the request and no error but the return is an error -32602 strange...

For the directory it seems that it must be urlencoded from the jsonrpc source.

Just try :
Quote:const string postData = "{\"jsonrpc\": \"2.0\", \"method\": \"Files.GetDirectory\", \"params\" : { \"type\" : \"files\", \"directory\" : \".\" }, \"id\": 1}";
I just test this quickly it works well.

For C:\ it should work also with : C%3A\ but it seems not Smile

Just use C:/ and it will works Smile

Yatse 2 : Media Center Remote Control for Touch Screens
Yatse, the Xbmc Remote and Widgets for Android
find quote
topfs2 Offline
Team-XBMC Developer
Posts: 3,825
Joined: Dec 2007
Reputation: 8
Post: #50
The directory shouldn't be urlencoded, atleast not afaik.

But yeah the params needs to be inside params. Thats jsonrpc spec, here is documentation regarding it

I'll need to fire up windows and try but afaik C:\ should work, sounds weird if it doesn't Smile Does C:\ as a source work?

btw, File.Download will not download the file per say, it will just tell you how you should download it depending on your transport, for http it will tell you a useable url with tcp it may open up a new port (like ftp, but its not doing that now but will at some point Smile ).

Also for explanation sake, id may be anything so you can use it for your own benefits. EDIT: Although it looks like thats outside json-rpc specification, maybee I should change it Smile. Anyways it cannot be omitted.

i.e. this is an ok call
Code:
{ "jsonrpc": "2.0", "method": "foo", "id": { "somekey": [1, 2, 3, 4] } }

Cheers
Tobias

If you have problems please read this before posting

Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.


[Image: badge.gif]

"Well Im gonna download the code and look at it a bit but I'm certainly not a really good C/C++ programer but I'd help as much as I can, I mostly write in C#."
(This post was last modified: 2010-03-21 21:10 by topfs2.)
find quote
Post Reply