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)



- barrygordon - 2010-10-15

welshboy, I have had my best results using the raw TCP Socket. You enable that I believe in system/network "allow external control". The TCP port is 9090. you send to the port a simple sequence that looks like :
"POST /jsonrpc\r\n\r\n"+ the JSON object you wish to transmit as in

"POST /jsonrpc\r\n\r\n"+"{\"jsonrpc\": \"2.0\", \"method\": \"JSONRPC.Version\", \"id\": 1}"

This will return the version of JSON that is running. Took me a few days to figure it out so I empathize. I am not sure if the blank line between the "Prefix" and the JSON object is needed. You may be able to get away with a prefix of "POST /jsonrpc\r\n" or "POST /jsonrpc ". The above is all javascript syntax


- topfs2 - 2010-10-15

barrygordon Wrote:welshboy, I have had my best results using the raw TCP Socket. You enable that I believe in system/network "allow external control". The TCP port is 9090. you send to the port a simple sequence that looks like :
"POST /jsonrpc\r\n\r\n"+ the JSON object you wish to transmit as in

"POST /jsonrpc\r\n\r\n"+"{\"jsonrpc\": \"2.0\", \"method\": \"JSONRPC.Version\", \"id\": 1}"

This will return the version of JSON that is running. Took me a few days to figure it out so I empathize. I am not sure if the blank line between the "Prefix" and the JSON object is needed. You may be able to get away with a prefix of "POST /jsonrpc\r\n" or "POST /jsonrpc ". The above is all javascript syntax

Well on the RAW port you don't need to do anything besides send jsonobjects, we do strip anything which isnt' a jsonobject but you don't need to send it.

So for raw just putty in and {\"jsonrpc\": \"2.0\", \"method\": \"JSONRPC.Version\", \"id\": 1}


- Ilia - 2010-10-15

I might be doing something wrong, but does the sortmethod for GetMovies and GetRecentlyAddedMovies work?

curl -i -X POST -d '{"jsonrpc": "2.0", "method": "VideoLibrary.GetRecentlyAddedMovies","params":{"fields":["rating"],"sortmethod":"rating","sortorder":"ascending"}, "id": 1}' http://localhost:8080/jsonrpc

??


- topfs2 - 2010-10-15

Ilia Wrote:I might be doing something wrong, but does the sortmethod for GetMovies and GetRecentlyAddedMovies work?

curl -i -X POST -d '{"jsonrpc": "2.0", "method": "VideoLibrary.GetRecentlyAddedMovies","params":{"fields":["rating"],"sortmethod":"rating","sortorder":"ascending"}, "id": 1}' http://localhost:8080/jsonrpc

??

It has been changed, its sort: { "method": "rating", "order": "ascending" }


- hello_man - 2010-10-15

topfs2 Wrote:It has been changed, its sort: { "method": "rating", "order": "ascending" }

Topfs2, is there any documenation or some way to know all the apis exposed and their respective parameters and return value?

thanks,


- Ilia - 2010-10-15

topfs2 Wrote:It has been changed, its sort: { "method": "rating", "order": "ascending" }

Thanks for the reply, but I am still not getting the right result

curl -i -X POST -d '{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovies","params":{"fields":["rating"],"method":"rating","order":"ascending"}, "id": 1}' http://localhost:8080/jsonrpc

It still sorts then by movieid


- Ilia - 2010-10-15

hello_man Wrote:Topfs2, is there any documenation or some way to know all the apis exposed and their respective parameters and return value?

thanks,

There is a wiki page at http://wiki.xbmc.org/index.php?title=JSON_RPC, but it seems to be out of date and incomplete Sad


- dstruktiv - 2010-10-15

JSONRPC.Introspect and digging through the c++ jsonrpc code in the xbmc svn (Everything's easy to read even if c++ is new to you).

JSON-RPC interface is still in beta and under heavy development I don't think it's fair to expect all documentation to be 100% accurate and up to date.


- barrygordon - 2010-10-15

Thanks for the simplification. It will make things simpler and a trivial change since most of the code I wrote is table driven for flexibility!!


- Ilia - 2010-10-15

Found it, by digging though cpp, if anyone is intrested:

"sort":{"method":"videorating","order":"descending"} <- make sure u have no spaces between the ""

other methods: date, size, file, drivetype, track, duration, title, artists, album, genre, year, videorating, programcount, playlist, episode, title (video), sorttitle (without "the") productioncode, songrating, mpaarating, videoruntime, studio, fullpath, lastplayer, unsorted, max

all available to see in xbmc/lib/libjsonrpc/FileItemHandler.cpp


- Montellese - 2010-10-15

Hey guys

As Soundgraph has released a first API to access their LCDs and VFDs from 3rd party applications I started writing a tool (with C#) which uses the JSON-RPC service XBMC provides with Dharma to display information about currently playing items on the LCD/VFD. I found the xbmc-json library developped by dstruktiv and think it's quite useful. But I am lacking the possibility of receiving announcements (I absolutely don't want to poll the status of the players every second or so).
Could someone please provide me some detailed information on how to catch those announcements? As far as I found out these are broadcasted over TCP on port 9090. Is that correct and is that port fixed or do I need to configure it somewhere?


- topfs2 - 2010-10-15

Montellese Wrote:Could someone please provide me some detailed information on how to catch those announcements? As far as I found out these are broadcasted over TCP on port 9090. Is that correct and is that port fixed or do I need to configure it somewhere?

Just open a TCP socket to 9090 and there you have it. By default you are listening to all announcements but for future reference you can use the SetAnnouncementFlags to tell which you actually are interested in.

To test just use putty against 9090 and you'll get the data.

No way to configure, always 9090. It should be announced over zeroconf which is a good way to handle if it ever changes.


- Montellese - 2010-10-15

topfs2 Wrote:Just open a TCP socket to 9090 and there you have it. By default you are listening to all announcements but for future reference you can use the SetAnnouncementFlags to tell which you actually are interested in.

To test just use putty against 9090 and you'll get the data.

No way to configure, always 9090. It should be announced over zeroconf which is a good way to handle if it ever changes.

Thanks. Just wanted to confirm the details on the port and the protocol as it is not available in the wiki article. Maybe I'll try to extend the xmbc-json plugin to throw an event when something comes in.


- MKay - 2010-10-15

topfs2 Wrote:Hmm, I didn't think of your scenario MKay.[...]
(topfs2 asked me to post my PM here for discussion about solutionsSmile

To get the currently playing data (e.g. artist and title of a song) i need to get the active player (GetActivePlayers) and then get the playlist's items with GetItems. The result contains a field with the name "current" which is the playlist-entry-index of the currently playing file, right?
So when i want to get the artist/title of the currently playing song i can retrieve the playlist's data with GetItems and everything is fine.

But when a song is playing (playlist has one entry) and i clear the playlist with AudioPlaylist.Clear then there is no way to get the artist/title of the currently playing file because the GetItems-function of the playlist will return an empty list (as i know).

At least this was the case in beta2 ... beta3 not tested yet Smile


- Tolriq - 2010-10-15

After some tests i can confirm that System.GetInfoLabels is good for getting currently informations even with empty playlist :p
Even permit to send one less request for getting the seekposition Smile

See http://wiki.xbmc.org/?title=InfoLabels for list Smile


Just a little question not json related but since it have the same effect perhaps topfs have a solution Smile

The info label : System.KernelVersion always send busy on the first request need to wait for 300 or 400 ms to retry and get the data (same with httpapi)

Not very important but since i use this to check if Yatse connects to the correct machine it's annoying to add delays for nothing Sad