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 - 2011-01-05

litemotiv Wrote:Thanks for your reply Montellese. Unfortunately, replacing all the single quotes still gives a parse error.

The mootools request object is also using single quotes internally though, so i'm not sure if there still is a problem there in some way: https://github.com/mootools/mootools-core/blob/master/Source/Request/Request.js

I feared as much as what you provide for the json rpc request is javascript syntax and there the single quote is alright.

The question is how mootools formats the json object you provide it with and how it is sent to XBMC. Can you use something like Firebug to look at the actually sent HTTP request? This might help in locating the problem.

EDIT: Just had another thought. How do you tell mootools where XBMC is located? Your url only says "/jsonrpc" but there is no IP or something like that. But as I don't know mootools anymore (last time I used it it was in the very first beta Wink) this is simply a shot in the dark.


- litemotiv - 2011-01-05

Montellese Wrote:I feared as much as what you provide for the json rpc request is javascript syntax and there the single quote is alright.

The question is how mootools formats the json object you provide it with and how it is sent to XBMC. Can you use something like Firebug to look at the actually sent HTTP request? This might help in locating the problem.

EDIT: Just had another thought. How do you tell mootools where XBMC is located? Your url only says "/jsonrpc" but there is no IP or something like that. But as I don't know mootools anymore (last time I used it it was in the very first beta Wink) this is simply a shot in the dark.

Firebug only says it is doing a post with the following data:
Code:
[application/x-www-form-urlencoded]
id    1
jsonrpc    2.0
method    Files.GetSources
params[media]    video

[Source]
jsonrpc=2.0&method=Files.GetSources&id=1&params[media]=video

So no sign of any quotes there. I'm pretty sure that the url is alright though..


- Montellese - 2011-01-05

litemotiv Wrote:Firebug only says it is doing a post with the following data:
Code:
[application/x-www-form-urlencoded]
id    1
jsonrpc    2.0
method    Files.GetSources
params[media]    video

[Source]
jsonrpc=2.0&method=Files.GetSources&id=1&params[media]=video

So no sign of any quotes there. I'm pretty sure that the url is alright though..

I think the problem is this: "application/x-www-form-urlencoded"

Looks like mootools changes your whole request into an url encoded format as shown at the end:
Code:
jsonrpc=2.0&method=Files.GetSources&id=1&params[media]=video
Another way to find out how mootools sends your request to XBMC is to check the XBMC log. Start XBMC make the request and close it. Then check XBMCs log file and you should see something like
Code:
ERROR: JSONRPC: Failed to parse '
somewhere in the log. There you should see the exact request how it was received by XBMC. If you don't see anything try enabling debug logging in XBMC (but it should be there without it being enabled).


- litemotiv - 2011-01-05

Montellese Wrote:I think the problem is this: "application/x-www-form-urlencoded"

Looks like mootools changes your whole request into an url encoded format as shown at the end:
Code:
jsonrpc=2.0&method=Files.GetSources&id=1&params[media]=video

You're right, the conversion to querystring which mootools does by default is the problem... I've used a workaround for this which seems to work, but i'm going to nag the mootools developers a little to change this for json requests. Wink

Thanks for your help!


- Montellese - 2011-01-06

I'd say they should convert it to a query string if you use GET but leave it as a jso object if you use POST. D'ont know if it would make sense for XBMC to support GET requests as well...


- topfs2 - 2011-01-06

Montellese Wrote:I'd say they should convert it to a query string if you use GET but leave it as a jso object if you use POST. D'ont know if it would make sense for XBMC to support GET requests as well...

It may be be arguably sane, i.e. it may be no problem accepting GET also, but jsonrpc spec regarding http communication states post to be used for the json object. I know some servers accept RESTless stuff though.


- Montellese - 2011-01-06

topfs2 Wrote:It may be be arguably sane, i.e. it may be no problem accepting GET also, but jsonrpc spec regarding http communication states post to be used for the json object. I know some servers accept RESTless stuff though.

