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)



- bradvido88 - 2011-11-30

Hey, I found some odd behavior in the Files.GetDirectory() call changes between Dharma and Eden. I posted the details here: http://forum.xbmc.org/showthread.php?tid=114921 but now realize this thread might have been a better place to ask Blush


- jimk72 - 2011-12-01

Montellese Wrote:It's not really a bug because that's how XBMC works. If it has to create a playlist from multiple files it (by default) creates a video playlist unless there is some specific meta data that can be retrieved that specifies it as a music playlist (which is possible with smart playlists). This logic/implementation is far from perfect and I don't really know why it is done this way but that's how it is.

If you want to know the playlistid of the playlist used by a player you can use Player.GetProperties and retrieve the "playlistid" property.

That will work. Thanks!!


- el_Paraguayo - 2011-12-01

Montellesse,

I'm writing a python script that's trying to catch the "OnStop" notification (by listening on port 9090).

While I can search the data for "OnStop", a neater way would be to detect the end of the notification and then parse the full JSON response.

However, I'm having difficulty in making the script determine the end of the notification as there doesn't seem to be any break character (maybe this is intentional - i.e. as required by the specification).

Do you have any tips for catching the end of the notification?

Thanks,

el_P


- Montellese - 2011-12-01

el_Paraguayo Wrote:Montellesse,

I'm writing a python script that's trying to catch the "OnStop" notification (by listening on port 9090).

While I can search the data for "OnStop", a neater way would be to detect the end of the notification and then parse the full JSON response.

However, I'm having difficulty in making the script determine the end of the notification as there doesn't seem to be any break character (maybe this is intentional - i.e. as required by the specification).

Do you have any tips for catching the end of the notification?

Thanks,

el_P

You have to count the { and } that you receive from the socket on port 9090. Whenever the number of } matches the number of { you have a whole JSON-RPC notification/response. But ideally you would use some kind of stream-parser because { and } could also appear within strings but this is not the case with any JSON-data generated by XBMC.

This problem has been discussed before and other people have requested to add something like a line break (\n) to the end of every notification/response but that's no good solution at all because it makes scripts depend on something that is not part of the specification. The JSON-RPC specification doesn't state anything apart from saying that all data between notifications/responses must be ignored.


- othrayte - 2011-12-01

el_Paraguayo Wrote:Montellesse,

I'm writing a python script that's trying to catch the "OnStop" notification (by listening on port 9090).

While I can search the data for "OnStop", a neater way would be to detect the end of the notification and then parse the full JSON response.

However, I'm having difficulty in making the script determine the end of the notification as there doesn't seem to be any break character (maybe this is intentional - i.e. as required by the specification).

Do you have any tips for catching the end of the notification?

Thanks,

el_P
This has actually come up several times before, the recommended method is to "count the brackets" or in the case of json count the brackets and the quote marks. To simplify there should be an equal number of opening and closing brackets that aren't surrounded with quote marks (e.g. inside a string). In TU we do this by keeping a count, increasing the count on an opening bracket, decreasing it on a closing one and doing nothing in between quotes. One special case to remember to account for is when you start partway through a notification you need to check if your count has become negative, reset the count and assume you are at the start of the next message. The only other case that can cause problems is starting inside a string, and if anyone has any ideas how to detect this it would be most helpful; in general this is unlikely to happen.


- el_Paraguayo - 2011-12-01

Thanks both for your quick replies - I'll take a look at TU to get some tips.

Sorry for having missed the earlier discussions.


- el_Paraguayo - 2011-12-01

Othrayte,

Your code works beautifully, I'll adapt slightly for my (less impressive) needs, giving full credit to TU.

Thanks so much for pointing me to the code.

el_P


- topfs2 - 2011-12-01

For streaming parsing check YAJL (or YAJL-py for the python version). it does add some complexity with parsing but such will always be the case with streaming data as the raw TCP is. So with YAJL-Py you would count the object start/ends and when you reach 0 on end you know you have one package. You could do the actual parsing in the SAX handlers or simply store the string you input and do the parsing when you have deduced when the package is finished (the former is the better). For those understanding C++ you can look at our streaming parsers in XBMC, (https://github.com/xbmc/xbmc/blob/master/xbmc/utils/JSONVariantParser.cpp)

The fact is that \n checking which some others relied on previously was equally error prone as its as valid to have \n within a json object as } is in strings Smile


- el_Paraguayo - 2011-12-02

Is it possible to use Playlist.Add to add more than one item ("file") in a single request?

If not, is this because submitting single requests should ensure the correct ordering?


- Montellese - 2011-12-02

el_Paraguayo Wrote:Is it possible to use Playlist.Add to add more than one item ("file") in a single request?

If not, is this because submitting single requests should ensure the correct ordering?

You can't pass multiple "file" property parameters in one request but you can send multiple requests in one HTTP request. This is called batch requesting and you just put multiple json-rpc request into a json array

Code:
[
  { "jsonrpc": "2.0", ... },
  { "jsonrpc": "2.0", ... },
  ...
  { "jsonrpc": "2.0", ... }
]



- el_Paraguayo - 2011-12-02

Great. I learn something new every day.

Sorry if these are really basic questions for you!


Notifications for slideshows - dwagner - 2011-12-04

Is there any notification for when a slideshow or pictures are shown?

Having this would be useful as I was prefer not to continually poll the server for when a slideshow or picture are played. Currently I use the Player.OnPlay and Player.OnStop notification to update data on what is currently playing.


- Montellese - 2011-12-04

dwagner Wrote:Is there any notification for when a slideshow or pictures are shown?

Having this would be useful as I was prefer not to continually poll the server for when a slideshow or picture are played. Currently I use the Player.OnPlay and Player.OnStop notification to update data on what is currently playing.

Currently not. The whole slideshow stuff is very badly integrated into XBMC and requires a lot of extra work for it to be available in JSON-RPC at all.


- dwagner - 2011-12-04

Montellese Wrote:Currently not. The whole slideshow stuff is very badly integrated into XBMC and requires a lot of extra work for it to be available in JSON-RPC at all.

That's quite sad, because I do see that Player.GetActivePlayers correctly retrieves the picture player.

I was using the notification system to just get info when it changed, but without getting the picture information the notification system goes out the door for me and I instead have to continually poll to see if pictures are being shown as opposed to videos and music.


- dwagner - 2011-12-04

Hi Montellese,

One other thing I've noted as I am trying to do my work arounds for pictures.

The JSON result for Player.GetItem comes back with correct picture information for file, label and type but it gives me a path to a fanart image that supposedly sits in the Video/Fanart directory. The file does not exist there.

Another issue seems to be that if you view a single image, the return has the correct thumbnail, but if you view images in a slideshow the return has no thumbnail set.