From 9838b0146709fb876d97c3babbc08b6e32cab854 Mon Sep 17 00:00:00 2001 From: Marcel van der Veldt Date: Thu, 26 Mar 2015 22:35:11 +0100 Subject: [PATCH] support for isengard sqlite and **experimental** mysql support --- addon.xml | 1 + resources/lib/Utils.py | 57 +++++++++++++++++++++++++++++++++--- resources/lib/WriteKodiDB.py | 17 ++++------- 3 files changed, 59 insertions(+), 16 deletions(-) diff --git a/addon.xml b/addon.xml index 560c8845..1f52ed77 100644 --- a/addon.xml +++ b/addon.xml @@ -5,6 +5,7 @@ provider-name="Emby.media"> + diff --git a/resources/lib/Utils.py b/resources/lib/Utils.py index 0202fedb..f1432906 100644 --- a/resources/lib/Utils.py +++ b/resources/lib/Utils.py @@ -11,7 +11,6 @@ import os import cProfile import pstats import time -import sqlite3 import inspect from xml.etree.ElementTree import Element, SubElement, Comment, tostring from xml.etree import ElementTree @@ -24,7 +23,7 @@ from DownloadUtils import DownloadUtils downloadUtils = DownloadUtils() addonSettings = xbmcaddon.Addon(id='plugin.video.emby') language = addonSettings.getLocalizedString -DATABASE_VERSION_HELIX = "90" + def logMsg(title, msg, level = 1): logLevel = int(addonSettings.getSetting("logLevel")) @@ -83,18 +82,68 @@ def checkKodiSources(): return False return True + +def KodiSQL(): + if xbmc.getinfolabel("System.BuildVersion").startswith("13"): + #gotham + dbVersion = "78" + if xbmc.getinfolabel("System.BuildVersion").startswith("15"): + #isengard + dbVersion = "91" + else: + #helix + dbVersion = "90" + + #find out if we should use MySQL + settingsFile = xbmc.translatePath( "special://profile/advancedsettings.xml" ) + if xbmcvfs.exists(settingsFile): + tree = ET.ElementTree(file=settingsFile) + root = tree.getroot() + video = root.find("videolibrary") + if video != None: + mysql = video.find("type") + if mysql != None: + useMySQL = True + db_port = video.find("port").text + db_host = video.find("host").text + db_user = video.find("user").text + db_pass = video.find("pass").text + if video.find("name") != None: + db_name = video.find("name").text + else: + db_name = "MyVideos" + SubElement(video, "importwatchedstate").text = "true" + if video.find("importresumepoint") == None: + writeNeeded = True + SubElement(video, "importresumepoint").text = "true" + + + if useMySQL: + import local.mysql.connector as database + connection = database.connect(dbPath) + connection = database.connect(db = db_name, user = db_user, passwd = db_pass, host = db_host, port = db_port) + connection.set_charset('utf8') + connection.set_unicode(True) + + else: + import sqlite3 as database + dbPath = xbmc.translatePath("special://userdata/Database/MyVideos" + dbVersion + ".db") + connection = database.connect(dbPath) + + return connection + def addKodiSource(name, path, type): #add new source to database, common way is to add it directly to the Kodi DB. Fallback to adding it to the sources.xml #return boolean wether a manual reboot is required. #todo: Do feature request with Kodi team to get support for adding a source by the json API - dbPath = xbmc.translatePath("special://userdata/Database/MyVideos%s.db" % DATABASE_VERSION_HELIX) + error = False if xbmcvfs.exists(dbPath): try: - connection = sqlite3.connect(dbPath) + connection = KodiSQL() cursor = connection.cursor( ) cursor.execute("select coalesce(max(idPath),0) as pathId from path") pathId = cursor.fetchone()[0] diff --git a/resources/lib/WriteKodiDB.py b/resources/lib/WriteKodiDB.py index b9706b03..9ede4d54 100644 --- a/resources/lib/WriteKodiDB.py +++ b/resources/lib/WriteKodiDB.py @@ -818,9 +818,8 @@ class WriteKodiDB(): #season poster and banner are set by the nfo. landscape image is filled by this method #if wanted this feature can be extended to also update the other artwork tvshowid = KodiItem["tvshowid"] - - dbPath = xbmc.translatePath("special://userdata/Database/MyVideos%s.db" % utils.DATABASE_VERSION_HELIX) - connection = sqlite3.connect(dbPath) + + connection = utils.KodiSQL() cursor = connection.cursor( ) seasonData = ReadEmbyDB().getTVShowSeasons(MBitem["Id"]) @@ -848,8 +847,7 @@ class WriteKodiDB(): utils.logMsg("MB3 Sync","setting resume point in kodi db..." + fileType + ": " + str(id)) xbmc.sleep(sleepVal) - dbPath = xbmc.translatePath("special://userdata/Database/MyVideos%s.db" % utils.DATABASE_VERSION_HELIX) - connection = sqlite3.connect(dbPath) + connection = utils.KodiSQL() cursor = connection.cursor( ) if fileType == "episode": @@ -901,10 +899,7 @@ class WriteKodiDB(): utils.logMsg("AddActorsToMedia", "List needs updating") xbmc.sleep(sleepVal) - - dbPath = xbmc.translatePath("special://userdata/Database/MyVideos%s.db" % utils.DATABASE_VERSION_HELIX) - - connection = sqlite3.connect(dbPath) + connection = utils.KodiSQL() cursor = connection.cursor() if(people != None): @@ -942,9 +937,7 @@ class WriteKodiDB(): def addBoxsetToKodiLibrary(self, boxset): #use sqlite to set add the set - dbPath = xbmc.translatePath("special://userdata/Database/MyVideos%s.db" % utils.DATABASE_VERSION_HELIX) - - connection = sqlite3.connect(dbPath) + connection = utils.KodiSQL() cursor = connection.cursor() strSet = boxset["Name"]