I just checked and the JSON RPC 1.1 specification has a definition for HTTP GET (http://json-rpc.org/wd/JSON-RPC-1-1-WD-20060807.html#GetProcedureCall). But it states that HTTP GET does not allow json objects as parameters which is kind of a huge drawback.


- litemotiv - 2011-01-06

Montellese Wrote:I just checked and the JSON RPC 1.1 specification has a definition for HTTP GET (http://json-rpc.org/wd/JSON-RPC-1-1-WD-20060807.html#GetProcedureCall). But it states that HTTP GET does not allow json objects as parameters which is kind of a huge drawback.

I would be pretty nice to accept json objects through post, and querystrings through get?


- Mindzai - 2011-01-07

Hi all,

I'm having a problem using the TCP transport via PHP's sockets implementation. I am using the following code:

PHP Code:
$buffer '';
do {
    
$data socket_read($this->socket1024);
    if (
socket_last_error($this->socket) == 104) {
        throw new 
XBMC_RPC_ClientException('Connection reset by peer');
        break;
    }
    if (!empty(
$data)) {
        
$buffer .= $data;
    } elseif (
$data === '') {
        throw new 
XBMC_RPC_ClientException('Socket closed unexpectedly');
        break;
    }
} while (!empty(
$data)); 

However this produces an infinite loop. If I check the data from socket_read, I see that I'm getting the same data each time, ie the first 1024 bytes of the response, so the loop never terminates. Is there something I'm doing wrong here?

EDIT: Seems its not an infinite loop but rather the socket is blocking. If I use socket_recv with the MSG_DONTWAIT flag I get an error:

Code:
unable to read from socket [11]: Resource temporarily unavailable

EDIT2: Never mind. I guess XBMC is not sending any kind of EOF character or otherwise to indicate the end of a message so the socket blocks while it's waiting. I ended up just counting the number of { and } characters in the response, though it seems messy to me.


- litemotiv - 2011-01-09

This was probably asked before, but is there or will there be a sortmethod for the audiolibrary available ?


- litemotiv - 2011-01-09

I'm also experiencing some kind of strange bug: when i retrieve AudioPlaylist.GetItems while audio is playing, XBMC dies. The music keeps playing until the song is finished, then X (linux here) crashes and drops to the shell.

Any ideas on how to debug this? All other rpc calls work without problems.


- topfs2 - 2011-01-09

litemotiv Wrote:This was probably asked before, but is there or will there be a sortmethod for the audiolibrary available ?

Every call to get a list has a sorting option you may use.


- Montellese - 2011-01-09

litemotiv Wrote:I'm also experiencing some kind of strange bug: when i retrieve AudioPlaylist.GetItems while audio is playing, XBMC dies. The music keeps playing until the song is finished, then X (linux here) crashes and drops to the shell.

Any ideas on how to debug this? All other rpc calls work without problems.
First thing might be to enable debug logging in XBMC and then reproduce the problem and check the debug log (and pastebin it). I'll see if the problem exists on Windows and report back.
EDIT: Seems to work properly on windows. Made several calls to AudioPlaylist.GetItems and nothing out of the ordinary happend. Is it with all songs/albums/playlists?

topfs2 Wrote:Every call to get a list has a sorting option you may use.
Last time I used it I thought it didn't work properly but I didn't investigate further (but it's on my TODO list).


- litemotiv - 2011-01-10

Montellese Wrote:First thing might be to enable debug logging in XBMC and then reproduce the problem and check the debug log (and pastebin it). I'll see if the problem exists on Windows and report back.
EDIT: Seems to work properly on windows. Made several calls to AudioPlaylist.GetItems and nothing out of the ordinary happend. Is it with all songs/albums/playlists?

I can reproduce it 100% so far, xbmc completely crashes (happens with all songs/albums/etc). Both with Library and file browser.

This is on Arch linux, kernel 2.6.36 and kernel 2.6.37, xbmc 10.0 release version.

Request:
Code:
X-Request:JSON
X-Requested-With:XMLHttpRequest

{"jsonrpc":"2.0","method":"AudioPlaylist.GetItems","id":1,"params":""}

Log:
Code:
13:25:37 T:139820897503296 M:1447632896   DEBUG: CGUIInfoManager::SetCurrentSong(/home/ollie/music/downloads-check/Higher Limits presents Promised Land Volume 2 - mixed by Fabio/Promised Land 2 CD2 - Unmixed (1996)/01 - Crystl - Paradise.flac)
13:25:37 T:139820897503296 M:1447632896   DEBUG: Loading additional tag info for file /home/ollie/music/downloads-check/Higher Limits presents Promised Land Volume 2 - mixed by Fabio/Promised Land 2 CD2 - Unmixed (1996)/01 - Crystl - Paradise.flac
13:25:44 T:139820897503296 M:1447075840   DEBUG: SECTION:UnloadDll(libcurl.so.4)
13:25:44 T:139820897503296 M:1447075840   DEBUG: Unloading: libcurl.so.4
13:26:07 T:139820897503296 M:1444724736   DEBUG: SECTION:UnloadDelayed(DLL: special://xbmcbin/system/ImageLib-x86_64-linux.so)
13:26:07 T:139820897503296 M:1444724736   DEBUG: Unloading: ImageLib-x86_64-linux.so
13:26:08 T:139820897503296 M:1444794368   DEBUG: ADDON: cpluff: 'Plug-in webinterface.mtouch has been uninstalled.'

[...many uninstalls here...]

13:26:08 T:139820897503296 M:1444794368    INFO: ADDON: cpluff: 'An unreleased information object was encountered at address 0x18639c0 with reference count 1 when destroying the associated plug-in context. Not releasing the object.'
13:26:08 T:139820897503296 M:1444794368    INFO: ADDON: cpluff: 'An unreleased information object was encountered at address 0x18233e0 with reference count 1 when destroying the associated plug-in context. Not releasing the object.'
13:26:08 T:139820897503296 M:1444794368   ERROR: (pthread_mutex_destroy(&m_mutex)): [XCriticalSection.cpp:84] 16
13:26:08 T:139820897503296 M:1449111552 WARNING: Cleanup: Having to cleanup texture mouse.png
13:26:08 T:139820897503296 M:1449111552 WARNING: Cleanup: Having to cleanup texture osd/osd_progress_back.png
13:26:08 T:139820897503296 M:1449111552 WARNING: Cleanup: Having to cleanup texture osd/osd_progress_mid.png
13:26:08 T:139820897503296 M:1449111552 WARNING: Cleanup: Having to cleanup texture osd/osd_progress_right.png
13:26:08 T:139820897503296 M:1449111552 WARNING: Cleanup: Having to cleanup texture osd/osd_progress_left.png
13:26:08 T:139820897503296 M:1449111552 WARNING: Cleanup: Having to cleanup texture osd/osd_progress_clear.png
13:26:08 T:139820897503296 M:1450762240 WARNING: Cleanup: Having to cleanup texture osd/osd_progressmid.png
13:26:08 T:139820897503296 M:1450762240 WARNING: Cleanup: Having to cleanup texture home/nowplaying_info.png
13:26:08 T:139820897503296 M:1450762240 WARNING: Cleanup: Having to cleanup texture home/nowplaying_back.png
13:31:08 T:139820578825984 M:1447370752   DEBUG: Error: Requested setting (services.webskin) was not found.  It must be case-sensitive



- litemotiv - 2011-01-10

topfs2 Wrote:Every call to get a list has a sorting option you may use.

I can't seem to get it working, what would be the sortmethod parameters for retrieving the album or artists lists, ordered by name/title? Do they use the database fields, or something else?

I've tried stuff like this:
Code:
{"jsonrpc":"2.0","method":"AudioLibrary.GetAlbums","id":1,"params":{"sortmethod":"strAlbum","start":0,"end":10}}