Emby for Kodi / JSON-RPC / Alternate back end
#1
The purpose of this topic is to discuss mechanisms to enable addons such as our addon 'Emby for Kodi' to replace the Kodi DB and scrapers as a back end.

History:

Emby for Kodi started out as an addon called XBMB3C which started as a fork from PleXBMC(using MediaBrower/Emby instead of Plex) in late 2013. The addon originally worked with the traditional 'ListItem' methodology - which worked but as we expanded to try to completely replicate the native Kodi DB speed and experience we hit a wall, particularly with large collections. Also, this methodology required custom skins - which became a lot of work in themselves.

Earlier this year, marcelveldt had the idea to try using .strm files and JSON-RPC to build a Kodi DB based on the Emby DB. This created a virtual filesystem with the .strm files, which Kodi then scanned in. The meta-data was then back-filled using JSON-RPC where possible. In this setup, the Kodi DB is really a local cache of the Emby DB.

Over time, due to performance reasons and missing JSON-RPC access, this was replaced with direct DB creation/updates. At the time, we did some searches and saw similar requests for speed ups and more access - and so we didn't report our issues. The intent here is to rectify that.

Issues:

1. Creating the virtual file system containing strm and scraping the information in proved to be quite slow. It was okay for a movie collection, barely tolerable for TV and intolerable for music. The process to build my db (as an example) is currently 3 minutes on my main PC and 15 minutes on my Pi. The strm version took 45 minutes and 8 hours respectively.

2. The JSON-RPC itself is considerably slower than direct DB access. At startup we do a comparison of the local DB to the Emby DB - and again this process is considerably slower. In my example DB, 30 seconds vs. ~4 minutes on a fast machine, and 8 minutes to 45 minutes on a Pi.

3. When the JSON-RPC is running the startup comparison above, there are considerable GUI glitches. The Kodi interface becomes slow and the screen flickers. This also occurs at end of playback when we would do playstate updates.

4. The JSON-RPC does not have access to some critical fields. We need to be able to set any and every property. Some missing controls are:
  • Ability to add new items
  • Full control over artwork
  • Control over stream details
  • Control over boxsets
One of our team is set up for Kodi development (and more may follow), so some of the above enhancements may come through as pull requests.

Way Forward:

Everyone on the team is a huge Kodi fan and wants to work with the Kodi team as much as possible.

Our goal is still to completely replace the Kodi scraper and all the artwork scripts - we are willing help with JSON-RPC enhancement, and/or other ways to achieve this (like the UPNP-based DB discussion).

We would like to ask that a Kodi dev sets up Emby and Emby for Kodi to see what we are doing and really understand the extent to which we are taking over DB responsibility. Emby is now easy to install for most Linux distributions. While we know we are breaking the rules - the thing works really, really well.

Regards,
marcelveldt, null_pointer, angelblue05, im85288, xnappo, jurmb84
Reply
#2
I don't know how far off it is from being merged, but I get the impression that Montellese's media import project would be the way forward on this.
Reply
#3
Do you guys still have a snapshot of the code that does this via json-rpc? Can I have a look?

And yeah, you will be slower then direct access to the db. But there are other points were all sides will profit.
Reply
#4
Well, 10-20% slower is okay, 10x-20x slower, we need to work on (together).

I will look through the old releases later today to see if I can find a good release point.

The inability to 'add' via JSON-RPC is a pretty big stopper - null_pointer is working on a Kodi change to support that now, so may be best just to wait a bit on that and see how it performs.
Reply
#5
I may have something to play with in a day or so, the idea to start with is try to be as agile as possible on the requirements/dev and have continuous testing with what is being added.

I really dont want to put in 40 hours of work on adding a bunch of end points to add items if speed or some other show stopper just kills this approach dead in its tracks.

The good news is all of the library manipulation code is in place and it is just a matter of wrapping up the required actions in JSON-API endpoints. This should help with minimizing changes required and reducing risk of data corruption being introduced.
Reply
#6
(2015-09-08, 22:18)Ned Scott Wrote: I don't know how far off it is from being merged, but I get the impression that Montellese's media import project would be the way forward on this.

yup. I guess with JSON RPC we could potentially allow for a deeper connection with external media managers though, easier way to add features and such not found in uPnP. With that said, uPnP is very well designed and if we add some non-standard tags (which we already do) then I'm not sure if JSON RPC hooks would even be benificial. But I'm sure Montellese could answer this better given how knowledgeable he is in both JSON RPC and uPnP Smile

(2015-09-08, 22:32)Razze Wrote: Do you guys still have a snapshot of the code that does this via json-rpc? Can I have a look?

And yeah, you will be slower then direct access to the db. But there are other points were all sides will profit.

