matthuisman / docker-kodi-headless

A headless install of kodi in a docker container
GNU General Public License v3.0
124 stars 11 forks source link

Does the client app have to perform library scans #48

Closed labmonkey closed 3 months ago

labmonkey commented 3 months ago

Hello, Not an issue but rather a question. I've set up everything and I suppose it works as it should. One thing I am not sure is the way the client apps work now. By client I mean the app on my Android TV and the server being kodi headless. I can see in the logs that the headless app is performing library scan and cleanup whenever something is changed and that is great. On the other hand I was hoping that since the client is pointing to the database then it will always display the up to date library content while the "heavy" stuff is will be done by the headless app. It kind of works that way but the client does not refresh the library locally until I perform library scan in the android tv app as well. It is very quick but still it has to be performed. I was wondering if I either forgot to setup something or does the android tv app keep some kind of cache and it has to be refreshed after every change in headless? I've managed to kind of work around this by setting the android tv app to perform library scan on startup and additionally running a script that triggers the scan in case I am already running kodi on TV (So I dont have to restart app to refresh) curl --data-binary '{ "jsonrpc": "2.0", "method": "VideoLibrary.Scan", "id": "kodi-script"}' -H 'content-type: application/json;' http://ANDROID-TV-IP/jsonrpc . TLDR I was wondering if I can configure this in a way that the library scans on android TV can be disabled whatsoever.

matthuisman commented 3 months ago

if the client is pointed to a shared DB that the headless uses - then it will automatically be upto date. Otherwise, im not sure how you think it would work?

I suspect they are not using the same database. My other clients never need to scan

There is nothing special about headless except its Kodi client without the GUI.

Kodi doesnt do a Server- > Client archietecture All kodis are client. This docker just lets you run a Kodi client on a server. This allows you to point it to a shared SQL database and do the scans etc. So when other clients that talk to the same DB will see the new content

labmonkey commented 3 months ago

Let me maybe give you an example of what I have to do in order to watch a movie. Let's assume I already have the movie file somewhere:

  1. I put that movie file in one of my kodi headless library directories
  2. As far as I know Kodi has no way to monitor in real time directories for changes so if I want headless to see the new movie instantly then I have to manually trigger library rescan on headless instance by the script I have mentioned.
  3. I can see in the logs that scan was performed and I can see in the MariaDB itself that the movie is in "movies" table.

At this point there are 2 scenarios: 4A. My TV/Android Kodi was turned off so I turn it on and as soon as the app loads the Movie is there and I can watch it. This works great and no issues here and I assume my configuration is correct. 4B. I've already opened Kodi on my TV and it was running with library on my screen at same time when step 2 was performed. Even that movie was added to the database I cannot see it on my screen - it does not suddenly update. In order to "refresh" it I have to either restart kodi, manually rescan the library or run the script that triggers the rescan that I've mentioned but this time pointing to my Androidtv IP (I can see immediately on screen in top right corner that it performs the scan).

So my question is if the step 4B is normal in your case as well or do you do this differently.

matthuisman commented 3 months ago

Oh - if your clients are already on the screen showing latest etc, then yes you'll see the content its already loaded.

Thats a kodi thing. It doesnt continually re-run the SQL queries as they can be quite slow.

You could have a client script to gui.refresh() or something so those "latest" lists get reloaded. This could be a good oppurtunty for a Kodi service add-on. It runs on the client and keeps calling api call to get latest movie. When it detects a new content, it gui.refreshes() or something

matthuisman commented 3 months ago

id personally make use of such an addon / service so I may look at writing one that i could chuck into my slyguy repos for others to use

niko2 commented 3 months ago

there is an auto update addon, but it runs at regular interval, which is not the best approach best solution is probably to trigger the scan (on all clients, the headless and the TV, sequentially) from your download app, or create an addon on the headless to trigger updates on other clients (since headless runs for another clients)

matthuisman commented 3 months ago

I think your responding to the issue of the headless not automatically scanning when it detects new content? For me, i have a script that renames content and moves it into the content folders. It then uses headless API to scan for new content.

As for the clients "refreshing" their latest movies etc: i used to have the server client tell the others to update once it was done. But that means you need to open up all the clients for api access etc. and then hard-code each IP / auto discovery into the headless etc etc. Simpler and easier for others to just install service on the clients I think. It can poll very quickly as its detection is literally "Get the latest movie. If movie != last_seen_movie: refresh gui"

matthuisman commented 3 months ago

ok. new service addon added to slyguy repo.

service.recently.added.refresh -> v0.0.1

Works pretty well actually :) Grabs the most recent movie/episode/album/song every 10s If its different to the previous one it fetched, it calls library update.

It pass lib update a directory that doesnt exist so it completes basically instantly. And also tells it not to show a dialog so its all in the background. Kodi refreshes the recently added widgets after a DB update so they still get triggered without having to do a "proper update"

matthuisman commented 3 months ago

please report back how it works for you. Ill wait a few days before doing a "release post" for it on my blog etc

labmonkey commented 3 months ago

Hello. You got me by surprise by making this addon. So I've tested it and I must admit it works great. I was following the logs of everything just to see it works properly and in order. I think its just important to mention that this completely handles the client kodi app but the headless kodi still needs to trigger the library scan. Personally I am still triggering it with a script and kodi API. So my current workflow is following:

  1. Movie is file is added to library directory
  2. My script triggers the library scan and I see confirmation in headless
    2024-03-04 14:57:41.648 T:500      info <general>: VideoInfoScanner: Starting scan ..
    2024-03-04 14:57:41.924 T:500      info <general>: CleanDatabase: Starting videodatabase cleanup ..
    2024-03-04 14:57:41.966 T:500      info <general>: CleanDatabase: Cleaning videodatabase done. Operation took 41 ms
    2024-03-04 14:57:41.966 T:500      info <general>: VideoInfoScanner: Finished scan. Scanning for video info took 324 ms
  3. Whatever I am doing on my TV the kodi will refresh GUI in max 10 seconds (configurable)

And that's it actually. Fully automated setup.

One issue I had was when movie was deleted but it turned out my script somehow was triggering rescan and it still not worked. After debugging I managed to trigger it and then even when movie is deleted the gui is updated properly.

Nothing much else to add. I just do 3 steps mentioned above and it works.

matthuisman commented 3 months ago

Yes, still need to trigger scan. Which I think is ok as scans can take long. As I said, I use a script to rename downloads, move them and then kick off a scan.

You could install the library updater service on headless. That'll just periodically run a scan. But I prefer manually running so it's immediate.

Other way would be have a service watching your folders for changes that then kicks off a scan.

Glad my new client script works. I'm using it myself too and now wondering why never did it earlier

Enjoy!