•
• 1
• 153
• 154
• 155(current)
• 156
• 157
• 177
•
[RELEASE] Texture Cache Maintenance utility
I use texturecache for maintaining my kodi db (MySQL) and keep up with what is really on my storage. I use Sonarr and I have 1 MySQL server with the Kodi database with 2 PI's running Kodi

This is what I use for Texturecache, but I wonder if I am missing something (2 weeks ago I made some adjustments as I saw that some removed shows where still present in the DB of Kodi
I have two locations (NFS) for movies and 1 location for all TV shows (NFS)

#!/bin/bash

NAME=texturecache
INIT_DIR=/etc/init.d
echo "Start Scanning Video Library vscan"
/home/kodi/texturecache.py vscan
sleep 5
echo "Start Cleaning Video Library vclean"
/home/kodi/texturecache.py vclean
sleep 5
echo "Start scanning texturecache with function C"
/home/kodi/texturecache.py c
sleep 5
echo "Prune data missing on disk P"
/home/kodi/texturecache.py P
sleep 5
echo "Start update with qax"
/home/kodi/texturecache.py qax
sleep 3
echo "Start update with Xd"
/home/kodi/texturecache.py Xd
sleep 3
echo "Start update with ./texturecache.py R"
/home/kodi/texturecache.py R
sleep 3
echo "end"
Updating the cache on the scanning client is of limited value, you really want to update the caches of your non-scanning clients.

I'd also suggest running qax before the cache © step, since qax may cause an item to be refreshed (removed and reloaded), potentially scraping a new image.

If the shows you think you removed are still in the library, then they weren't removed.
Texture Cache Maintenance Utility: Preload your texture cache for optimal UI performance. Remotely manage media libraries. Purge unused artwork to free up space. Find missing media. Configurable QA check to highlight metadata issues. Aid in diagnosis of library and cache related problems.
(2017-09-20, 18:43)Bmn2016 Wrote: Hi,

I've found out that when using the script with the "R" option, my "Bookmarks" I've created (which are set when you use the "create bookmark" function while a video is playing and stored in "...userdata/thumbnails/video/bookmarks") are always removed!!!

That's not surprising, as the "Bookmarks" are stored in the bookmark table of the "MyVideos*" database, and not in the "Textures13.db" file which the script is investigating when using the "R" option.

So here are my suggestions for modifying the "R" option behaviour:

1. Ignore the "Bookmark" files that are stored in "...userdata/thumbnails/video/bookmarks" to prevent being deleted because of a lacking reference in the "Textures13.db" file
- or -
2. Find and delete only the "orphaned" "Bookmark" files that are stored in "...userdata/thumbnails/video/bookmarks" which have no reference in the "MyVideos*" database

(2017-09-20, 19:13)Milhouse Wrote: Yeah... I think I'll just ignore the contents of the Bookmarks folder for now. I'll make the change when I can.

@Milhouse:

Maybe I got another idea for a "work-around":

I'm using a MySQL database on a NAS. Is it possible to "move" the usage of the folder "bookmarks" to my NAS via path substitution? (I don't intend to "move" the whole "Thumbnail" folder, as I know that could cause many problems; I'm thinking only about "moving" the "Bookmarks" subfolder in "...userdata/thumbnails/video/")

1. Would your script delete them from the shared folder on the NAS, too, when using the "R" option?

2. Besides that, I'm hoping that would at least bring the benefit of sharing the images linked with the created bookmarks... I find it very annoying that when I use the "create bookmark" function on a KODI machine, the image of the bookmark is only visible on that machine, but not on my other KODI devices (of course I can see the time stamps of the "Bookmarks" on the other devices, too, but not the linked images, because they only exist on the first machine).

What do you think?
I'm not really sure. Path substitution of thumbnails isn't something I would recommend, but as these bookmarks are not true thumbnails (in the sense of being cached with references in Textures13.db etc.) then maybe it will be OK to use a path sub but just for the Bookmarks folder. If you relocate the Bookmarks folder outside of the Thumbnails folder then I don't think the script will try to delete it.
Texture Cache Maintenance Utility: Preload your texture cache for optimal UI performance. Remotely manage media libraries. Purge unused artwork to free up space. Find missing media. Configurable QA check to highlight metadata issues. Aid in diagnosis of library and cache related problems.
@Milhouse: Thanks for your feedback: I just "moved" the "Bookmarks" folder to my NAS via "path substitution"; I can confirm now that there it is untouched when using the "R" option, and by this way I now can actually see the linked images on all my KODI machines. So: Success at all ends! :-)
I just stumbled about an issue regarding thumbnails for videos created in "file
view mode":

When browsing a video in "file view mode", KODI creates a thumbnail image and
caches it. As this isn't ideal in all cases, you can build an image file with
the same name and the special extension ".tbn", place it in the folder together
with the video, and achieve by this way that from now on this will "override"
KODIs mechanism of creating a thumbnail for this particular video by itself
(anyone interested see here for example:
https://www.xbmc4xbox.org.uk/wiki/Thumbnails ) I played around with this option
use the "s" option followed by the "d" option of the script to detect and delete
the rows in the texture database in order to "refresh" the custom thumbnail of
the video - all went fine.

But at the end, for some videos I decided to revert to the "original" mechanism
and let KODI do the work: I deleted the .tbn-files and thought that would be
enough... but no - KODI does not create the thumbnails by itself anymore!
Instead it displays a "default icon of a movie"! I tried all kind of things:
used the script with the "d", "P", "R", "Xd" and/or "C" options; removed the video
file by KODIs context menu and copied it back afterwards to the previous storage
location, but nothing helped - for testing purposes, I copied the .tbn-files
again in the video folder, and immediately the "default icon of a movie" was
replaced with it!

So there must be an entry anywhere in the textures13.db file that somehow
"survives" all these methods! Other "untouched" KODI machines which are also
connected to the MySQL-database had no issues with this, so I guess the problem
can't be related to the MyVideo.db file.

In the end, the only solution that helped was deleting the textures13.db file
and the thumbnail folder manually, and then let KODI rebuild the cache again,
which took a while... very annoying!

This strange behaviour is reproducable, and I would like to find out how I can use the script to solve the problem at first hand - has anyone a clue?
(2017-10-07, 13:27)Bmn2016 Wrote: As this isn't ideal in all cases, you can build an image file with
the same name and the special extension ".tbn", place it in the folder together
with the video, and achieve by this way that from now on this will "override"
KODIs mechanism of creating a thumbnail for this particular video by itself
<file-name>-thumb.jpg also works.

tbn is the old image extension which is pretty unfortunate as pretty much nothing other than Kodi understands it, and having to give a jpg a tbn extension then makes it more difficult to preview in the OS or image apps.

(2017-10-07, 13:27)Bmn2016 Wrote: So there must be an entry anywhere in the textures13.db file that somehow
"survives" all these methods! Other "untouched" KODI machines which are also
connected to the MySQL-database had no issues with this, so I guess the problem
can't be related to the MyVideo.db file.

There isn't.

The "thumbnail extraction from video" process is a separate process to normal library image scraping and caching, and happens only when BOTH of the following settings are enabled (tested with latest Kodi 18a1):

Settings > Media > Videos > Extract video information from files
Settings > Media > Videos > Extract thumbnails from video files

If either setting is disabled then no thumbnail extraction will take place.

IMHO "Extract video information from files" should not need to be enabled in order to extract thumbnails, and would therefore appear to be a Kodi bug. If you feel strongly about it, open a ticket on trac.kodi.tv.

(2017-10-07, 13:27)Bmn2016 Wrote: This strange behaviour is reproducable, and I would like to find out how I can use the script to solve the problem at first hand - has anyone a clue?

Enable both "Extract" settings.
Texture Cache Maintenance Utility: Preload your texture cache for optimal UI performance. Remotely manage media libraries. Purge unused artwork to free up space. Find missing media. Configurable QA check to highlight metadata issues. Aid in diagnosis of library and cache related problems.
@Milhouse: Thanks for the clarification!
(2016-02-02, 16:10)Milhouse Wrote:
(2016-02-02, 13:14)lstar337 Wrote: I gave it a go, but I get an addon error. Looking in the log it says this:

Ah right, you don't want to execute this script in the context of the Kodi process.

Here's a fix... http://sprunge.us/eLXN

Put this alongside the texturecache.py script, call it shell.py and give it execute permissions - on Linux:
Code:
wget http://sprunge.us/eLXN -O ~/.kodi/userdata/shell.py && chmod +x ~/.kodi/userdata/shell.py

Now your Runscript() call needs to be (note this assumes the texturecache.py script is alongside the shell.py script, otherwise specify the full path to texturecache.py - don't use special://whatever):
Code:
RunScript(special://profile/shell.py,./texturecache.py,c)

For instance to map this to a remote control button:
Code:
<red>XBMC.RunScript(special://profile/shell.py,./texturecache.py,c)</red>

As a bonus you'll get notifications on start and finish, and you won't be able to run multiple instances (which wouldn't be good).

@milhouse:

While the solution via the shell.py script is working fine on my KODI Krypton v17.4 installations under LibreELEC on my Raspberry Pi and ANDROID box, I can't get it to work on my PC using KODI for windows...

First problem:
As there are no "/var/run/" directories on the KODI installation on my PC running Windows 7, I replaced the line from
pidfile = "/var/run/shellpy.pid"
to
pidfile = "C:\Users\Stefan\AppData\Roaming\KODI\userdata\shellpy.pid"

-> problem solved

Second problem:
Trying to run the script shell.py throws the following excepton in the KODI log:
05:43:21.729 T:2148   ERROR: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--
- NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
Error Type: <type 'exceptions.WindowsError'>
Error Contents: [Error 2] Das System kann die angegebene Datei nicht finden
Traceback (most recent call last):
File "C:\Users\Stefan\AppData\Roaming\Kodi\userdata\shell.py", line 31, in <module>
shellnotify(sys.argv[1:])
File "C:\Users\Stefan\AppData\Roaming\Kodi\userdata\shell.py", line 24, in shellnotify
notify("Starting...", " ".join(args))
File "C:\Users\Stefan\AppData\Roaming\Kodi\userdata\shell.py", line 11, in notify
File "C:\Users\Stefan\AppData\Roaming\Kodi\userdata\shell.py", line 7, in shellcmd
process = subprocess.Popen(args, stderr=open(os.devnull, 'w'))
File "C:\Program Files (x86)\Kodi\system\python\Lib\subprocess.py", line 390, in __init__
File "C:\Program Files (x86)\Kodi\system\python\Lib\subprocess.py", line 640, in _execute_child
startupinfo)
WindowsError: [Error 2] Das System kann die angegebene Datei nicht finden
-->End of Python script error

I assume that the "WindowsError: [Error 2] Das System kann die angegebene Datei nicht finden" (translated to english: "The system can't find the specified file") is caused by the missing "kodi-send" command under Windows, right?
I was not able to find an alternative command line tool for windows, but maybe I didn't use the appropriate search terms, since I'm a noob regarding python programming...

So - how could I get a "work-around" for this problem?
(2017-10-15, 06:25)Mr.Floppy Wrote: I assume that the "WindowsError: [Error 2] Das System kann die angegebene Datei nicht finden" (translated to english: "The system can't find the specified file") is caused by the missing "kodi-send" command under Windows, right?

Yep.

(2017-10-15, 06:25)Mr.Floppy Wrote: I was not able to find an alternative command line tool for windows, but maybe I didn't use the appropriate search terms, since I'm a noob regarding python programming...

You can try using texturecache.py - replace:
Code:
shellcmd(["kodi-send", "--action", "Notification(%s,%s)" % (header, text)])
with:
Code:
shellcmd(["X:\path\to\texturecache.py", "send", header, text])

but if that doesn't work then just remove the "notify()" calls.
Texture Cache Maintenance Utility: Preload your texture cache for optimal UI performance. Remotely manage media libraries. Purge unused artwork to free up space. Find missing media. Configurable QA check to highlight metadata issues. Aid in diagnosis of library and cache related problems.
@Milhouse:

After having removed all "notify()" calls, the shell.py script now looks as following:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os, sys, subprocess

def shellcmd(args):
process = subprocess.Popen(args, stderr=open(os.devnull, 'w'))
output = process.communicate()[0]

def shellnotify(args):
pidfile = "C:\Users\Stefan\AppData\Roaming\KODI\userdata\shellpy.pid"
if os.path.isfile(pidfile):
sys.exit(1)
file(pidfile, 'w').write(" ".join(args))

try:
os.chdir(os.path.dirname(os.path.realpath(__file__)))
shellcmd(args)
finally:

shellnotify(sys.argv[1:])

I've changed the keymap entry to:
Code:
<red>XBMC.RunScript(special://profile/shell.py,./texturecache.py,c)</red>

When trying to run the script from my remote control red button, I'm getting the following exception:

16:54:49.250 T:6956   ERROR: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--
- NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
Error Type: <type 'exceptions.WindowsError'>
Error Contents: [Error 193] %1 ist keine zulässige Win32-Anwendung
Traceback (most recent call last):
File "C:\Users\Stefan\AppData\Roaming\Kodi\userdata\shell.py", line 31, in <module>
shellnotify(sys.argv[1:])
File "C:\Users\Stefan\AppData\Roaming\Kodi\userdata\shell.py", line 25, in shellnotify
shellcmd(args)
File "C:\Users\Stefan\AppData\Roaming\Kodi\userdata\shell.py", line 7, in shellcmd
process = subprocess.Popen(args, stderr=open(os.devnull, 'w'))
File "C:\Program Files (x86)\Kodi\system\python\Lib\subprocess.py", line 390, in __init__
File "C:\Program Files (x86)\Kodi\system\python\Lib\subprocess.py", line 640, in _execute_child
startupinfo)
WindowsError: [Error 193] %1 ist keine zulässige Win32-Anwendung
-->End of Python script error report<--

"WindowsError 193: [Error 193} %1 ist keine zulässige Win32 Anwendung" translated to english means something like "%1 is not a valid Win32 application".

Any idea how to solve this?
(2017-10-15, 17:33)Mr.Floppy Wrote: Any idea how to solve this?

Not really - I don't understand German, and this is may need someone more familiar with Windows to come up with a solution. Your problem is, however, just a standard add-on issue rather than anything specific to texturecache.py so you may have more luck posting in the Add-on Support sub-forum.
Texture Cache Maintenance Utility: Preload your texture cache for optimal UI performance. Remotely manage media libraries. Purge unused artwork to free up space. Find missing media. Configurable QA check to highlight metadata issues. Aid in diagnosis of library and cache related problems.
(2017-10-07, 13:27)Bmn2016 Wrote: I just stumbled about an issue regarding thumbnails for videos created in "file
view mode":

When browsing a video in "file view mode", KODI creates a thumbnail image and
caches it. As this isn't ideal in all cases, you can build an image file with
the same name and the special extension ".tbn", place it in the folder together
with the video, and achieve by this way that from now on this will "override"
KODIs mechanism of creating a thumbnail for this particular video by itself
(anyone interested see here for example:
https://www.xbmc4xbox.org.uk/wiki/Thumbnails ) I played around with this option
use the "s" option followed by the "d" option of the script to detect and delete
the rows in the texture database in order to "refresh" the custom thumbnail of
the video - all went fine.

But at the end, for some videos I decided to revert to the "original" mechanism
and let KODI do the work: I deleted the .tbn-files and thought that would be
enough... but no - KODI does not create the thumbnails by itself anymore!
Instead it displays a "default icon of a movie"! I tried all kind of things:
used the script with the "d", "P", "R", "Xd" and/or "C" options; removed the video
file by KODIs context menu and copied it back afterwards to the previous storage
location, but nothing helped - for testing purposes, I copied the .tbn-files
again in the video folder, and immediately the "default icon of a movie" was
replaced with it!

So there must be an entry anywhere in the textures13.db file that somehow
"survives" all these methods! Other "untouched" KODI machines which are also
connected to the MySQL-database had no issues with this, so I guess the problem
can't be related to the MyVideo.db file.

In the end, the only solution that helped was deleting the textures13.db file
and the thumbnail folder manually, and then let KODI rebuild the cache again,
which took a while... very annoying!

This strange behaviour is reproducable, and I would like to find out how I can use the script to solve the problem at first hand - has anyone a clue?
I have noticed same behaviour but for me it seems to be for 50/50 of the media. Some media caching does work and for some don't.
(2017-10-07, 17:23)Milhouse Wrote:
(2017-10-07, 13:27)Bmn2016 Wrote: As this isn't ideal in all cases, you can build an image file with
the same name and the special extension ".tbn", place it in the folder together
with the video, and achieve by this way that from now on this will "override"
KODIs mechanism of creating a thumbnail for this particular video by itself
<file-name>-thumb.jpg also works.

tbn is the old image extension which is pretty unfortunate as pretty much nothing other than Kodi understands it, and having to give a jpg a tbn extension then makes it more difficult to preview in the OS or image apps.

(2017-10-07, 13:27)Bmn2016 Wrote: So there must be an entry anywhere in the textures13.db file that somehow
"survives" all these methods! Other "untouched" KODI machines which are also
connected to the MySQL-database had no issues with this, so I guess the problem
can't be related to the MyVideo.db file.

There isn't.

The "thumbnail extraction from video" process is a separate process to normal library image scraping and caching, and happens only when BOTH of the following settings are enabled (tested with latest Kodi 18a1):

Settings > Media > Videos > Extract video information from files
Settings > Media > Videos > Extract thumbnails from video files

If either setting is disabled then no thumbnail extraction will take place.

IMHO "Extract video information from files" should not need to be enabled in order to extract thumbnails, and would therefore appear to be a Kodi bug. If you feel strongly about it, open a ticket on trac.kodi.tv.

(2017-10-07, 13:27)Bmn2016 Wrote: This strange behaviour is reproducable, and I would like to find out how I can use the script to solve the problem at first hand - has anyone a clue?

Enable both "Extract" settings.
Liike schumi2004 (see previous posting) I've noticed the same behavior, too. Even when both settings "Media > Videos > Extract video information from files" and "Media > Videos > Extract thumbnails from video files" are enabled, KODI (tested with Krypton v17.4) won't create a thumbnail for a video by itself anymore afterwards there has been a <file-name>-thumb.jpg in the past which is now deleted.
(2017-10-15, 06:25)Mr.Floppy Wrote:
(2016-02-02, 16:10)Milhouse Wrote:
(2016-02-02, 13:14)lstar337 Wrote: I gave it a go, but I get an addon error. Looking in the log it says this:

Ah right, you don't want to execute this script in the context of the Kodi process.

Here's a fix... http://sprunge.us/eLXN

Put this alongside the texturecache.py script, call it shell.py and give it execute permissions - on Linux:
Code:
wget http://sprunge.us/eLXN -O ~/.kodi/userdata/shell.py && chmod +x ~/.kodi/userdata/shell.py

Now your Runscript() call needs to be (note this assumes the texturecache.py script is alongside the shell.py script, otherwise specify the full path to texturecache.py - don't use special://whatever):
Code:
RunScript(special://profile/shell.py,./texturecache.py,c)

For instance to map this to a remote control button:
Code:
<red>XBMC.RunScript(special://profile/shell.py,./texturecache.py,c)</red>

As a bonus you'll get notifications on start and finish, and you won't be able to run multiple instances (which wouldn't be good).

@milhouse:

While the solution via the shell.py script is working fine on my KODI Krypton v17.4 installations under LibreELEC on my Raspberry Pi and ANDROID box, I can't get it to work on my PC using KODI for windows...

First problem:
As there are no "/var/run/" directories on the KODI installation on my PC running Windows 7, I replaced the line from
pidfile = "/var/run/shellpy.pid"
to
pidfile = "C:\Users\Stefan\AppData\Roaming\KODI\userdata\shellpy.pid"

-> problem solved

Second problem:
Trying to run the script shell.py throws the following excepton in the KODI log:
05:43:21.729 T:2148   ERROR: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--
- NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
Error Type: <type 'exceptions.WindowsError'>
Error Contents: [Error 2] Das System kann die angegebene Datei nicht finden
Traceback (most recent call last):
File "C:\Users\Stefan\AppData\Roaming\Kodi\userdata\shell.py", line 31, in <module>
shellnotify(sys.argv[1:])
File "C:\Users\Stefan\AppData\Roaming\Kodi\userdata\shell.py", line 24, in shellnotify
notify("Starting...", " ".join(args))
File "C:\Users\Stefan\AppData\Roaming\Kodi\userdata\shell.py", line 11, in notify
File "C:\Users\Stefan\AppData\Roaming\Kodi\userdata\shell.py", line 7, in shellcmd
process = subprocess.Popen(args, stderr=open(os.devnull, 'w'))
File "C:\Program Files (x86)\Kodi\system\python\Lib\subprocess.py", line 390, in __init__
File "C:\Program Files (x86)\Kodi\system\python\Lib\subprocess.py", line 640, in _execute_child
startupinfo)
WindowsError: [Error 2] Das System kann die angegebene Datei nicht finden
-->End of Python script error

I assume that the "WindowsError: [Error 2] Das System kann die angegebene Datei nicht finden" (translated to english: "The system can't find the specified file") is caused by the missing "kodi-send" command under Windows, right?
I was not able to find an alternative command line tool for windows, but maybe I didn't use the appropriate search terms, since I'm a noob regarding python programming...

So - how could I get a "work-around" for this problem?

Okay - after having dealt with Python and shell scripting under Windows for quite some time now, I finally found a way to modify the shell.py script so that it works now under this OS, too.

There are some important points to remember:
a) Since Windows (other than Linux) has no built-in Python interpreter and bash shell, you have to install them separately.
b) To avoid any problems with KODI, you have to install "Python 2.x" - "Python 3.x" won't work!
c) The paths to the executable files must be added to the environment variable PATH in Windows.

But don't afraid - this is not complicated at all if you follow my advices:
1. Download and install a "Python 2.x" version from the website under https://www.python.org/downloads/windows/ ; make sure that you enable "Add python.exe to path" in the process of installation!
2. Download and install "Git for windows" (which provides a BASH emulation) from the website under https://git-for-windows.github.io/ ; make sure that you enable "Use Git and optional Unix tools from the Windows Command Prompt" in the process of installation!

And here's the modified shell.py script:
Code:
!/usr/bin/env python # -*- coding: utf-8 -*- import os, subprocess, sys, xbmc def shellcmd(args):   if sys.argv[1].endswith(".py"):     command = "python " + " ".join(args)   elif sys.argv[1].endswith(".sh"):     command = "sh " + " ".join(args)   subprocess.call(command, shell=True) def notify(header, text):   xbmc.executebuiltin('notification(%s, %s)' % (header, text)) def shellnotify(args):   os.chdir(os.path.dirname(os.path.realpath(__file__)))   pidfile = "shellpy.pid"   if os.path.isfile(pidfile):    notify("Already running!", file(pidfile, 'r').read())    sys.exit(1)   file(pidfile, 'w').write(" ".join(args))   try:     notify("Starting...", " ".join(args))     shellcmd(args)     notify("Finished", " ".join(args))   finally:     os.unlink(pidfile) shellnotify(sys.argv[1:])

The beauty of this solution is that it will work not only with the Runscript() call of "./texturecache.py", but also with any other shell script; for an example see here: https://forum.kodi.tv/showthread.php?tid...pid2233173

Have fun with it :-)
•
• 1
• 153
• 154
• 155(current)
• 156
• 157
• 177
•