(2020-03-09, 17:22)jmgibson1981 Wrote: website
Hmm... An article posted on 20. 11. 2015. The Kodi database has seen a couple of changes since then.
That article is only mentioning the "files" table from which entries are removed. The Kodi database holds a few more database tables than that.
I'll be the first to admit that Kodi's "garbage collection" could do with an upgrade, but nothing of the data that is left behind now is a "problem" in terms of overall usage.
(2020-03-09, 17:22)jmgibson1981 Wrote: I'm posting here to get other's opinions as I know virtually nothing about sql syntax or what the above does.
I would suggest if you have no clue of what SQL is or can do, you better leave the databases as they are. They are quite small compared to the media collections that most Kodi users have, so nothing will get in the way.
If you want to do a rigorous database cleaning, you can do the following:
- Enable the watched state and resume points for export in the advancedsettings.xml file and restart Kodi.
- Do a full Video Library Export (preferably with separate nfo files), and exit Kodi.
- Rename/remove the MyVideos116.db SQLite file or the MySQL/MariaDB MyVideos116 database table.
- Restart Kodi, reinstate/confirm your video source(s), and scrape your media collection.
- You should have a cleansed video library without any phantom entries.
As an example, I'll show you which queries IMO should be done when removing a movie or a tv show.
When removing a movie:
php:
'DELETE FROM actor_link WHERE media_type="movie" AND media_id='.$idFile;
'DELETE FROM actor_link WHERE media_type="movie" AND media_id='.$idFile;
'DELETE FROM country_link WHERE media_type="movie" AND media_id='.$idMovie;
'DELETE FROM director_link WHERE media_type="movie" AND media_id='.$idMovie;
'DELETE FROM writer_link WHERE media_type="movie" AND media_id='.$idMovie;
'DELETE FROM uniqueid WHERE media_type="movie" AND media_id='.$idMovie;
'DELETE FROM studio_link WHERE media_type="movie" AND media_id='.$idMovie;
'DELETE FROM rating WHERE media_type="movie" AND media_id='.$idMovie;
'DELETE FROM genre_link WHERE media_type="movie" AND media_id='.$idMovie;
'DELETE FROM art WHERE media_type IN ("movie", "episode") AND media_id='.$idMovie;
'DELETE FROM streamdetails WHERE idFile IN ( SELECT idFile FROM movie WHERE idMovie='.$idMovie.')';
'DELETE FROM bookmark WHERE idFile IN ( SELECT idFile FROM movie WHERE idMovie='.$idMovie.')';
'DELETE FROM path WHERE idParentPath='.$movie_root_path.' OR idPath='.$movie_root_path;
'DELETE FROM files WHERE idFile IN ( SELECT idFile FROM movie WHERE idMovie='.$idMovie.')';
'DELETE FROM movie WHERE idMovie='.$idMovie;
When removing a tv show:
php:
'DELETE FROM path WHERE idParentPath='.$tvshow_root_path.' OR idPath='.$tvshow_root_path;
'DELETE FROM actor_link WHERE media_type="tvshow" AND media_id='.$idShow;
'DELETE FROM country_link WHERE media_type="tvshow" AND media_id='.$idShow;
'DELETE FROM director_link WHERE media_type="tvshow" AND media_id='.$idShow;
'DELETE FROM writer_link WHERE media_type="tvshow" AND media_id='.$idShow;
'DELETE FROM uniqueid WHERE media_type="tvshow" AND media_id='.$idShow;
'DELETE FROM studio_link WHERE media_type="tvshow" AND media_id='.$idShow;
'DELETE FROM rating WHERE media_type="tvshow" AND media_id='.$idShow;
'DELETE FROM genre_link WHERE media_type="tvshow" AND media_id='.$idShow;
'DELETE FROM art WHERE media_type IN ("tvshow", "episode") AND media_id='.$idShow;
'DELETE FROM streamdetails WHERE idFile IN ( SELECT idFile FROM episode WHERE idShow='.$idShow.')';
'DELETE FROM bookmark WHERE idFile IN ( SELECT idFile FROM episode WHERE idShow='.$idShow.')';
'DELETE FROM files WHERE idFile IN ( SELECT idFile FROM episode WHERE idShow='.$idShow.')';
'DELETE FROM tvshowlinkpath WHERE idShow='.$idShow;
'DELETE FROM episode WHERE idShow='.$idShow;
'DELETE FROM seasons WHERE idShow='.$idShow;
'DELETE FROM tvshow WHERE idShow='.$idShow;
Don't use these lines, they have variables that require content.
It goes to show that you'll need a bit more than just deleting records from the 'files' table alone if you truely want to clean up the database.