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)



- Montellese - 2012-02-29

JSON-RPC does not support PVR yet so it's not really a bug it just isn't supported.

Nonetheless what do you mean by "Can't use it"? Do none of the commands work? What error do you get?


- yallah - 2012-02-29

Montellese Wrote:JSON-RPC does not support PVR yet so it's not really a bug it just isn't supported.

Nonetheless what do you mean by "Can't use it"? Do none of the commands work? What error do you get?


by exemple, if i use PVR.ChannelSwitch method when pvr video is in full screen the channel can change. but if pvr video is in window inside xbmc's home page or in pvr page i can't change channel with PVR.ChannelSwitch. And information is not received in xbmc because i can't get any log when json command doesn't work.


- Montellese - 2012-02-29

Ah these PVR specific methods are not from me and I don't have them in my code because I don't use PVR yet. You might wanna contact FSSDawid which implemented the JSON-RPC extensions for PVR so far (see https://github.com/opdenkamp/xbmc/pull/355).


- yallah - 2012-02-29

Montellese Wrote:Ah these PVR specific methods are not from me and I don't have them in my code because I don't use PVR yet. You might wanna contact FSSDawid which implemented the JSON-RPC extensions for PVR so far (see https://github.com/opdenkamp/xbmc/pull/355).

ok thx


- jimk72 - 2012-02-29

Tolriq Wrote:For currently playing, you can ask for totaltime and time to get those informations.

thanks!! that is exactly what I was looking for!


- Millencolin007 - 2012-03-02

I was playing around with the json api today and run into a couple of issues I wanted to share:

Files.PrepareDownload is not working as I expected on the windows platform. (tested with eden rc2/beta3)
When retrieving a list of audio files using (AudioLibrary.GetSongs) the file paths are returned with backslashes in the path, which produces an error message when used as argument in the Files.PrepareDownload call.


Request:
{"jsonrpc": "2.0", "method": "Files.PrepareDownload", "params": { "path":"D:\MP3\123.mp3" }, "id": 1}

Response:
{"error":{"code":-32700,"message":"Parse error."},"id":null,"jsonrpc":"2.0"}

Replacing the backslashes with forward slashes the call works.
Request:
{"jsonrpc": "2.0", "method": "Files.PrepareDownload", "params": { "path":"D:/MP3/123.mp3" }, "id": 1}

Response:
{"id":1,"jsonrpc":"2.0","result":{"details":{"path":"vfs/D%3a%2fMP3%2f123%2emp3"},"mode":"redirect","protocol":"http"}}


The returned path (http://xbmc_ip: port/vfs/D%3a%2fMP3%2f123%2emp3 ) cannot be played by xbmc when it is added to a playlist using a json call like the following:
{"jsonrpc": "2.0", "method": "Playlist.Add", "params" : { "playlistid" : 0 , "item" : { "file" : "%s" } }, "id" : 1 }

If %2e is replaced with a . so that the file ends in .mp3 playback works.


- Montellese - 2012-03-02

Millencolin007 Wrote:I was playing around with the json api today and run into a couple of issues I wanted to share:

Files.PrepareDownload is not working as I expected on the windows platform. (tested with eden rc2/beta3)
When retrieving a list of audio files using (AudioLibrary.GetSongs) the file paths are returned with backslashes in the path, which produces an error message when used as argument in the Files.PrepareDownload call.


Request:
{"jsonrpc": "2.0", "method": "Files.PrepareDownload", "params": { "path":"D:\MP3\123.mp3" }, "id": 1}

Response:
{"error":{"code":-32700,"message":"Parse error."},"id":null,"jsonrpc":"2.0"}
It's the job of either your JSON library or yourself to escape special characters and backslash (\) is a special character. XBMC does this as well but once you interpret it in your client as a string it will remove the double slashes. So you'll need to send the path as "D:\\MP3\\123.mp3"

Millencolin007 Wrote:Replacing the backslashes with forward slashes the call works.
Request:
{"jsonrpc": "2.0", "method": "Files.PrepareDownload", "params": { "path":"D:/MP3/123.mp3" }, "id": 1}

Response:
{"id":1,"jsonrpc":"2.0","result":{"details":{"path":"vfs/D%3a%2fMP3%2f123%2emp3"},"mode":"redirect","protocol":"http"}}
This is not the correct way to go.

Millencolin007 Wrote:The returned path (http://xbmc_ip: port/vfs/D%3a%2fMP3%2f123%2emp3 ) cannot be played by xbmc when it is added to a playlist using a json call like the following:
{"jsonrpc": "2.0", "method": "Playlist.Add", "params" : { "playlistid" : 0 , "item" : { "file" : "%s" } }, "id" : 1 }

If %2e is replaced with a . so that the file ends in .mp3 playback works.
I'm a bit confused. You use AudioLibrary.GetSongs, then Files.PrepareDownload (which is obviously meant to download the file through HTTP and not for playback) and then you use that result to play it again in XBMC? Why don't you use the "songid" of that particular song (which is returned by AudioLibrary.GetSongs) in the first place?


- Millencolin007 - 2012-03-02

Thanks, now that you say it, it makes absolutely sense to escape the backslash.

You are right. Normally one would add the song by songid. I used the prepare download function to retrieve the download url with the idea in mind to play this url on another xbmc instance or sending a playback request to an airplay capable device.


- Montellese - 2012-03-02

Millencolin007 Wrote:You are right. Normally one would add the song by songid. I used the prepare download function to retrieve the download url with the idea in mind to play this url on another xbmc instance or sending a playback request to an airplay capable device.

Ah right I didn't consider that. So it doesn't work with XBMC and other (non-xbmc) airplay capable devices? The problem is that the path after "/vfs/" can contain anything so we need to URL encode it. Not sure if it makes sense to URL encode everything except the dot before the file extension.


- digitaldesaster - 2012-03-02

Hi,

i am playin around with json-rpc and jquery.

Quote:<script>
$.post('http://myxbmc:8080/jsonrpc', '{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovies","params": { "properties": ["thumbnail"]}, "id": 1}',
function(data){

jQuery.each(data.result.movies, function(index, value) {
image=data.result.movies[index].thumbnail;
$("body").append("<img src='myxbmc/vfs/"+image+"' class='mystyle'></img>");


});




}, "json");
</script>

because of the cross-domain policy i get in trouble. this code does work in safari but not in chrome. is there an easy way without modifying the xbmc-server (php proxy) to get direct jquery access up and running in my lanHuh

regards
dd


- Montellese - 2012-03-02

Currently not as it is a browser limitation. I have already written code to support websockets but it will not be available in Eden but should make it into XBMC soon after Eden has been released. websockets should support cross-domain communication.


- digitaldesaster - 2012-03-03

thanks for this info..
dd


- Millencolin007 - 2012-03-03

Montellese Wrote:Ah right I didn't consider that. So it doesn't work with XBMC and other (non-xbmc) airplay capable devices? The problem is that the path after "/vfs/" can contain anything so we need to URL encode it. Not sure if it makes sense to URL encode everything except the dot before the file extension.

Unfortunately I don't have any airplay capable devices except xbmc therefore I cannot confirm that the problem exists in general with airplay devices. (Playback on android is working using android.media.MediaPlayer)

Below the output from the xbmc logs when trying to play a file with the encoded "." Maybe xbmc needs a file extension to be able to decode the file correctly

Code:
21:35:17 T:3043596080   ERROR: CAudioDecoder: Unable to Init Codec while loading file http://10.0.0.127:8080/vfs/%2fhome%2fxbmc%2fMusic%2fBob%20Sinclar%20feat%2e%20Sean%20Paul%20%2d%20Disco%20Crash%20%2d%202012%2f07%20%2d%20Bob%20Sinclar%20feat%2eHot%20Rod%20%2d%20Put%20Your%20Handz%20Up%2emp3|User-Agent=AppleCoreMedia/1.0.0.8F455 (Appleā€ TV; U; CPU OS 4_3 like Mac OS X; de_de)



- hans234567 - 2012-03-04

Montellese Wrote:Over TCP you don't have to send a header and there's no authentication but it's more work for the client because you don't get "messages" but a stream so you need to count { and } to know when a JSON-RPC response (or a notification) is complete.

Wouldn't it be easier (for the client) if xbmc sends a LF after a 'message' as a end of message character?

Simply counting { or } doesn't help when this happens:
Code:
{"member":"}"}



- Montellese - 2012-03-04

hans234567 Wrote:Wouldn't it be easier (for the client) if xbmc sends a LF after a 'message' as a end of message character?

This has been discussed at least three times in this thread at length. It would be easier but it is not part of any specification so we would kind of operate outside of the specification which might lead to incompatibility with certain very strict JSON(-RPC) libraries. Furthermore it would mean that if we ever change our JSON library in XBMC we would have to remember that we need to modify that library to send an extra (CR)LF after every message. Last but not least it would not work to look for something like "}\r\n" or "}\n" in the received data because if a user has pretty printing enabled for XBMC's JSON-RPC output (which can be done through advancedsettings.xml) you will get lots of those patterns in one JSON-RPC response/message.