From 9c1f8476aaad31f4683224e3bc4d1d797caf8deb Mon Sep 17 00:00:00 2001 From: angelblue05 Date: Wed, 17 Jun 2015 21:34:45 -0500 Subject: [PATCH] Database follow up When upgrading Kodi, it will leave the old database in the folder. As to not conflict, use the higher database version number. --- resources/lib/Utils.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/resources/lib/Utils.py b/resources/lib/Utils.py index 8920fb78..4ed7b2c9 100644 --- a/resources/lib/Utils.py +++ b/resources/lib/Utils.py @@ -64,13 +64,16 @@ def KodiSQL(type="video"): def getKodiVideoDBPath(): dirs, files = xbmcvfs.listdir("special://database") - dbVersion = "" - + dbVersions = {} + for database in files: if "MyVideos" in database and database.endswith("db"): - dbVersion = database + version = database[len("MyVideos"):-len(".db")] + dbVersions[int(version)] = database + # Sort by highest version number + versions = sorted(dbVersions.keys(), reverse=True) - dbPath = xbmc.translatePath("special://database/%s" % dbVersion) + dbPath = xbmc.translatePath("special://database/%s" % dbVersions[versions[0]]) logMsg("Utils", "Path to Video database: %s" % dbPath, 0) return dbPath @@ -78,13 +81,16 @@ def getKodiVideoDBPath(): def getKodiMusicDBPath(): dirs, files = xbmcvfs.listdir("special://database") - dbVersion = "" + dbVersions = {} for database in files: if "MyMusic" in database and database.endswith("db"): - dbVersion = database + version = database[len("MyMusic"):-len(".db")] + dbVersions[int(version)] = database + # Sort by highest version number + versions = sorted(dbVersions.keys(), reverse=True) - dbPath = xbmc.translatePath("special://database/%s" % dbVersion) + dbPath = xbmc.translatePath("special://database/%s" % dbVersions[versions[0]]) logMsg("Utils", "Path to Music database: %s" % dbPath, 0) return dbPath