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)



- carmenm - 2011-04-06

topfs2 Wrote:I say put a ticket on this, we should notify on window change no matter and we could probably notify on player going to from fullscreen also, I agree its a nice state to track. For sure a good idea to have remotes look different when in fullscreen and when in GUI, so whatever makes that easier is good Smile

Cheers,
Tobias.

I love that kind of answer Big Grin and i completely agree with you on remotes. That s the whole point of the app i am developing.
By the way if we have an announcement we also need a function to get the state.

EDIT : added


- carmenm - 2011-04-06

still on my request frenzy:
- would it be possible to query date Added as a field? I know we can get recently added, but having a date added would allow to sort that way. Yet i dont know if that s even possible on XMBC's side.

Thanks


- Montellese - 2011-04-06

jitterjames Wrote:yes, but audioplaylist.add only appears to allow us to add a single item, So how would we add

- All songs by artist "xyz"
- All songs with genre "rock"
etc

it seems that I would need to request all items in the library and then filter them myself and then add each on individually by id. That doesn't seem very efficient to me, but maybe I misunderstand.

You should be able to use AudioLibrary.GetArtists() to get a list of all artists, then choose artist "xyz" and remember his artistid and then do AudioPlaylist.Add using that artistid in the correct parameter.


- topfs2 - 2011-04-06

carmenm Wrote:still on my request frenzy:
- would it be possible to query date Added as a field? I know we can get recently added, but having a date added would allow to sort that way. Yet i dont know if that s even possible on XBMC's side.

Thanks

IIRC this is not possible on xbmc side, we don't store it. However I see no reason at all why we shouldn't so feel free to suggest it along with the sort option for it. That way we can remove the recently added method and just use the normal getters for the same effect.


- carmenm - 2011-04-06

topfs2 Wrote:IIRC this is not possible on xbmc side, we don't store it. However I see no reason at all why we shouldn't so feel free to suggest it along with the sort option for it. That way we can remove the recently added method and just use the normal getters for the same effect.

once again i completely agree. i am adding a feature request in database component.


- marksoccer - 2011-04-06

Montellese Wrote:I removed all the parameters which caused some problems or didn't always work properly. If I have the time to fix them the parameters will be re-added.
Did you try to run AudioPlaylist.Play() after using AudioPlaylist.Add? AudioPlaylist.Play() expects a parameter "item" which indicates the position of the item in the playlist to start playing.

Sorry, I should have mentioned, I tried using AudioPlaylist.Play after using AudioPlaylist.Add (also tried after AudioPlaylist.Insert).

I should note however, that AudioPlaylist.Play appears to be working fine as I can play something through the XBMC GUI and have it restart to the top of the playlist using AudioPlaylist.Play. However, regardless of whether I use Add or Insert, I cannot get items (songids, albumids, artistids) to be added to the now playing queue.

Here are some examples of the commands I am sending, and their respective results:

Using Insert:
{"jsonrpc":"2.0","method":"AudioPlaylist.Insert","id":1,"params":{"item":{"artistid":89},"index":0}}
{"jsonrpc":"2.0","method":"AudioPlaylist.Play","id":2,"params":{"item":0}}

Result[1] = {"id":1,"jsonrpc":"2.0","result":"OK"}
Result[2] = {"id":2,"jsonrpc":"2.0","result":{"success":true}}

Using Add:
{"jsonrpc":"2.0","method":"AudioPlaylist.Add","id":1,"params":{"item":{"artistid":89}}}
{"jsonrpc":"2.0","method":"AudioPlaylist.Play","id":2,"params":{"item":0}}

Result[1] = {"id":1,"jsonrpc":"2.0","result":"OK"}
Result[2] = {"id":2,"jsonrpc":"2.0","result":{"success":true}}


- Montellese - 2011-04-06

marksoccer Wrote:Sorry, I should have mentioned, I tried using AudioPlaylist.Play after using AudioPlaylist.Add (also tried after AudioPlaylist.Insert).

