diff --git a/resources/lib/kodi_db/video.py b/resources/lib/kodi_db/video.py index 1e959938..aceb5447 100644 --- a/resources/lib/kodi_db/video.py +++ b/resources/lib/kodi_db/video.py @@ -178,11 +178,13 @@ class KodiVideoDB(common.KodiDBBase): 'plugin://plugin.video.plexkodiconnect' These entries should be deleted as they're created falsely by Kodi. """ - return (x[0] for x in self.cursor.execute(''' - SELECT idFile FROM files - WHERE dateAdded IS NULL - AND strFilename LIKE \'plugin://plugin.video.plexkodiconnect%\' - ''')) + return (x[0] for x in self.cursor.execute(""" + SELECT files.idFile + FROM files + LEFT JOIN path ON path.idPath = files.idPath + WHERE files.dateAdded IS NULL + AND path.strPath LIKE \'%plex.direct%\' + """)) def show_id_from_path(self, path): """ diff --git a/resources/lib/kodimonitor.py b/resources/lib/kodimonitor.py index d38fa658..23243da7 100644 --- a/resources/lib/kodimonitor.py +++ b/resources/lib/kodimonitor.py @@ -517,13 +517,13 @@ def _clean_file_table(): This function tries for at most 5 seconds to clean the file table. """ LOG.debug('Start cleaning Kodi files table') - app.APP.monitor.waitForAbort(2) + app.APP.monitor.waitForAbort(1) try: - with kodi_db.KodiVideoDB() as kodidb_1: - with kodi_db.KodiVideoDB(lock=False) as kodidb_2: - for file_id in kodidb_1.obsolete_file_ids(): - LOG.debug('Removing obsolete Kodi file_id %s', file_id) - kodidb_2.remove_file(file_id, remove_orphans=False) + with kodi_db.KodiVideoDB() as kodidb: + file_ids = list(kodidb.obsolete_file_ids()) + LOG.debug('Obsolete kodi file_ids: %s', file_ids) + for file_id in file_ids: + kodidb.remove_file(file_id) except utils.OperationalError: LOG.debug('Database was locked, unable to clean file table') else: