Fix kodi slow clean library

Published on Author Artem ButusovLeave a comment

Kodi is trying to check each file even if it is located on network nfs/smb share and is no more available. Network connect with timeout is very slow, so attempt to clean kodi audio/video library with dead nfs/smb resources thru UI will cause application freeze.

To fix this issue you could temporarily rename all smb:// and nfs:// paths to be local so kodi will be able to faster check that file is not available anymore without trying to establish network connection.

Kodi database has sqlite3 format.

In example below kodi database is located in /storage/.kodi/userdata/Database (LibreELEC).

cd /storage/.kodi/userdata/Database

# this script will show what database files have nfs/smb paths in their dump
for file in $(ls *.db); do
  echo "DB: $file"
  sqlite3 "$file" .dump \
    | grep '\(nfs\|smb\)://' \
    | grep 'INSERT INTO [^ ]*' -o \
    | uniq \
    | cut -d ' ' -f 3
done

I would strongly recommend to backup all database files before modifying them.

Example how MyVideos107.db could be fixed:

sqlite3 MyVideos107.db

update movie set c22 = replace(c22, 'nfs://', '/media/') where c22 like 'nfs://%';
update movie set c22 = replace(c22, 'smb://', '/media/') where c22 like 'smb://%';
update episode set c18 = replace(c18, 'nfs://', '/media/') where c18 like 'nfs://%';
update episode set c18 = replace(c18, 'smb://', '/media/') where c18 like 'smb://%';
update path set strPath = replace(strPath, 'nfs://', '/media/') where strPath like 'nfs://%';
update path set strPath = replace(strPath, 'smb://', '/media/') where strPath like 'smb://%';

Example how MyMusic60.db could be fixed:

sqlite3 MyMusic60.db

update path set strPath = replace(strPath, 'nfs://', '/media/') where strPath like 'nfs://%';
update path set strPath = replace(strPath, 'smb://', '/media/') where strPath like 'smb://%';
update art set url = replace(url, 'nfs://', '/media/') where url like 'nfs://%';
update art set url = replace(url, 'smb://', '/media/') where url like 'smb://%';

Once you will fix database you could invoke “clean library” from kodi settings and reboot kodi.

Please note, this solution could also be used to relocate your files from one resource to another one.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.