From 6718182411a1ce4e0bad521fb51b0010bf49939f Mon Sep 17 00:00:00 2001 From: croneter Date: Sun, 7 Oct 2018 17:07:45 +0200 Subject: [PATCH] Fix sync issues if video lies in root of file system - Fixes #544 - Manual Kodi database reset is necessary --- resources/lib/kodidb_functions.py | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/resources/lib/kodidb_functions.py b/resources/lib/kodidb_functions.py index 1a9c9727..c5680cd3 100644 --- a/resources/lib/kodidb_functions.py +++ b/resources/lib/kodidb_functions.py @@ -5,13 +5,9 @@ Connect to the Kodi databases (video and music) and operate on them """ from __future__ import absolute_import, division, unicode_literals from logging import getLogger -from ntpath import dirname from sqlite3 import IntegrityError -from . import artwork -from . import utils -from . import variables as v -from . import state +from . import artwork, utils, variables as v, state, path_ops ############################################################################### @@ -109,12 +105,9 @@ class KodiDBMethods(object): Video DB: Adds all subdirectories to path table while setting a "trail" of parent path ids """ - if "\\" in path: - # Local path - parentpath = "%s\\" % dirname(dirname(path)) - else: - # Network path - parentpath = "%s/" % dirname(dirname(path)) + parentpath = path_ops.path.abspath( + path_ops.path.join(path, + path_ops.decode_path(path_ops.path.pardir))) pathid = self.get_path(parentpath) if pathid is None: self.cursor.execute("SELECT COALESCE(MAX(idPath),0) FROM path") @@ -125,9 +118,11 @@ class KodiDBMethods(object): VALUES (?, ?, ?) ''' self.cursor.execute(query, (pathid, parentpath, datetime)) - parent_id = self.parent_path_id(parentpath) - query = 'UPDATE path SET idParentPath = ? WHERE idPath = ?' - self.cursor.execute(query, (parent_id, pathid)) + if parentpath != path: + # In case we end up having media in the filesystem root, C:\ + parent_id = self.parent_path_id(parentpath) + query = 'UPDATE path SET idParentPath = ? WHERE idPath = ?' + self.cursor.execute(query, (parent_id, pathid)) return pathid def add_video_path(self, path, date_added=None, id_parent_path=None,