Kodi Community Forum

Full Version: JSON-RPC (JSON Remote Procedure Call) interface protocol in development for XBMC
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
in no language!

Some of us have to communicate with xbmc over a raw tcp port.

I will post a working call later today.

Would it be possible to have user specified formatting if the output? Say, if user created format file foo doesn't exist output in the default manner?

For example, here is what my perl scrip returns for an artist request.

STARTDATA###ENDRECORD
CLEARARTISTS###ENDRECORD
XBMCARTIST###1###(hed) Planet Earth###ENDRECORD
XBMCARTIST###7###.38 Special###ENDRECORD
XBMCARTIST###5###10,000 Maniacs###ENDRECORD
XBMCARTIST###2###3 Doors Down###ENDRECORD
XBMCARTIST###3###3-6 Mafia###ENDRECORD
XBMCARTIST###9###311###ENDRECORD
XBMCARTIST###6###38 Special###ENDRECORD
ENDDATA###ENDRECORD

topfs2 Wrote:Simple example in what language? its plain jsonrpc and any language has more or less a wrapper for it.

the poc webinterface is by far the simplest IMO, here is a pastebin of my testing python script if it helps http://pastebin.com/BhmCq6kH

Call with python foo.py Method [Parameter]
For example
python foo.py JSONRPC.Introspect

or

python foo.py AudioLibrary.GetArtists '{ "start": 1, "end": 3 }'
Fiasco Wrote:in no language!

Some of us have to communicate with xbmc over a raw tcp port.

Read JSONRPC specifications, its nothing weird over a raw tcp port, its just a serialized json following jsonrpc 2.0 spec.

The given script even prints the raw jsonrpc dump. I've written raw jsonrpc dumps in lots of posts in this very thread.


Fiasco Wrote:Would it be possible to have user specified formatting if the output? Say, if user created format file foo doesn't exist output in the default manner?

NO! The whole point of jsonrpc is to stop the user configuration formating nonsense. json is a simple, human readable, standardized serialization of objects. Any programing languages have parsers and generators readily available for you to use. If you need to have a special formating for a closed source product you must create a middleman, its impossible to have configuration to support all and every given products formating.
Here is a working call in CommandFusion

POST /jsonrpc HTTP/1.1\x0D\x0AContent-Length: 64\x0D\x0AHOST: 192.168.2.202:80\x0D\x0A\x0D\x0A{"jsonrpc": "2.0", "method": "AudioLibrary.GetArtists", "id": 1}\x0D\x0A
topfs2 Wrote:NO! The whole point of jsonrpc is to stop the user configuration formating nonsense. json is a simple, human readable, standardized serialization of objects. Any programing languages have parsers and generators readily available for you to use. If you need to have a special formating for a closed source product you must create a middleman, its impossible to have configuration to support all and every given products formating.

Can I open up a persistant tcp port connection to the xbmc json server or is it like HTTP with a disconnect after request/response?

I'm trying to use the output of json for commandfusion. I am limited to splitting the output on a user selected end of message marker (im using }) and running a regex on each value group to get the info I need.

Unfortunately no luxury of wrappers/parsers (beyond line by line regex)
Here is the list of commands linked in the first page.

Under music library I see
MusicLibrary.GetArtists
MusicLibrary.GetSongs
MusicLibrary.GetAlbums
and
MusicLibrary.GetSongInfo

Would it be possible to add a GetArtistInfo and GetAlbumInfo to retrieve artist biographies and album discographies?
Great. Thanks for the example. Now I understand how I am supposed to interface with json rpc. I was able to write some php to get and set the volume. Thanks.
Fiasco Wrote:Here is the list of commands linked in the first page.

Under music library I see
MusicLibrary.GetArtists
MusicLibrary.GetSongs
MusicLibrary.GetAlbums
and
MusicLibrary.GetSongInfo

Would it be possible to add a GetArtistInfo and GetAlbumInfo to retrieve artist biographies and album discographies?

Although I do see MusicLibrary commands in the list of commands on the first page, I do not see them in development.html. Does this mean that the commands are not implemented... or not tested?

Is there a way to get the artist of a song from a playlist?
marksoccer Wrote:Although I do see MusicLibrary commands in the list of commands on the first page, I do not see them in development.html. Does this mean that the commands are not implemented... or not tested?

