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)



- Fiasco - 2010-06-22

I almost completely sidestepped the HTTP API by putting an Apache Server and Perl on my XBMC box to query the databases directly. The HTTP API wasn't "parse friendly" to a 3rd party control system.

I also pull playlists this way (scan the folder in perl) and than correlate the items in the playlist file to the database so I can display the actual playlist songs on my iPad GUI.

The end result is

http://www.youtube.com/watch?v=QaejslEb-fE

I hope JSON allows me to dump the seperate Apache Server and query XBMC directly.


- Kabooga - 2010-06-22

Fiasco, I queried the databases by using HTTP API calls "queryvideodatabase" and "querymusicdatabase." These were not published in the WIKI but I did find them in the code.

Currently the JSON API doesn't support direct database queries. I don't know if it ever will.


- jmarshall - 2010-06-22

It won't. Direct queries will not be allowed.


- Fiasco - 2010-06-22

Kabooga Wrote:Fiasco, I queried the databases by using HTTP API calls "queryvideodatabase" and "querymusicdatabase." These were not published in the WIKI but I did find them in the code.

Currently the JSON API doesn't support direct database queries. I don't know if it ever will.

I initially tried querying the database with the HTTP API but the response wasn't exactly readily parsable by a 3rd party controller. By doing the query myself w/ apache/perl I was able to structure the responses to be exactly what I wanted.

I also didn't have to program in a long query string into my 3rd party controller instead doing something like

xbmc.pl?type=artistlist
xbmc.pl?type=artistalbums&artistid=3
xbmc.pl?type=playlists

ect ect


- Kabooga - 2010-06-22

Yeah. The parsing of the returned data from "querymusicdatabase" was a pain in the rear.


- topfs2 - 2010-06-23

Fiasco Wrote:I hope JSON allows me to dump the seperate Apache Server and query XBMC directly.

Sure, you can access the JSONRPC from anything, so a middle man server should have no troubles getting to it.

Regarding the queries, no it won't ever be added, reason is simple. Its major PITA for those using the API. Its silly unsecure (anyone on the web could wipe your db). Multiplies the work a silly amount (every user of the API needs to do what XBMC already knows how to do).

Checkout the poc_jsonrpc in trunk and you'll see that the new way is still rather flexible (ofcourse never as flexible as direct sql) but tons easier.


- marksoccer - 2010-06-23

topfs2 Wrote:Isn't PHP run by the server? the new webserver have no support what so ever for server side scripting Smile

Yeah, PHP is run server side. For my project, I don't want to assume that the server is hosting xbmc. For development, my server will be running both xbmc and apache, but I would like to support the scenario in which someone is running an apache server on one machine and xbmc on another machine. I figured by keeping the majority of stuff server side, I can support low end devices like phones, psp's and the like. However, it looks like json requires a fair amount of client side stuff.


- topfs2 - 2010-06-23

marksoccer Wrote:Yeah, PHP is run server side. For my project, I don't want to assume that the server is hosting xbmc. For development, my server will be running both xbmc and apache, but I would like to support the scenario in which someone is running an apache server on one machine and xbmc on another machine. I figured by keeping the majority of stuff server side, I can support low end devices like phones, psp's and the like. However, it looks like json requires a fair amount of client side stuff.

Sure the jsonrpc requires more client side but in your scenario the client for jsonrpc is the php backend, not the phone Smile


- Nuka1195 - 2010-06-23

topfs2, i'm working on a new recentlyadded.py script using json.

there are some limitations, eg movie totals and lastwatched items.

here is the unfinished script http://xbmc-addons.googlecode.com/svn/packages/RecentlyAdded.py

you can see i'm cyclying thru the results to calculate totals. this is incredibly slow with larger db. this use to be done with a sql command and httpapi.

can this be added, also there is some return info not available. here is a patch for some of it, but maybe more could/should be added. http://xbmc-addons.googlecode.com/svn/packages/json.diff

also getting the most recently added for music would be nice.

also a parameter to getmostrecent that could skip watched items.

and could a sortmethod by lastplayed be added, this would enable getmovies eg to limit to 1, the most recent.

and as a side note since i have your attention, mark as watched on a movie puts the same date and time if you do it on the same time. it's like the time is not the current time. maybe it's not the current time after the first time mark as watch is run, but closing xbmc and trying again did not change the time.


- Nuka1195 - 2010-06-23

Image

Image

this is what i'm trying to acomplish. i updated the diff to include studio and writer


- Nuka1195 - 2010-06-26

what's the policy for changes to the database.

specifically, the episode view, has everything from tvshow table except genre. i added this to the view, but this requires a new db build or a way to just drop the view then recreate it, which doesn't look like xbmc is setup to do that.

topfs2, if you are not looking into my previous suggestions two posts back, i may have a look. don't want to duplicate work.


- Fiasco - 2010-06-26

jmarshall Wrote:It won't. Direct queries will not be allowed.

Will any common queries be built in? Most of us 3rd party controller GUI builders are trying to get at the same information.


- Fiasco - 2010-06-27

Could someone post an example of a basic JSON command sent to the xbmc json server?

For example, using the HTTP API, I open a TCP port and send commands like this
GET /xbmc.pl?artistid=[artistid]&type=artistalbums HTTP/1.1\x0D\x0AHOST: http://www.host.com\x0D\x0A\x0D\x0A


- marksoccer - 2010-06-27

I second that request for a simple example. Maybe showing how to get the current volume and then set a new volume would be nice. Also, could someone show how to externally get access json rpc? I can't get the copied and pasted code from development.html to work on my apache server.

I changed the json.js address to point to the externally accessible address, but I am not sure what else I have to change. I am thinking the second parameter of this line should have the external address... but that didn't work:

Code:
http_request.open( "POST", "jsonrpc", false );

Also, I am still a little confused on how I want to setup my project. Why do I need javascript at all? All the javascript is doing is requesting a json string right? Shouldn't I be able to do that from php and then use json_decode() and json_encode() to get and send the variables? I looked into using json-rpc php , but I am guessing I would need to add a file to the xbmc web directory (which I would prefer not to do for my project).


- topfs2 - 2010-06-27

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 }'