With a cache in Kodi it could potentially be negligible. Which is what Montellese has afaik.
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
#7
TBH I don't think that JSON-RPC is the right approach to achieve synchronisation of Kodi's database with any other database. It's just not fast enough right now. And while we're at it UPnP isn't really fast either. But my media importing work (which isn't bound to UPnP) would allow us (or someone else) to write a completely different synchronisation implementation specific to a custom backend with whatever protocol fits best.

I see the main problem in all these attempts to synchronise the Kodi database(s) with remote databases in the fact that our current database layout and system sucks and we really need a new one. There has been effort to do that but I haven't seen anything that really convinced me yet to invest a lot of time in it. Is the database layout (and system) for Emby documented / available somewhere?
With a better layout we could support things like minimal synchronisation based on changesets instead of having to read the whole database and then manually determining what has changed.
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
#8
(2015-09-09, 09:52)Montellese Wrote: I see the main problem in all these attempts to synchronise the Kodi database(s) with remote databases in the fact that our current database layout and system sucks and we really need a new one. There has been effort to do that but I haven't seen anything that really convinced me yet to invest a lot of time in it. Is the database layout (and system) for Emby documented / available somewhere?
With a better layout we could support things like minimal synchronisation based on changesets instead of having to read the whole database and then manually determining what has changed.

Thats actually something I plan to start working on. Splitting tables so we end up with metadata and userdata in their own tables and adding modified date stamps. Would be the first thing I thought about.
Reply
#9
(2015-09-09, 09:52)Montellese Wrote: TBH I don't think that JSON-RPC is the right approach to achieve synchronisation of Kodi's database with any other database.
agree, but at the moment it is all we have to work with.
Reply
#10
(2015-09-09, 10:11)Razze Wrote:
(2015-09-09, 09:52)Montellese Wrote: I see the main problem in all these attempts to synchronise the Kodi database(s) with remote databases in the fact that our current database layout and system sucks and we really need a new one. There has been effort to do that but I haven't seen anything that really convinced me yet to invest a lot of time in it. Is the database layout (and system) for Emby documented / available somewhere?
With a better layout we could support things like minimal synchronisation based on changesets instead of having to read the whole database and then manually determining what has changed.
Thats actually something I plan to start working on. Splitting tables so we end up with metadata and userdata in their own tables and adding modified date stamps. Would be the first thing I thought about.
Has the new DB structure project been rejected or abandoned? See http://forum.kodi.tv/showthread.php?tid=200911
Reply
#11
I think this breaks down to two phases - 1. See if we can quickly get compliant by fixing JSON-RPC enough to do the job, 2. Discussing long term ways to enable alternate DBs. #1 may end up not really being possible, but #2 will take a while and will need some consensus.
Reply
#12
Hi guys, Luke here from Emby. xnappo asked me to drop in and say a few words.

We have not currently documented the db structure although in general we do write pretty good documentation so I could do this on demand if needed. Just for a quick overview, it is a very generic structure much like our api. We don't have separate api's for movies, tv, etc. although there are sometimes features that only apply to specific content types. Our db is currently also in a bit of a state of transition where there are changes that are being made gradually from each release to the next. So until it gets to where i want it to go there are going to continue to be some adjustments, nothing drastic, but certainly enough that anyone talking to the db directly would have to pay attention to. That's why I would always recommend going through the api, just as the Kodi team does with their own. So then it's just a matter of can we get the api to perform well enough to handle these kinds of bulk operations.
Reply
#13
(2015-09-11, 03:37)lukemb Wrote: Our db is currently also in a bit of a state of transition where there are changes that are being made gradually from each release to the next. So until it gets to where i want it to go there are going to continue to be some adjustments, nothing drastic, but certainly enough that anyone talking to the db directly would have to pay attention to. That's why I would always recommend going through the api, just as the Kodi team does with their own.

I'm not planning on accessing the database directly or anything. I was just wandering what your database schema looks like to get some input for a potential new database schema in Kodi (which we need sooner than later).
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
#14
(2015-09-09, 17:02)xnappo Wrote: I think this breaks down to two phases - 1. See if we can quickly get compliant by fixing JSON-RPC enough to do the job, 2. Discussing long term ways to enable alternate DBs. #1 may end up not really being possible, but #2 will take a while and will need some consensus.
Also checkout garbear's just announced plans http://forum.kodi.tv/showthread.php?tid=238307

And longterm plan to combine those with http://forum.kodi.tv/showthread.php?tid=224794
Reply
#15
That looks interesting but its months away, if ever.
Reply

Logout Mark Read Team Forum Stats Members Help
Emby for Kodi / JSON-RPC / Alternate back end0