• 1
  • 2
  • 3(current)
  • 4
  • 5
  • 226
JSON-RPC (JSON Remote Procedure Call) interface protocol in development for XBMC
#31
jez500 Wrote:Hi all, long time xbmc fan, first time poster.

Firstly a big thanks to all involved in the move to json (and xbmc in general), it is a dream to use compared to the old httpapi. I am a web developer by trade and have been working on a web ui over the last few months. The news of a json-rpc was music to my ears, So I decided to spend a few days rebuilding my app using json but during this process I got a bit stuck on a few things...

Glad to see that the decision to move to json is appreciated by the client creators Smile

jez500 Wrote:1. Search : I found the combination of QueryMusicDatabase + LIKE %q% + searchbox + ajax resulted in powerful and fast itunes style searching. I can’t seem to make “MusicLibrary.GetSongs” do the same thing, is it possible? I am currently grabbing all songs at page load and looping through each item when searched - which I don’t think will scale well.

Great idea! I'll add some form of filter parameters to all the FooLibrary.GetBar calls.

Does
Code:
{"jsonrpc": "2.0", "method": "MusicLibrary.GetSongs", "params": { "filter": { "artist": "FOO", "album": "BAR" } } , "id": 1 }
Sounds like a plan?

I think filter object could have some settings aswell, like compare case and such aswell. Only problem might be if you want to compare case on artist but not album, but I doubt many will need that? If we need more granualirity it probably need to be something like:
Code:
"filter": { "artist": { "beginswith": "ac", "endswith": "dc", "casesensative": false } }
But that might be cluttery?

Also FOO and BAR would probably be regular expressions, sounds best imo?

jez500 Wrote:2. Add to Playlist: “Playlist.Add” doesn’t seem to have the same power as AddToPlayListFromDB, I found the ability to add songs, albums or artists to the playlist by id to be very useful.

Yeah it really needs to be connected with db here for sure, same with play and such aswell.

jez500 Wrote:3. Playlist data: more of a feature request here but it would be great if each playlist item was a fully loaded db row. Eg artist, artistid, genre, albumid, album ,thumb....etc. The virtual playlist sounds very cool!

Hmm, thought it did do that already. I'll need to check that abit Smile the code is in place to handle the data atleast if data is given.

jez500 Wrote:4. Maybe these don’t exist yet or maybe I'm going blind but I cannot find equivalents of: clearPlayList, playFile, GetCurrentlyPlaying and SetPlaylistSong, any ideas?

I have been using this: http://pastebin.com/m340ebb83 and the default web interface (nightly win32 xbmc-r28256-trunk.exe) as my point of reference for documentation, is there anywhere else I should be looking?

Thanks again for all the great work!

To clear playlists you call "Playlist.Clear" with ID.

GetCurrentlyPlaying is still not implemented, basically I'm missing some stuff in core to make it working (threadsafe atleast). But playlist without ID can be used for the same thing in the mean time (check code in NowPlaying.html).

Thanx for the great ideas and kind words, hope you get it working.

Cheers,
Tobias
If you have problems please read this before posting

Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.

Image

"Well Im gonna download the code and look at it a bit but I'm certainly not a really good C/C++ programer but I'd help as much as I can, I mostly write in C#."
Reply
#32
topfs2 Wrote:Also FOO and BAR would probably be regular expressions, sounds best imo?

Woudln't using regexp's require you to scan the entire db for each query? Using SQL LIKE logic would allow the DB to use it's indexes.
Reply
#33
Hi Tobias
Yep I think the filter sounds spot on. The extra granularity would be nice but the filter by itself (especially if it is a regex) would probably suit 99% of cases.
Thanks for all the other tips, I will give them a go.

