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)



- wuench - 2011-12-06

Trying to convert my code over to Pre-Eden.

When I try to submit the following command:

{"jsonrpc":"2.0","method":"XBMC.GetInfoLabels","params":["System.CurrentControl"],"id":1}

I get back an error:
{"error":{"code":-32602,"data":{"method":"XBMC.GetInfoLabels","stack":{"message":"Invalid type string received","name":"labels","type":"array"}},"message":"Invalid params."},"id":1,"jsonrpc":"2.0"}

I can't make heads or tails out what this is trying to tell me. Is it saying the info label "System.CurrentControl" is not supported. If not, is there a list of which infolabels are supported?

I get that infolabels are deperecated, but I am more trying to figure out how to read the new docs and what array [1...x] means and the JSON schema stuff. Debugging my code, one command at a time. Some examples in the docs would be really helpful.


- Montellese - 2011-12-06

The most important thing the doc tells you is that XBMC.GetInfoLabels takes a parameter named "labels" (http://wiki.xbmc.org/index.php?title=JSON-RPC_API/v3#XBMC.GetInfoLabels) which is not present in your request.

So you're request should look like this:
Code:
{"jsonrpc":"2.0","method":"XBMC.GetInfoLabels","pa rams":{ "labels": ["System.CurrentControl"] },"id":1}

The reason why the error message tells you that it received a string but expected an array is because it thinks you are using JSON-RPC's by position notation i.e. the parameters are not provided by their names (in this case e.g. "labels") but by their position (i.e. "params" is an array and not an object) and so XBMC thinks that "System.CurrentControl" is your first parameter.

Taking a look at both the JSON-RPC 2.0 specification and the JSON schema draft help a lot in understanding the docs.

BTW [1..x] means that the array must contain at least 1 item but can contain as many items as you want. Alternatives would be [] which means the array can take 0 to infinite items or [0..5] which means the array can take 0 to 5 items and so on.


- wuench - 2011-12-06

Yep, that worked. Thanks. I read those docs, but it's just not quite sinking in yet... So there may be more dumb questions coming... Smile


Slideshow - vasikgreif - 2011-12-09

Hi, how are picture playlists supposed to work?Do they have it's own id and how can I start slideshow?

I tried adding the picture as:
Code:
{"id":50,"jsonrpc":"2.0","method":"Playlist.Add","params":{"playlistid":1,"item":{"file":"smb://192.168.1.109/filestore/1.jpg"}}}
which adds pictures into video playlist, but I'm unable to play it...

Thanks
Vasik


- Montellese - 2011-12-09

You can either use Player.Open and pass a path to a directory with pictures in the "path" property of the "item" parameter (And optionaly specify "random" and "recursive" as well) or you can add pictures with Playlist.Add to the playlist with ID 3 (this is how it is right now but might change in the future but Playlist.GetPlaylists will tell you the available playlists, their type and ID) and then use Player.Open and pass the "playlistid" 3 in the "item" parameter.


- vasikgreif - 2011-12-09

Thanks, I tried that now, but I get:

Code:
{"error":{"code":-32602,"data":{"method":"Playlist.Add","stack":{"message":"Value between 0 (inclusive) and 2 (inclusive) expected but 3 received","name":"playlistid","type":"integer"}},"message":"Invalid params."},"id":50,"jsonrpc":"2.0"}



- Montellese - 2011-12-09

Sorry my bad. The correct playlistid is 2 (see Playlist.GetPlaylists).


- vasikgreif - 2011-12-09

Montellese Wrote:Sorry my bad. The correct playlistid is 2 (see Playlist.GetPlaylists).

Works great, thanks!


- Mizaki - 2011-12-18

A couple of questions on Files.GetDirectory:

1: I was expecting by specifying media:music that I would only get music files returned but I get the directory names. The folder has only directories with the albums names. Am I just misunderstanding what media:music does?
Code:
{"jsonrpc": "2.0", "method": "Files.GetDirectory", "params" : { "directory" : "/audio/artist/", "media" : "music", "sort": { "order": "ascending", "method": "file" } }, "id": 1}

2: I have a smart playlist that returns all the albums from an artist randomly. Albumid is empty. Is that expected?

Code:
{"jsonrpc": "2.0", "method": "Files.GetDirectory", "params": {"directory": "special://profile/playlists/music/artist.xsp", "media": "music", "properties": ["albumid", "artistid"]}, "id": 1}

Thanks.


- Montellese - 2011-12-18

Mizaki Wrote:A couple of questions on Files.GetDirectory:

1: I was expecting by specifying media:music that I would only get music files returned but I get the directory names. The folder has only directories with the albums names. Am I just misunderstanding what media:music does?
Code:
{"jsonrpc": "2.0", "method": "Files.GetDirectory", "params" : { "directory" : "/audio/artist/", "media" : "music", "sort": { "order": "ascending", "method": "file" } }, "id": 1}
Directories are always returned independant of what you pass in the "media" parameter. Otherwise we wouldn't be able to return directories at all because depending on your definition of "files" a directory is not a file either. But as every returned item has a "type" property it should be easy for you to just ignore all the items with "type": "directory".

Mizaki Wrote:2: I have a smart playlist that returns all the albums from an artist randomly. Albumid is empty. Is that expected?

Code:
{"jsonrpc": "2.0", "method": "Files.GetDirectory", "params": {"directory": "special://profile/playlists/music/artist.xsp", "media": "music", "properties": ["albumid", "artistid"]}, "id": 1}

"albumid" should be returned but as I never used smartplaylists so far I never tested it either. Please create a bug report on trac. Thanks.


- Mizaki - 2011-12-18

Okay, thanks. http://trac.xbmc.org/ticket/12297


- Mizaki - 2011-12-20

I see you've put a fix in for id. I've not tried it yet but I have another query with files.getdirectory.

It lists m3u (and I guess all playlists) as a directory. Which is quite useful. However this means that if I use something like:
Code:
{"jsonrpc": "2.0", "method": "Playlist.Add", "params": {"item": {"directory": "playlist.m3u"}, "playlistid": 0}, "id": 1}
it adds all the files in the playlist. Which if there is a dir with the songs and an m3u with those same songs in it gets added twice (by me on purpose to add 1 level of recursive support). I can code around it but should playlist.add be acting this way?


- vasikgreif - 2011-12-20

Speaking of Files.GetDirectory, it still returns directories only, not the files. Anyone having similar problem, or was it fixed during last days? (I'm on two weeks old nightly)...

Thanks
Vasik


- Montellese - 2011-12-20

Mizaki Wrote:I see you've put a fix in for id. I've not tried it yet but I have another query with files.getdirectory.

It lists m3u (and I guess all playlists) as a directory. Which is quite useful. However this means that if I use something like:
Code:
{"jsonrpc": "2.0", "method": "Playlist.Add", "params": {"item": {"directory": "playlist.m3u"}, "playlistid": 0}, "id": 1}
it adds all the files in the playlist. Which if there is a dir with the songs and an m3u with those same songs in it gets added twice (by me on purpose to add 1 level of recursive support). I can code around it but should playlist.add be acting this way?
I'll have to take a look at such a special case. I don't use any m3u (or other) playlists so I don't have any specific expectations of what should happen in the case you describe. Generally Playlist.Add does not act recursively on directories but then again an m3u playlist is "just" a file and when it is added to a playlist in XBMC it is automatically expanded to all the tracks it contains.

vasikgreif Wrote:Speaking of Files.GetDirectory, it still returns directories only, not the files. Anyone having similar problem, or was it fixed during last days? (I'm on two weeks old nightly)...

Uhm Files.GetDirectory is returning directories AND files for me and I didn't do any fundamental changes to it for quite a while (only fixed the bug reported by Mizaki) so please provide specific details on what is not working including your JSON-RPC request, the result and what you would expect to be present in the response.


- Mizaki - 2011-12-20

It may seem like a bit of a silly question as getdir reports it as a dir so, why wouldn't playlist.add treat it as such but, like you say it is just a file. I'm wondering if the type shouldn't be "playlist" or some such but then I suppose that'll take you down the playlist support that will come after Eden.