Is there a way to get the artist of a song from a playlist?

The page i pulled those commands from must be out of date (it's linked in the first post of this thread)
marksoccer Wrote:Although I do see MusicLibrary commands in the list of commands on the first page, I do not see them in development.html. Does this mean that the commands are not implemented... or not tested?

Yeah as Fiasco said, they are out of date. Always refer to the Introspect (this is what development.html shows).

marksoccer Wrote:Is there a way to get the artist of a song from a playlist?

Getting fields is exactly the same throughout the interface by design (no proper docs about that yet though, haven't had time writing it)

{ "jsonrpc": "2.0", "method": "AudioPlaylist.GetItems", "params": { "fields": ["album", "lyrics", "duration", "rating"], "end": 100 }, "id": 1 }

Fiasco Wrote:Here is the list of commands linked in the first page.

Under music library I see
MusicLibrary.GetArtists
MusicLibrary.GetSongs
MusicLibrary.GetAlbums
and
MusicLibrary.GetSongInfo

Would it be possible to add a GetArtistInfo and GetAlbumInfo to retrieve artist biographies and album discographies?

The GetSongInfo have been removed as its not needed. Similair to how SQL works you have the ability to choose whatever fields you need when calling the GetFoo methods. Again, what parameters they take is discussed quite much in this thread but the idea is that development.html (and introspect) should give you examples (not done for Audio Library though and some others).
Example:
{ "jsonrpc": "2.0", "method": "AudioLibrary.GetAlbums", "params": { "fields": ["album", "lyrics", "duration", "rating"], "end": 100 }, "id": 1 }

Fiasco Wrote:Can I open up a persistant tcp port connection to the xbmc json server or is it like HTTP with a disconnect after request/response?

Sure, the raw TCP port can be kept for as long as you wish, whenever you have sent a proper jsonrpc command xbmc will respond. You can do this for how long as you wish and then disconnect.

Fiasco Wrote:I'm trying to use the output of json for commandfusion. I am limited to splitting the output on a user selected end of message marker (im using }) and running a regex on each value group to get the info I need.

Unfortunately no luxury of wrappers/parsers (beyond line by line regex)

I have no clue what commandfusion is but if its proprietary you can always create a middleman script that translates to what commandfusion understand, this if far more flexible than transforming what jsonrpc server sends to fit the device (wouldn't be jsonrpc then even).

Cheers,
Tobias
Thanks for your responses I hope I'm not trying your patience.

Is the port for raw TCP communication to the JSON server different than the http port specified in XBMC?
At this time it's the same since the data is served by the Web Server Smile

Most of the time testing and reading gives most answers Smile
Tolriq Wrote:At this time it's the same since the data is served by the Web Server Smile

Most of the time testing and reading gives most answers Smile

So can I write a raw json request to the same port or do I have to wrap it in a HTTP POST?

I've read and reread this thread several times.

And of course the joy of wireshark Wink
Well it's as it's served by HTTP, yes you need to wrap it into HTTP Smile

The main difference beetween httpapi and json is that the dataposted and received is formated in a well known and popular format (JSON) that most language have implementations for.
Fiasco Wrote:Thanks for your responses I hope I'm not trying your patience.

Is the port for raw TCP communication to the JSON server different than the http port specified in XBMC?

Nah, not trying my patience at all Smile If its early I might have a bit grumpier responses but any unclear fact about jsonrpc is good if it comes out in the open since this will be the base of the documentation and FAQ Smile

raw TCP is on another port, 9090 IIRC (should be announced by zeroconf).
So you gave this example

{ "jsonrpc": "2.0", "method": "AudioLibrary.GetAlbums", "params": { "fields": ["album", "lyrics", "duration", "rating"], "end": 100 }, "id": 1 }

Is the "end" : 100 a limiter (first 100 records?)

How would I go about doing this for just one album, something like?

{ "jsonrpc": "2.0", "method": "AudioLibrary.GetAlbums", "params": { "albumid": albumid, "fields": ["album", "lyrics", "duration", "rating"]}, "id": 1 }


or pull an artists biography and fanart, something like

{"jsonrpc": "2.0", "method": "AudioLibrary.GetArtists", "params": { "artistid": 9, "fields": ["biography", "fanart"] }, "id": 1}


http://192.168.2.5:81/jsonrpc



http://192.168.2.5:81/jsonrpc