I should note however, that AudioPlaylist.Play appears to be working fine as I can play something through the XBMC GUI and have it restart to the top of the playlist using AudioPlaylist.Play. However, regardless of whether I use Add or Insert, I cannot get items (songids, albumids, artistids) to be added to the now playing queue.

Here are some examples of the commands I am sending, and their respective results:

Using Insert:
{"jsonrpc":"2.0","method":"AudioPlaylist.Insert","id":1,"params":{"item":{"artistid":89},"index":0}}
{"jsonrpc":"2.0","method":"AudioPlaylist.Play","id":2,"params":{"item":0}}

Result[1] = {"id":1,"jsonrpc":"2.0","result":"OK"}
Result[2] = {"id":2,"jsonrpc":"2.0","result":{"success":true}}

Using Add:
{"jsonrpc":"2.0","method":"AudioPlaylist.Add","id":1,"params":{"item":{"artistid":89}}}
{"jsonrpc":"2.0","method":"AudioPlaylist.Play","id":2,"params":{"item":0}}

Result[1] = {"id":1,"jsonrpc":"2.0","result":"OK"}
Result[2] = {"id":2,"jsonrpc":"2.0","result":{"success":true}}

No problem I thought as much but just wanted to be sure. I'll have to double-check that because I didn't touch the logic behind it I only re-structured the parameters.


- marksoccer - 2011-04-07

Montellese Wrote:No problem I thought as much but just wanted to be sure. I'll have to double-check that because I didn't touch the logic behind it I only re-structured the parameters.

I think I have discovered the problem. It appears that the parameterObject being passed into CAudioLibrary::FillFileItemList is the "parameters" object rather than the newly created "item" object. I tried to find the simplest fix, which I determined was to change parameterObject to parameterObject["item"] in AVPlaylistOperations.cpp before passing it into FillFileItemList. I'm not sure whether this is the best fix (it might break other stuff), but it solves the problem I was having.


- marksoccer - 2011-04-07

Also, can you explain what you mean by:

Quote:It is now possible to send multiple calls in a single request and receive all the responses in a single response. This can result in less data traffic and faster responses over HTTP

An example of a multi-command json string would be much appreciated Smile


- Montellese - 2011-04-07

marksoccer Wrote:I think I have discovered the problem. It appears that the parameterObject being passed into CAudioLibrary::FillFileItemList is the "parameters" object rather than the newly created "item" object. I tried to find the simplest fix, which I determined was to change parameterObject to parameterObject["item"] in AVPlaylistOperations.cpp before passing it into FillFileItemList. I'm not sure whether this is the best fix (it might break other stuff), but it solves the problem I was having.
Thanks for taking a look at this. I will take a stab at it later today.

marksoccer Wrote:An example of a multi-command json string would be much appreciated Smile

There's nothing special about json-rpc's batch requests. It's simply a queuing of multiple requests like this:

Code:
[{ "jsonrpc": "2.0" method: "AudioPlayer.Add", "params": { ... }, "id": 1 },
{ "jsonrpc": "2.0" method: "AudioPlayer.Play", "params": { ... }, "id": 2 },
{ "jsonrpc": "2.0" method: "AudioPlayer.GetItems", "params": { ... }, "id": 1 }]

You can put together as many requests as you like. Obviously this makes no difference over TCP but over HTTP you will get the responses of all three requests from the above example in a single HTTP Response packet. Furthermore you can drop the "id" parameter on the first two requests and therefore making it into notifications which do not generate a response at all and you will only get the response for the call to "AudioPlayer.GetItems". Obviously you will miss any errors happening during the requests you send as notifications.

EDIT: Forgot to mention that batch requests need to be transfered in an array so you'll have to put [ ] around the requests and a comma as a seperator between requests.


- Montellese - 2011-04-07

marksoccer Wrote:Sorry, I should have mentioned, I tried using AudioPlaylist.Play after using AudioPlaylist.Add (also tried after AudioPlaylist.Insert).

I should note however, that AudioPlaylist.Play appears to be working fine as I can play something through the XBMC GUI and have it restart to the top of the playlist using AudioPlaylist.Play. However, regardless of whether I use Add or Insert, I cannot get items (songids, albumids, artistids) to be added to the now playing queue.

Here are some examples of the commands I am sending, and their respective results:

Using Insert:
{"jsonrpc":"2.0","method":"AudioPlaylist.Insert","id":1,"params":{"item":{"artistid":89},"index":0}}
{"jsonrpc":"2.0","method":"AudioPlaylist.Play","id":2,"params":{"item":0}}

Result[1] = {"id":1,"jsonrpc":"2.0","result":"OK"}
Result[2] = {"id":2,"jsonrpc":"2.0","result":{"success":true}}

Using Add:
{"jsonrpc":"2.0","method":"AudioPlaylist.Add","id":1,"params":{"item":{"artistid":89}}}
{"jsonrpc":"2.0","method":"AudioPlaylist.Play","id":2,"params":{"item":0}}

Result[1] = {"id":1,"jsonrpc":"2.0","result":"OK"}
Result[2] = {"id":2,"jsonrpc":"2.0","result":{"success":true}}

Thanks again for the report. You were right about the "item" and I fixed it in https://github.com/xbmc/xbmc/commit/db9d7e5fd4b15fda5f7539e9f40def063fd7af05. Please report back whether it works for you as well (I tested it for artistid and albumid).


XBMC.Play ? - noem - 2011-04-11

I just tried to do an XBMC.Play with a movieid
Code:
{"method":"XBMC.Play","id":23,"jsonrpc":"2.0","params":{"movieid":222}}

responce:

Code:
{
   "error" : {
      "code" : -32602,
      "data" : {
         "method" : "XBMC.Play",
         "stack" : {
            "message" : "Missing parameter",
            "name" : "file",
            "type" : "string"
         }
      },
      "message" : "Invalid params."
   },
   "id" : 23,
   "jsonrpc" : "2.0"
}

this works fine:
Code:
{"method":"XBMC.Play","id":23,"jsonrpc":"2.0","params":{"file":"the\file\path"}}
but when you start a playback of a file you dont get any info like movieid/thumbnail/fanart in playlist .... How to play a movieid ? or an artist/albumid ?
BTW love the RPC changes Smile
Kind Regards!


- Montellese - 2011-04-12

noem Wrote:but when you start a playback of a file you dont get any info like movieid/thumbnail/fanart in playlist .... How to play a movieid ? or an artist/albumid ?

You can use AudioPlaylist.Add() or VideoPlaylist.Add() and then XXXPlaylist.Play(). Both Add() methods take a parameter "item" with a respective property (artistid, albumid, movieid, ...). Hope that helps.


- noem - 2011-04-12

I'd like to mention that correct invocation of AudioPlaylist.Add requires non-valid JSON string:

Code:
{"jsonrpc":"2.0","method":"AudioPlaylist.Add","id" :1,"params":{"item":{"artistid":89},"item":{"artistid":80}}}

therefore, it should be something like:
Code:
{"jsonrpc":"2.0","method":"AudioPlaylist.Add","id" :1,"params":{"item":[{"artistid":89},{"artistid":80}]}}

Regards


- Montellese - 2011-04-12

noem Wrote:I'd like to mention that correct invocation of AudioPlaylist.Add requires non-valid JSON string:

Code:
{"jsonrpc":"2.0","method":"AudioPlaylist.Add","id" :1,"params":{"item":{"artistid":89},"item":{"artistid":80}}}

therefore, it should be something like:
Code:
{"jsonrpc":"2.0","method":"AudioPlaylist.Add","id" :1,"params":{"item":[{"artistid":89},{"artistid":80}]}}

Regards

The first example is a non-valid JSON string because the second "item" property of "params" overwrites the first one. There is no way of getting both artistid's if you provide such a JSON string. Furthermore there is no support in AudioPlaylist.Add to provide multiple artistid's or albumid's or whatever right now so there is nothing wrong with how you have to provide the parameters as it is not a supported feature. You can only define one "item" object right now.