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)



RE: JSON-RPC (JSON Remote Procedure Call) interface protocol in development for XBMC - A guy - 2012-06-02

Hello. I'm sorry for being total idiot in this. I tried to do the HTTP posting thing, but it just isn't working out. I can understand the JSON syntax more or less, but I fail to pass the command to XBMC. Maybe some of you guys could show me how it's done in html or something for complete new to this thing. I'd really appreciate it. Thank you for your time.

Edit: I tested around with REST client on chrome at the data I send works, does what it needs to do. However I just can't get it working with html, then again i don't know if I'm doing things correctly. Currently I'm just trying to post {"jsonrpc": "2.0", "method": "Input.Select", "id": 1} throught html. I'm very bad at improvising


RE: JSON-RPC (JSON Remote Procedure Call) interface protocol in development for XBMC - Montellese - 2012-06-03

(2012-06-01, 23:32)Archigos Wrote: Once I get back home and start toying with this again, I imagine your example (along with Montellese's comment) something like these would work for the Volume? (I don't want to give exact percentages).
Code:
{"jsonrpc": "2.0", "method": "Application.SetVolume", "params": { "volume": "increment"}, "id": 1}
{"jsonrpc": "2.0", "method": "Application.SetVolume", "params": { "volume": "decrement"}, "id": 1}
Yes that should work.

(2012-06-01, 23:32)Archigos Wrote: So, "id": "1" should be at the end of each command... I'm guessing it wouldn't hurt to just leave it there even when I'm done since the script outputs everything to a div which I'm hiding in the released version. Also, I think it was in the post, pages back, but I thought the id specified type, like "id": "1" was for video or is this just another area I misunderstood? (The posts were about adding images not in the library into a slideshow or something like that).
The "id" we are talking about here comes from the JSON-RPC 2.0 specification and has nothing to do with XBMC itself. Generally JSON-RPC can't assure that when you send request A and then B that you will first receive the response for request A and then the response for request B. It could be the other way around. So by specifying a "unique" "id" value for every request you can use the "id" value returned in the response to match a request with a response. What most people do is just use an integer value and increment it with every request they make. the "playerid" in XBMC's Player methods are something totaly different and are very XBMC-specific.

(2012-06-01, 23:32)Archigos Wrote: I'll remove all the permissions and set the id's. So, something like the following should work for Mute then?
Code:
{"jsonrpc": "2.0", "method": "Application.SetMute", "params": {"mute": "toggle"}, "id": "1"}
Yes that should work.

(2012-06-02, 23:36)A guy Wrote: Hello. I'm sorry for being total idiot in this. I tried to do the HTTP posting thing, but it just isn't working out. I can understand the JSON syntax more or less, but I fail to pass the command to XBMC. Maybe some of you guys could show me how it's done in html or something for complete new to this thing. I'd really appreciate it. Thank you for your time.

Edit: I tested around with REST client on chrome at the data I send works, does what it needs to do. However I just can't get it working with html, then again i don't know if I'm doing things correctly. Currently I'm just trying to post {"jsonrpc": "2.0", "method": "Input.Select", "id": 1} throught html. I'm very bad at improvising
What do you mean by "through html"? If you want to write a webinterface for XBMC (or something similar web-based) you either need to use JavaScript (and send POST requests or use WebSockets (which are not available in Eden)) or you need another programming/scripting language like PHP or Python.


RE: JSON-RPC (JSON Remote Procedure Call) interface protocol in development for XBMC - Archigos - 2012-06-03

(2012-06-02, 23:36)A guy Wrote: Hello. I'm sorry for being total idiot in this. I tried to do the HTTP posting thing, but it just isn't working out. I can understand the JSON syntax more or less, but I fail to pass the command to XBMC. Maybe some of you guys could show me how it's done in html or something for complete new to this thing. I'd really appreciate it. Thank you for your time.

