Clear all the image cache then reload it

I have two Raspberry Pis and want to do the following…

  1. Clear ALL the image cache from both Pis (for tv shows and movies).
  2. Scan all the media in my current library and pre cache the artwork, and posters.

On my two Pis (wireless) I hover over a movie title and it takes about 5-7 seconds to load the image for the poster. On my Kodi Windows 10 boxes (hardwired) I do not see this time to load the images. I hope to clear up old cache, and preload all the images so when I look at it on my OSMC Pis the images are there already and I don’t have to wait for each to cache.

Fastest way to clear the cache is:

systemctl stop mediacenter
rm -fr /home/osmc/.kodi/userdata/Thumbnails/*
rm /home/osmc/.kodi/userdata/Database/Textures13.db
systemctl start mediacenter

Next, enable the Kodi webserver (Settings->Services->Remote Control). Pick a username and password.

Then, install the texture cache maintenance utility. The default settings will likely work, although you will have to set a username and password from what you set in Kodi.

Then, run the following:

texturecache.py c movies
texturecache.py c sets
texturecache.py c tvshows

I have been trying to use the texturecache.py script with little consistency/success.

For example…

osmc@OSMCBR:~/.kodi/scripts$ ./texturecache.py s "22 Jump Street"
Matching row ids:
osmc@OSMCBR:~/.kodi/scripts$ ./texturecache.py C movies "22 Jump Street"

Caching artwork: 0 items remaining of 2 (qs: 0, qm: 0), 1 error, 0 threads active (01.00 downloads per second, ETA: 00:00:00)

The following items could not be downloaded:

[fanart    ] [22 Jump Street                          ] smb://mydomain.local/media/movies/22 Jump Street (2014)/fanart.jpg

Cache pre-load activity summary for "movies", filtered by "22 Jump Street":

              |    fanart   |    poster   |    TOTAL
--------------+-------------+-------------+-------------
Cached        |      -      |      1      |      1
Deleted       |      -      |      1      |      1
Duplicate     |      -      |      -      |      0
Error         |      1      |      -      |      1
Ignored       |      -      |      -      |      0
Skipped       |      -      |      -      |      0
Undefined     |      -      |      -      |      0
========================================================
TOTAL         |      1      |      2      |      3
Download Time | 00:00:21.53 | 00:00:02.02 | 00:00:21.53

  Threads Used: 2
   Min/Avg/Max: 01.00 / 00.09 / 01.00 downloads per second
   Min/Avg/Max: 02.03 / 11.78 / 21.53 seconds per download

       Loading: 00:00:00.40
       Parsing: 00:00:00.00
     Comparing: 00:00:00.17
   Downloading: 00:00:21.57
 TOTAL RUNTIME: 00:00:22.15
osmc@OSMCBR:~/.kodi/scripts$ ./texturecache.py s "22 Jump Street"
Matching row ids:
osmc@OSMCBR:~/.kodi/scripts$

Maybe I’m not using it correctly but I was trying to (just for this title)…

  1. Find all the images for it, (found none).
  2. Cache/delete all images for the title (could not cache the fanart, had an error…).
  3. Find all the images for it, (found none).

Yet when I use JSON…

osmc@OSMCBR:~/.kodi/scripts$ ./texturecache.py j movies "22 Jump Street"
[
  {
    "art": {
      "fanart": "image://smb%3a%2f%2fmydomain.local%2fmedia%2fmovies%2f22%20Jump%20Street%20(2014)%2ffanart.jpg/",
      "poster": "image://http%3a%2f%2fimage.tmdb.org%2ft%2fp%2foriginal%2ftPnw9oqIvIMoYjVozkDkxm3xR8r.jpg/"
    },
    "file": "smb://ms/movies/22 Jump Street (2014)/22 Jump Street (2014).mp4",
    "label": "22 Jump Street",
    "movieid": 135,
    "title": "22 Jump Street"
  }
]

I end up seeing there that somewhere in the DB is an image stored local and one on the internet. My goal is to try and clean up all the image cache in the database itself (not just on this osmc client). I want to clean up the shared media DB. As you can also see from above there is a mydomain.local path. I need to get rid of all image/media paths that do NOT start with smb://ms/ (for movies and tv). I need to really convert them all to smb://ms/.

It almost seems like my best solution is to just use good ol SQL to make this happen. I just can’t get the texturecache.py script to perform with any consistency.

The problem is that the main database also has references to mydomain.local.

You could try to play around and fix it using SQL if you are comfortable with it.

There are 2 taxturecache.py options that may help:

 purge      Remove cached artwork with URLs containing specified patterns, with or without hash
 purgetest  Dry-run version of purge

or:

qa         Run QA check on movies, tags and tvshows, identifying media with missing artwork or plots
qax        Same as qa, but remove and rescan those media items with missing details.

I’ve never used either of those, so be careful.

The “qa” option is completely safe, as it is informative only…no changes are made.

And, @armega, what @bmillham said was right…you need to get rid of that information in the Kodi database. If the path is correct except for “mydomain.local/media” needs to change to “ms”, and since you have more than one Pi, that means you must be using MySQL. That makes it pretty easy, once you log into the MySQL server:

USE kodivideo107;
UPDATE art SET url = REPLACE(url, 'smb://mydomain.local/media', 'smb://ms');

I do this kind of thing all the time…you can’t really mess it up too bad, since it’s already broken. :slight_smile:

Are you sure it’s just in art? I see entries in my database in movies that also point to images. I didn’t check TV.

That’s all old data. If you do a complete new scrape, nothing should end up there, if you use local artwork. It might still get populated if you don’t have art files on disk, and instead go straight from the Internet to cache.

I just re-scraped everything, and all the art fields (c08: poster, c20: fanart, c17: Thumbnail URL Spoof) are empty in every record.

So you are saying that the fields in the movie table are no longer used and that the art table is what’s currently used?

I get all artwork just fine with only the art table populated, so that appears to the be case.

And, adding/changing/deleting an entry from the art table shows immediate results in Kodi, even if the file from the previous entry still exists on disk.

Yea that’s what I was thinking… I try my best to stay out of databases themselves if I can avoid it for many reasons. I’m very familiar with SQL in general but not the Kodi database specifically (linking etc). Before I went to the extreme of taking things into my own hands I wanted to see if someone that very familiar with the Kodi DB had some type of solution that I could use to do this automatically.

Thanks!

So to be clear… texturecache.py is only working with the local Kodi cache correct? It does not make changes to the shared Kodi database?

If I have bad urls (paths and files that no longer exist on my network) that I need to get rid of in the art table, can I just delete those rows in mysql? Or is there something more I would need to worry about?

Mostly. For the options that mess with the cache, It only modifies Textures13.db and files in the “Thumbnails” directory tree. But, options like vscan and vclean tell Kodi to do things that can modify the shared database. But, most of the options that do modify the shared database are just a command-line that triggers Kodi to do things that you can do manually, so although they can be destructive, they aren’t any more destructive than you can be in the Kodi GUI. The exception is set, which essentially does direct SQL modifications to the “art” table.

Sure. Deleting from the “art” table is just deleting a link from a video to a type of art for that video. A mistake has no ill effect other than Kodi not being able to show the artwork.

But, if you they are mostly correct, using the REPLACE SQL function is the better way to go.

And if you want the easiest way to manipulate MySQL, get Heidi SQL.

Thanks @nabsltd I have been cleaning up my DB like crazy manually and recaching everything with the python script. I did replace a lot of things in the DB. There were some urls that were to things that no longer existed etc that I wanted to cleanup and delete though (just a few).

I have Heidi but tend to gravitate towards MySQL Workbench. I spend most of my days in MS SQL’s GUI so it gives me a somewhat familiar interface in some regards.

Thanks again for all the help guys!

I would like to schedule the deletion of the database file Textures13.db using an anacron weekly task, but without restarting mediacenter or even the entire pi, which would be kind of uncontrolled out of a scheduled task.

I have noticed that deleting the file without restarting/rebooting works. Now are there any negative consequences of not restarting afterwards? Is it OK to do so, or is there a better way for deleting Textures13.db using a schedule?

Why would you need to delete the cache db every week? If you have a space constraint you would probably be better off just relocating the thumbnails folder. If the issue is something else the better solution would probably be to use the Texture Cache Maintenance utility to perform maintenance instead of dumping it.

2 Likes

Thanks darwindesign.
I don’t have a space issue, it’s rather that I want to make sure that in the long run the performance doesn’t drop too much.
While saying this, you are right that it should be enough to purge that cache once a month.

Anyway, meanwhile I found an external solution. Since it is a wizard I don’t want to name it here because it would violate the forum rules.
It can be scheduled to clear the Kodi cache, delete temporary files and remove cached images like posters and thumbnails.

I didn’t even find out whether it also cleans the Textures13.db but well, that can also be done manually from time to time.

You are reducing your performance by doing this, not the other way around. Neither Kodi or your SD starts running slower because you have extra thumbnails sitting there. However every time you delete them they all get recreated the first time they are accessed so what you do is add small delays all over your library until everything is cached again. If you really want to make sure you are running as lean as possible then the only way to do this in a sane manner would be to purge only the cached images that are no longer being referenced which currently means you use the Texture Cache Maintenance utility because AFAIK it is the only app with this function.