While I have your ear, A few other things Smile
-MusicPlayer.PlayPause, SkipPrevious, SkipNext do not seem work unless an item on the plalylist is already playing, it would be nice if they actioned the most recently used playlist.
Also it is a bit of a hassle having to map your controls to different namespaces for the same control methods, is it possible to get a generic wrapper for them. Eg. Player.PlayPause = MusicPlayer.PlayPause or VideoPlayer.PlayPause or PicturePlayer.PlayPause. In most cases I think there will only have one set of controls it seems a bit cumbersome doing all the logic on the client side.
-Does GetSongs song duration work? It was returning 0 for every result for me.
-I am guessing this is to do with no more GoAhead web server (or dev version of xbmc) but xbmc crashes if my webpage includes a css/js file that is in a sub folder.
-This one might be pushing it but I would love a way to add a rating to a song. or even better, setters you could use on the db (so you could use the a web ui to clean up your music or video collection)
-Lastly... I think its great that Playlist.Swap is now available, and much better than before (nothing) however what I would find more useful would be something like Playlist.setPosition {"playlist": "music", "item": 0, "position": 1 } and it would insert the x item in y position, pushing everything down.

Cheers,
Jeremy
Reply
#34
Zeron Wrote:Woudln't using regexp's require you to scan the entire db for each query? Using SQL LIKE logic would allow the DB to use it's indexes.

Well only if there actually is an index on the column you use the LIKE. And most often there aren't more than 1 index on a table so the index stuff wouldn't help.