Edit: I tested around with REST client on chrome at the data I send works, does what it needs to do. However I just can't get it working with html, then again i don't know if I'm doing things correctly. Currently I'm just trying to post {"jsonrpc": "2.0", "method": "Input.Select", "id": 1} throught html. I'm very bad at improvising
I know the feeling, I was in the same boat very recently. It took days but I was able to get it working through a JavaScript I wrote that uses the new Websocket in the Pre-Frodo nightly builds. If you're using a recent version I'm more than willing to share the code... (it sends via PHP, but 'may' be able to be modified easy for straight HTML, however Montellese's comment hints that straight HTML may not work anyway). I'm just curious, are you just doing this for personal internal use or for a project that will be released to the community? The reason I'm asking is if you want to help contribute to the community, maybe we can collaborate a little on the project I'm working on. PM me if you're interested in helping or just need the *.js and *.php file to get it working.

(2012-06-03, 11:15)Montellese Wrote:
(2012-06-01, 23:32)Archigos Wrote: Once I get back home and start toying with this again, I imagine your example (along with Montellese's comment) something like these would work for the Volume? (I don't want to give exact percentages).
Code:
{"jsonrpc": "2.0", "method": "Application.SetVolume", "params": { "volume": "increment"}, "id": 1}
{"jsonrpc": "2.0", "method": "Application.SetVolume", "params": { "volume": "decrement"}, "id": 1}
Yes that should work.

(2012-06-01, 23:32)Archigos Wrote: So, "id": "1" should be at the end of each command... I'm guessing it wouldn't hurt to just leave it there even when I'm done since the script outputs everything to a div which I'm hiding in the released version. Also, I think it was in the post, pages back, but I thought the id specified type, like "id": "1" was for video or is this just another area I misunderstood? (The posts were about adding images not in the library into a slideshow or something like that).
The "id" we are talking about here comes from the JSON-RPC 2.0 specification and has nothing to do with XBMC itself. Generally JSON-RPC can't assure that when you send request A and then B that you will first receive the response for request A and then the response for request B. It could be the other way around. So by specifying a "unique" "id" value for every request you can use the "id" value returned in the response to match a request with a response. What most people do is just use an integer value and increment it with every request they make. the "playerid" in XBMC's Player methods are something totaly different and are very XBMC-specific.

(2012-06-01, 23:32)Archigos Wrote: I'll remove all the permissions and set the id's. So, something like the following should work for Mute then?
Code:
{"jsonrpc": "2.0", "method": "Application.SetMute", "params": {"mute": "toggle"}, "id": "1"}
Yes that should work.
Thanks for the added info... I noticed the commands I had in that post worked after I got home to test, just forgot to post a thank you at that point. Now that I've managed to semi-wrap my head around getting the commands to work the way I want, now I just need to learn how to either handle or format the returned info into something useful for the end users.


RE: JSON-RPC (JSON Remote Procedure Call) interface protocol in development for XBMC - alicharles - 2012-06-03

Dear Community
I have had a pretty good read of these posts and the changes.
I am a novice but I spent a bit of time writing a simple text based remote control to run on my Linux desktop, mainly so I didn't have to keep picking my phone up to skip tracks and so I could play internet radio steams et..
These are the commands I used per Eden, which worked well for my basic needs.
The http stuff obviously still works but needs to be rewritten when that channel is fully removed, but I am having issues updating my commands for the JSON-RPC API v4

curl -i -X POST -d '{"jsonrpc": "2.0", "method": "AudioLibrary.ScanForContent", "id": "1"}' http://192.168.0.50:8080/jsonrpc ;;
curl 'http://192.168.0.50:8080/xbmcCmds/xbmcHttp?command=ExecBuiltIn&parameter=XBMC.updatelibrary(video)' ; sleep 5 ;;
curl "http://192.168.0.50:8080/xbmcCmds/xbmcHttp?command=ExecBuiltIn&parameter=%20PlayerControl%28Partymode%29" ;;
curl -i -X POST -d '{"jsonrpc": "2.0", "method": "AudioPlayer.PlayPause", "id": "1"}' http://192.168.0.50:8080/jsonrpc ;;
curl -i -X POST -d '{"jsonrpc": "2.0", "method": "AudioPlayer.Stop", "id": "1"}' http://192.168.0.50:8080/jsonrpc ;;
curl -i -X POST -d '{"jsonrpc": "2.0", "method": "AudioPlayer.State", "id": 1}' http://192.168.0.50:8080/jsonrpc ; sleep 4;;
curl -i -X POST -d '{"jsonrpc": "2.0", "method": "AudioPlayer.SkipNext", "id": 1}' http://192.168.0.50:8080/jsonrpc;;

curl "http://192.168.0.50:8080/xbmcCmds/xbmcHttp?command=getcurrentlyplaying" ; sleep 5;;
curl "http://192.168.0.50:8080/xbmcCmds/xbmcHttp?command=PlayFile%28smb://192.168.0.50/music/-0AdminTools/Future.m3u%29" ; sleep 4;;

I hoped it would be a simple change to the following

curl -i -X POST -d '{"jsonrpc":"2.0","method":"Player.PlayPause","params":{"playerid":1}}' http://192.168.0.50:8080/jsonrpc
HTTP/1.1 200 OK
Content-Length: 0
Content-Type: application/json
Date: Sun, 03 Jun 2012 15:13:04 GMT


OR

curl -i -X POST -d '{"jsonrpc": "2.0", "method": "Player.PlayPause", "params": { "playerid": 1 }, "id": 1}' http://192.168.0.50:8080/jsonrpc
HTTP/1.1 200 OK
Content-Length: 86
Content-Type: application/json
Date: Sun, 03 Jun 2012 15:39:08 GMT

{"error":{"code":-32100,"message":"Failed to execute method."},"id":1,"jsonrpc":"2.0"}


but neither of these appear to work, yet it also doesn't return any errors and I was really hoping for a pointer in the right direction.
XBMC Eden is running in standalone on Ubuntu 10.04 base
Many Thanks.



RE: JSON-RPC (JSON Remote Procedure Call) interface protocol in development for XBMC - Montellese - 2012-06-03

(2012-06-03, 17:46)alicharles Wrote: Dear Community
I have had a pretty good read of these posts and the changes.
I am a novice but I spent a bit of time writing a simple text based remote control to run on my Linux desktop, mainly so I didn't have to keep picking my phone up to skip tracks and so I could play internet radio steams et..
These are the commands I used per Eden, which worked well for my basic needs.
The http stuff obviously still works but needs to be rewritten when that channel is fully removed, but I am having issues updating my commands for the JSON-RPC API v4

curl -i -X POST -d '{"jsonrpc": "2.0", "method": "AudioLibrary.ScanForContent", "id": "1"}' http://192.168.0.50:8080/jsonrpc ;;
curl 'http://192.168.0.50:8080/xbmcCmds/xbmcHttp?command=ExecBuiltIn&parameter=XBMC.updatelibrary(video)' ; sleep 5 ;;
curl "http://192.168.0.50:8080/xbmcCmds/xbmcHttp?command=ExecBuiltIn&parameter=%20PlayerControl%28Partymode%29" ;;
curl -i -X POST -d '{"jsonrpc": "2.0", "method": "AudioPlayer.PlayPause", "id": "1"}' http://192.168.0.50:8080/jsonrpc ;;
curl -i -X POST -d '{"jsonrpc": "2.0", "method": "AudioPlayer.Stop", "id": "1"}' http://192.168.0.50:8080/jsonrpc ;;
curl -i -X POST -d '{"jsonrpc": "2.0", "method": "AudioPlayer.State", "id": 1}' http://192.168.0.50:8080/jsonrpc ; sleep 4;;
curl -i -X POST -d '{"jsonrpc": "2.0", "method": "AudioPlayer.SkipNext", "id": 1}' http://192.168.0.50:8080/jsonrpc;;

curl "http://192.168.0.50:8080/xbmcCmds/xbmcHttp?command=getcurrentlyplaying" ; sleep 5;;
curl "http://192.168.0.50:8080/xbmcCmds/xbmcHttp?command=PlayFile%28smb://192.168.0.50/music/-0AdminTools/Future.m3u%29" ; sleep 4;;

I hoped it would be a simple change to the following

curl -i -X POST -d '{"jsonrpc":"2.0","method":"Player.PlayPause","params":{"playerid":1}}' http://192.168.0.50:8080/jsonrpc
HTTP/1.1 200 OK
Content-Length: 0
Content-Type: application/json
Date: Sun, 03 Jun 2012 15:13:04 GMT


OR

curl -i -X POST -d '{"jsonrpc": "2.0", "method": "Player.PlayPause", "params": { "playerid": 1 }, "id": 1}' http://192.168.0.50:8080/jsonrpc
HTTP/1.1 200 OK
Content-Length: 86
Content-Type: application/json
Date: Sun, 03 Jun 2012 15:39:08 GMT

{"error":{"code":-32100,"message":"Failed to execute method."},"id":1,"jsonrpc":"2.0"}


but neither of these appear to work, yet it also doesn't return any errors and I was really hoping for a pointer in the right direction.
XBMC Eden is running in standalone on Ubuntu 10.04 base
Many Thanks.

Does your question only concern the Player.PlayPause request or all of the above?
If you want to control the audio player you need to pass "playerid" with a value of 0 and not 1. 1 is currently assigned to the video player. If you pass a "playerid" value of a player that is currently not active you will get a "Failed to execute method" error message.

(2012-06-03, 17:46)alicharles Wrote: curl -i -X POST -d '{"jsonrpc": "2.0", "method": "AudioLibrary.ScanForContent", "id": "1"}' http://192.168.0.50:8080/jsonrpc ;;
AudioLibrary.Scan
(2012-06-03, 17:46)alicharles Wrote: curl 'http://192.168.0.50:8080/xbmcCmds/xbmcHttp?command=ExecBuiltIn&parameter=XBMC.updatelibrary(video)' ; sleep 5 ;;
VideoLibrary.Scan
(2012-06-03, 17:46)alicharles Wrote: curl "http://192.168.0.50:8080/xbmcCmds/xbmcHttp?command=ExecBuiltIn&parameter=%20PlayerControl%28Partymode%29" ;;
There's currently no alternative for this in JSON-RPC
(2012-06-03, 17:46)alicharles Wrote: curl -i -X POST -d '{"jsonrpc": "2.0", "method": "AudioPlayer.PlayPause", "id": "1"}' http://192.168.0.50:8080/jsonrpc ;;
Player.PlayPause with "playerid" as 0
(2012-06-03, 17:46)alicharles Wrote: curl -i -X POST -d '{"jsonrpc": "2.0", "method": "AudioPlayer.Stop", "id": "1"}' http://192.168.0.50:8080/jsonrpc ;;
Player.Stop with "playerid" as 0
(2012-06-03, 17:46)alicharles Wrote: curl -i -X POST -d '{"jsonrpc": "2.0", "method": "AudioPlayer.State", "id": 1}' http://192.168.0.50:8080/jsonrpc ; sleep 4;;
Player.GetProperties with "playerid" as 0 and an array of "properties" you are interested in
(2012-06-03, 17:46)alicharles Wrote: curl -i -X POST -d '{"jsonrpc": "2.0", "method": "AudioPlayer.SkipNext", "id": 1}' http://192.168.0.50:8080/jsonrpc;;
Player.GoNext with "playerid" as 0
(2012-06-03, 17:46)alicharles Wrote: curl "http://192.168.0.50:8080/xbmcCmds/xbmcHttp?command=getcurrentlyplaying" ; sleep 5;;
Player.GetItem with "playerid" as 0 and an array of "properties" you are interested in
(2012-06-03, 17:46)alicharles Wrote: curl "http://192.168.0.50:8080/xbmcCmds/xbmcHttp?command=PlayFile%28smb://192.168.0.50/music/-0AdminTools/Future.m3u%29" ; sleep 4;;
Player.Open with the "item" parameter containing the "file" property set to the file you would like to start playing.


RE: JSON-RPC (JSON Remote Procedure Call) interface protocol in development for XBMC - _Andy_ - 2012-06-04

Hello

In Eden i query the database with a command like: @"{\"jsonrpc\": \"2.0\", \"method\": \"VideoLibrary.GetMovies\", \"params\": {\"properties\": [\"file\",\"year\",\"genre\",\"runtime\",\"fanart\",\"thumbnail\",\"plot\"],\"sort\":{\"method\":\"label\",\"order\":\"ascending\"}},\"id\": 1}";

As fanart and thumbnail i got a link to the special folder in xbmc. So i could download the pictures from my HTPC.

For testing purpose i updated to Frodo. No i get a link to imgobject.com. Is this a change? How can i retrieve the old style?




RE: JSON-RPC (JSON Remote Procedure Call) interface protocol in development for XBMC - Montellese - 2012-06-04

Yes after Eden jmarshall has changed the way XBMC caches images. They are now referenced with an URI of the following schema:
Code:
image://<url encoded uri from where the image originally came>
and that's also what you should get through JSON-RPC. You should still be able to URL-encode the whole image URI you get through JSON-RPC and call http://<ip>:<port>/vfs/<url encoded image path> but you should switch to using http://<ip>:<port>/image/<url encoded image path> which (in the future) will provide additional functionality like automatic image resizing during retrieval etc. So basically nothing has changed, the returned URIs just look different.


RE: JSON-RPC (JSON Remote Procedure Call) interface protocol in development for XBMC - alicharles - 2012-06-04

Excellent. Thanks Montellese, I was only looking for the help on the mistakes but you have answered them all. Much appreciated.


RE: JSON-RPC (JSON Remote Procedure Call) interface protocol in development for XBMC - alicharles - 2012-06-04

I have a further query here with the information. When passing the getcurrentlyplaying using http request. I get all the information returned. However when using the Player.GetItem I only every return the song title? Do I have a syntax issue?

Even when I request only Artist or Album I still return the title. Examples. Thanks


$ curl "http://192.168.0.50:8080/xbmcCmds/xbmcHttp?command=getcurrentlyplaying"

<html>
<li>Filename:/var/lib/mythtv/music/Masters of Persian Music/Without You/Masters of Persian Music_Without You_09_Zarbi Bayat-e Kord and Tasnif (Del-e Divaneh (Baba Taher)).mp3
<li>PlayStatusTonguelaying
<li>SongNo:0
<li>Type:Audio
<li>Title:Zarbi Bayat-e Kord and Tasnif (Del-e Divaneh (Baba Taher))
<li>Track:9
<li>Artist:Masters of Persian Music
<li>Album:Without You
<li>Genre:Reggae
<li>Year:2002
<li>URL:/var/lib/mythtv/music/Masters of Persian Music/Without You/Masters of Persian Music_Without You_09_Zarbi Bayat-e Kord and Tasnif (Del-e Divaneh (Baba Taher)).mp3
<li>Lyrics:
<li>Bitrate:197
<li>Samplerate:44
<li>ThumbBig GrinefaultAlbumCover.png
<li>Time:01:05
<li>Duration:08:47
<li>Percentage:12
<li>File size:12979705
<li>Changed:True
</html>
-------
$ curl -i -X POST -d '{"jsonrpc":"2.0","method":"Player.GetItem","params":{"playerid":0},"id": "0"} "properties":["Title", "Artist", "Album"]}' http://192.168.0.50:8080/jsonrpc
HTTP/1.1 200 OK
Content-Length: 100
Content-Type: application/json
Date: Mon, 04 Jun 2012 19:54:21 GMT

{"id":"0","jsonrpc":"2.0","result":{"item":{"id":35680,"label":"Positivity (Remix)","type":"song"}}}
-------
$ curl -i -X POST -d '{"jsonrpc":"2.0","method":"Player.GetItem","params":{"playerid":0},"id": "0"} "properties":["Artist"]}' http://192.168.0.50:8080/jsonrpc
HTTP/1.1 200 OK
Content-Length: 100
Content-Type: application/json
Date: Mon, 04 Jun 2012 19:55:14 GMT

{"id":"0","jsonrpc":"2.0","result":{"item":{"id":35680,"label":"Positivity (Remix)","type":"song"}}}ali@ali-laptop:~$








RE: JSON-RPC (JSON Remote Procedure Call) interface protocol in development for XBMC - alicharles - 2012-06-04

Issue solved with a slight change

curl -i -X POST -d '{ "jsonrpc": "2.0", "method": "Player.GetItem", "params": { "playerid": 0, "properties": ["title","artist"] }, "id": 0 }' http://192.168.0.50:8080/jsonrpc


RE: JSON-RPC (JSON Remote Procedure Call) interface protocol in development for XBMC - Montellese - 2012-06-07

(2012-05-22, 10:27)Millencolin007 Wrote: With this change I loose my current way to distinguish if playback was stopped automatically or through user interaction. Any chance this info can be added back to the notification using an additional parameter or by sending a different notification if playback was stopped automatically or through user interaction?

I have just committed a change that adds an "end" parameter to the Player.OnStop notification. If it's value is true the player has reached the end of the playable item(s). If it's false the player was (manually) stopped before having finished playback. Hope that's good enough for your purposes.


RE: JSON-RPC (JSON Remote Procedure Call) interface protocol in development for XBMC - Montellese - 2012-06-07

(2012-05-27, 16:15)Mizaki Wrote: There seems to be a problem with adding directories that are not in the library:
Code:
{"jsonrpc": "2.0", "method": "Playlist.Add", "params": {"item": {"directory": "/mnt/media/audio/Art Brut/Bang Bang Rock 'n Roll/"}, "playlistid": 0}, "id": 1}
Works and is in library.
Code:
{"jsonrpc": "2.0", "method": "Playlist.Add", "params": {"item": {"directory": "/mnt/media/music/A/How Ace Are Buildings/"}, "playlistid": 0}, "id": 1}
Does not work and is not in library. Invalid params is the error.

Am I missing something?

Sorry for not answering earlier but there was also a bug report on trac about this a few days ago and I fixed it. Can you check if it works again for you in latest master? Thanks.


RE: JSON-RPC (JSON Remote Procedure Call) interface protocol in development for XBMC - Millencolin007 - 2012-06-07

(2012-06-07, 13:42)Montellese Wrote:
(2012-05-22, 10:27)Millencolin007 Wrote: With this change I loose my current way to distinguish if playback was stopped automatically or through user interaction. Any chance this info can be added back to the notification using an additional parameter or by sending a different notification if playback was stopped automatically or through user interaction?

I have just committed a change that adds an "end" parameter to the Player.OnStop notification. If it's value is true the player has reached the end of the playable item(s). If it's false the player was (manually) stopped before having finished playback. Hope that's good enough for your purposes.

Thanks, exactly what I needed.


RE: JSON-RPC (JSON Remote Procedure Call) interface protocol in development for XBMC - Mizaki - 2012-06-07

(2012-06-07, 13:44)Montellese Wrote:
(2012-05-27, 16:15)Mizaki Wrote: There seems to be a problem with adding directories that are not in the library:
Code:
{"jsonrpc": "2.0", "method": "Playlist.Add", "params": {"item": {"directory": "/mnt/media/audio/Art Brut/Bang Bang Rock 'n Roll/"}, "playlistid": 0}, "id": 1}
Works and is in library.
Code:
{"jsonrpc": "2.0", "method": "Playlist.Add", "params": {"item": {"directory": "/mnt/media/music/A/How Ace Are Buildings/"}, "playlistid": 0}, "id": 1}
Does not work and is not in library. Invalid params is the error.

Am I missing something?

Sorry for not answering earlier but there was also a bug report on trac about this a few days ago and I fixed it. Can you check if it works again for you in latest master? Thanks.

No problem. I saw it and tried it yesterday. Seems to have fixed it. Thanks.


RE: JSON-RPC (JSON Remote Procedure Call) interface protocol in development for XBMC - rickles - 2012-06-08

Hi, I have spent way too much time trying to figure this out so I hope someone can help me. I am using curl to remotely export my video library from the terminal:

Code:
curl --data-binary '{ "jsonrpc": "2.0", "method": "VideoLibrary.Export", "id": "mybash"}' -H 'content-type: application/json;' http://htpc:8080/jsonrpc

I want to include the "images": "true" option so that my fanart and thumbnails are exported too. Can someone show me how to add it to the above command? Thanks very much.