support for isengard sqlite and **experimental** mysql support

This commit is contained in:
Marcel van der Veldt 2015-03-26 22:35:11 +01:00
parent 6f870cc4f8
commit 9838b01467
3 changed files with 59 additions and 16 deletions

View File

@ -5,6 +5,7 @@
provider-name="Emby.media">
<requires>
<import addon="xbmc.python" version="2.1.0"/>
<import addon="script.module.myconnpy" version="0.3.2"/>
</requires>
<extension point="xbmc.python.pluginsource"
library="default.py">

View File

@ -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]

View File

@ -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"]