BUT it is always faster to let the database handle as much of the filtering as possible (as that's what good database systems are tuned for) and only get the records you really want.

BTW if the database system uses UTF-8 as encoding it might be that it doesn't support case insensitivity. But that highly depends on the database system and only applies to table columns stored with an UTF-8 encoding.
Always read the online manual (wiki), FAQ (wiki) and search the forum before posting.
Do not e-mail Team Kodi members directly asking for support. Read/follow the forum rules (wiki).
Please read the pages on troubleshooting (wiki) and bug reporting (wiki) before reporting issues.
Reply
#35
is there an executejsonapi(0 equivelant for executehttpapi() in python.

and if you are not going to allow querying the database (or did i read that wrong) will require scripts to use pysqlite or equivelant.

which is builtin to python 2.6
For python coding questions first see http://mirrors.xbmc.org/docs/python-docs/
Reply
#36
Definitely allowing querying, just not arbitrary querying.
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.


Image
Reply
#37
I understand sql queries are powerfull and versatile but all need to consider that using sql in xbmc is subject to change, httpapi is one of those last roadblocks that doesn't use an abstracted form of the database, so its one of the last thing making it impossible to move from sqllite.

This is why it might be hard to do filter as a SQL query, howerver I would like that too since it will be speedier, need to think about it for a while

Nuka1195 Wrote:is there an executejsonapi(0 equivelant for executehttpapi() in python.

and if you are not going to allow querying the database (or did i read that wrong) will require scripts to use pysqlite or equivelant.

which is builtin to python 2.6

I'll add a executejsonapi but it won't be as nicely wrapped as jsonrpc is in python normally though, atleast I'm not proficient in python to do that Smile
If you have problems please read this before posting

Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.

Image

"Well Im gonna download the code and look at it a bit but I'm certainly not a really good C/C++ programer but I'd help as much as I can, I mostly write in C#."
Reply
#38
Thumbs Up 
Missed this thread completely until now. This is extremely good news! Performance will be way better. A great moment to start developing a java based cross platform remote controller Smile

edit: I've worked with json in web development a lot. Are there any examples available on how to remotely access the api?
Image

Please add to my reputation if you find my posts usefull (+/- button below posts)
Ubuntu 12.10 minimal XBMC auto-install script :: XBMControl :: Xbmc XBOX Skins :: XBMControl for Android :: Owner of Sudo Systems
Reply
#39
Bram77 Wrote:Missed this thread completely until now. This is extremely good news! Performance will be way better. A great moment to start developing a java based cross platform remote controller Smile

edit: I've worked with json in web development a lot. Are there any examples available on how to remotely access the api?

Indeed, the best example is probably the webinterface in svn since it uses it.

Here is a python script I use to test stuff though. Works with python script.py Method Params
Quote:python script.py MusicLibrary.GetSongs '{ "start": 0, "end": 3 }'
If you have problems please read this before posting

Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.

Image

"Well Im gonna download the code and look at it a bit but I'm certainly not a really good C/C++ programer but I'd help as much as I can, I mostly write in C#."
Reply
#40
played around a little, looks very promising.

postdata = json.dumps({'jsonrpc': "2.0", 'method': "VideoLibrary.GetMovieInfo", 'movieid': 11})

this gives a parse error:
{'message': 'Parse error.', 'code': -32700}

is there a page where params are listed? is "movieid" correct?

i would like to switch to this as it is easier, no parsing, but...
1. I do: respdata = eval( urllib.urlopen(jsonrpcurl, postdata ).read() )
this sets respdata as a valid dictionary, so no json module necessary
what does json.dumps() do. i printed it out and it doesn't appear to change anything.

could the above urlopen accept a urlencoded(postdata) where postdata is just the dictionary of items?

i get the same parse error as above when trying that with your {"jsonrpc": "2.0", 'method': "VideoLibrary.GetMovies", 'id': "1"}

urlencoded: jsonrpc=2.0&method=VideoLibrary.GetMovies&id=1

2. would the executejsonapi require the webserver to be enabled? if so, it may not be needed. i don't think it would be anymore convenient than your posted method.
For python coding questions first see http://mirrors.xbmc.org/docs/python-docs/
Reply
#41
ok i tried the example from the introspective listing

VideoLibrary.GetMovieInfo
Parameter example { "movieid": 0, "fields": ["plot"] }

i get the parse error
For python coding questions first see http://mirrors.xbmc.org/docs/python-docs/
Reply
#42
Frack, those GetInfo shouldn't be there Smile They don't do anything, still you shouldn't get parse error.

Although it could be because you mix ' ' and " " but the dump should serialize it correctly afaik. Could you pastebin a Debug Log when you get the errors?

the correct call should be { "jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", "params": { "foo": "bar" }, "id": 1 }

as for 1, nope it does not except urlencoded nor will it since its not really needed and outside jsonrpc specification. The postdata is seperate from the url your calling, I mean the post data is binary data you send to a certain location, your actually uploading a json to the server.

The dump just takes a json python type and serialize it afaik, I'm not extremely good with python but in my example I didn't use dump even though it can be used.
I'm not entirely sure I understand the map question but root json object is a map { "foo": "bar" } is a map were foo is key and bar is value. check here for more info

nbr 2. Right! jsonrpc has no dependency that the webserver is running so yeah an executejsonapi wouldn't need the webserver running so a clear benefit having it in python scripts then. Although if scripters use the web one (or tcp which is always active) the script can be run outside xbmc.

I'll add the executejsonrpc call to python ASAP, will do it to take a serialized json and return a serialized json, hope thats enough for most uses.

Cheers,
Tobias
If you have problems please read this before posting

Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.

Image

"Well Im gonna download the code and look at it a bit but I'm certainly not a really good C/C++ programer but I'd help as much as I can, I mostly write in C#."
Reply
#43
You always need the "jsonrpc": "2.0" don't know why Smile

Do you use a recent build ? some of previous build had problems with multi paquets requests.
Reply
#44
topsf2, no debug log, i'm just running it from python not xbmc.

my build is pre addons merge, so if things are fixed after that, then could be an issue. but it sounds like the getInfo calls aren't hooked in yet, so that was my issue.

as for urlencoding the data, that's a python spec i guess. not important as long as i don't need json.dump() unless xbmc includes the package.

Quote:
urlopen(url[, data[, proxies]])

If the url uses the http: scheme identifier, the optional data argument may be given to specify a POST request (normally the request type is GET). The data argument must be in standard application/x-www-form-urlencoded format; see the urlencode() function below

look forward to executejsonapi Smile
For python coding questions first see http://mirrors.xbmc.org/docs/python-docs/
Reply
#45
Pre addon merge should be plenty if its the latest one. I've altered some calls after but nothing major.

Hmm, weird that the python states that the post data should be urlencoded, I'll take a better look into it but afaik the spec for jsonrpc is non encoded.

We log the calls a client makes in xbmc.log so if you get parse error it will state exactly how it recieved the data, so could be good for debugging.

Afaik json.dump should be safe to use, http://docs.python.org/library/json.html shows some examples and none of them are urlencoded?
If you have problems please read this before posting

Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.

Image

"Well Im gonna download the code and look at it a bit but I'm certainly not a really good C/C++ programer but I'd help as much as I can, I mostly write in C#."
Reply
  • 1
  • 2
  • 3(current)
  • 4
  • 5
  • 226

Logout Mark Read Team Forum Stats Members Help
JSON-RPC (JSON Remote Procedure Call) interface protocol in development for XBMC8