mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2024-12-26 02:36:10 +00:00
fix a lock up on DB access
if you do an insert or update you MUST call commit() before returning
This commit is contained in:
parent
7b02b45000
commit
7b85d4aafc
1 changed files with 50 additions and 33 deletions
|
@ -417,7 +417,6 @@ class WriteKodiDB():
|
||||||
|
|
||||||
#update artwork
|
#update artwork
|
||||||
changes = False
|
changes = False
|
||||||
|
|
||||||
artwork = {}
|
artwork = {}
|
||||||
artwork["thumb"] = API().getArtwork(MBitem, "Primary")
|
artwork["thumb"] = API().getArtwork(MBitem, "Primary")
|
||||||
|
|
||||||
|
@ -692,13 +691,18 @@ class WriteKodiDB():
|
||||||
|
|
||||||
cursor.execute(pathsql, (movieid, fileid, title, plot, shortplot, rating, year, MBitem["Id"], sorttitle, runtime, title, trailerUrl))
|
cursor.execute(pathsql, (movieid, fileid, title, plot, shortplot, rating, year, MBitem["Id"], sorttitle, runtime, title, trailerUrl))
|
||||||
|
|
||||||
|
actionPerformed = False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
connection.commit()
|
connection.commit()
|
||||||
utils.logMsg("Emby","Added movie to Kodi Library",MBitem["Id"] + " - " + MBitem["Name"])
|
utils.logMsg("Emby","Added movie to Kodi Library",MBitem["Id"] + " - " + MBitem["Name"])
|
||||||
|
actionPerformed = True
|
||||||
except:
|
except:
|
||||||
utils.logMsg("Emby","Error adding movie to Kodi Library",MBitem["Id"] + " - " + MBitem["Name"])
|
utils.logMsg("Emby","Error adding movie to Kodi Library",MBitem["Id"] + " - " + MBitem["Name"])
|
||||||
actionPerformed = False
|
actionPerformed = False
|
||||||
|
|
||||||
|
return actionPerformed
|
||||||
|
|
||||||
def addMusicVideoToKodiLibrary( self, MBitem, connection, cursor ):
|
def addMusicVideoToKodiLibrary( self, MBitem, connection, cursor ):
|
||||||
|
|
||||||
#adds a musicvideo to Kodi by directly inserting it to connectionthe DB while there is no addMusicVideo available on the json API
|
#adds a musicvideo to Kodi by directly inserting it to connectionthe DB while there is no addMusicVideo available on the json API
|
||||||
|
@ -768,25 +772,55 @@ class WriteKodiDB():
|
||||||
pathsql="insert into musicvideo(idMVideo, idFile, c00, c04, c08, c23) values(?, ?, ?, ?, ?, ?)"
|
pathsql="insert into musicvideo(idMVideo, idFile, c00, c04, c08, c23) values(?, ?, ?, ?, ?, ?)"
|
||||||
cursor.execute(pathsql, (musicvideoid, fileid, title, runtime, plot, MBitem["Id"]))
|
cursor.execute(pathsql, (musicvideoid, fileid, title, runtime, plot, MBitem["Id"]))
|
||||||
|
|
||||||
|
actionPerformed = False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
connection.commit()
|
connection.commit()
|
||||||
utils.logMsg("Emby","Added musicvideo to Kodi Library",MBitem["Id"] + " - " + MBitem["Name"])
|
utils.logMsg("Emby","Added musicvideo to Kodi Library",MBitem["Id"] + " - " + MBitem["Name"])
|
||||||
|
actionPerformed = True
|
||||||
except:
|
except:
|
||||||
utils.logMsg("Emby","Error adding musicvideo to Kodi Library",MBitem["Id"] + " - " + MBitem["Name"])
|
utils.logMsg("Emby","Error adding musicvideo to Kodi Library",MBitem["Id"] + " - " + MBitem["Name"])
|
||||||
actionPerformed = False
|
|
||||||
|
return actionPerformed
|
||||||
|
|
||||||
def addEpisodeToKodiLibrary(self, MBitem, connection, cursor):
|
def addEpisodeToKodiLibrary(self, MBitem, connection, cursor):
|
||||||
|
|
||||||
#adds a Episode to Kodi by directly inserting it to the DB while there is no addEpisode available on the json API
|
#adds a Episode to Kodi by directly inserting it to the DB while there is no addEpisode available on the json API
|
||||||
#TODO: PR at Kodi team for a addEpisode endpoint on their API
|
#TODO: PR at Kodi team for a addEpisode endpoint on their API
|
||||||
|
|
||||||
|
# check season
|
||||||
|
season = 0
|
||||||
|
if MBitem.get("ParentIndexNumber") != None:
|
||||||
|
season = int(MBitem.get("ParentIndexNumber"))
|
||||||
|
else:
|
||||||
|
utils.logMsg("Emby","Error adding episode to Kodi Library, no ParentIndexNumber - ID: " + MBitem["Id"] + " - " + MBitem["Name"])
|
||||||
|
return False
|
||||||
|
|
||||||
# first check the episode is not already in the DB using the Emby ID which is stored in c20
|
# first check the episode is not already in the DB using the Emby ID which is stored in c20
|
||||||
cursor.execute("SELECT idEpisode FROM episode WHERE c20 = ?",(MBitem["Id"],))
|
cursor.execute("SELECT idEpisode FROM episode WHERE c20 = ?",(MBitem["Id"],))
|
||||||
result = cursor.fetchone()
|
result = cursor.fetchone()
|
||||||
if result != None:
|
if result != None:
|
||||||
utils.logMsg("Emby", "Episode already exists in DB : " + MBitem["Id"] + " - " + MBitem["Name"], 2)
|
utils.logMsg("Emby", "Episode already exists in DB : " + MBitem["Id"] + " - " + MBitem["Name"], 2)
|
||||||
return
|
return False
|
||||||
|
|
||||||
|
# get the showid
|
||||||
|
cursor.execute("SELECT idShow as showid FROM tvshow WHERE c12 = ?",(MBitem["SeriesId"],))
|
||||||
|
result = cursor.fetchone()
|
||||||
|
showid = -1
|
||||||
|
if(result == None):
|
||||||
|
utils.logMsg("Emby","Error adding episode to Kodi Library, couldn't find show - ID: " + MBitem["Id"] + " - " + MBitem["Name"])
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
showid = result[0]
|
||||||
|
|
||||||
|
# check season
|
||||||
|
cursor.execute("SELECT idSeason FROM seasons WHERE idShow = ? and season = ?",(showid, season))
|
||||||
|
result = cursor.fetchone()
|
||||||
|
if(result == None):
|
||||||
|
utils.logMsg("Emby","Error adding episode to Kodi Library, season does not exist - ShowId: " + str(showid) + " SeasonNo: " + str(season) + " EmbyId: " + MBitem["Id"] + " Name: " + MBitem["Name"])
|
||||||
|
return False
|
||||||
|
|
||||||
|
# do add
|
||||||
addon = xbmcaddon.Addon(id='plugin.video.emby')
|
addon = xbmcaddon.Addon(id='plugin.video.emby')
|
||||||
port = addon.getSetting('port')
|
port = addon.getSetting('port')
|
||||||
host = addon.getSetting('ipaddress')
|
host = addon.getSetting('ipaddress')
|
||||||
|
@ -845,32 +879,6 @@ class WriteKodiDB():
|
||||||
sql="INSERT OR REPLACE into files(idFile, idPath, strFilename, playCount, lastPlayed, dateAdded) values(?, ?, ?, ?, ?, ?)"
|
sql="INSERT OR REPLACE into files(idFile, idPath, strFilename, playCount, lastPlayed, dateAdded) values(?, ?, ?, ?, ?, ?)"
|
||||||
cursor.execute(sql, (fileid,pathid,filename,playcount,lastplayed,dateadded))
|
cursor.execute(sql, (fileid,pathid,filename,playcount,lastplayed,dateadded))
|
||||||
|
|
||||||
#get the showid
|
|
||||||
cursor.execute("SELECT idShow as showid FROM tvshow WHERE c12 = ?",(MBitem["SeriesId"],))
|
|
||||||
result = cursor.fetchone()
|
|
||||||
showid = -1
|
|
||||||
if(result == None):
|
|
||||||
utils.logMsg("Emby","Error adding episode to Kodi Library, couldn't find show - ID: " + MBitem["Id"] + " - " + MBitem["Name"])
|
|
||||||
actionPerformed = False
|
|
||||||
return False
|
|
||||||
else:
|
|
||||||
showid = result[0]
|
|
||||||
|
|
||||||
# check season
|
|
||||||
season = 0
|
|
||||||
if MBitem.get("ParentIndexNumber") != None:
|
|
||||||
season = int(MBitem.get("ParentIndexNumber"))
|
|
||||||
else:
|
|
||||||
utils.logMsg("Emby","Error adding episode to Kodi Library, no ParentIndexNumber - ID: " + MBitem["Id"] + " - " + MBitem["Name"])
|
|
||||||
return False
|
|
||||||
|
|
||||||
cursor.execute("SELECT idSeason FROM seasons WHERE idShow = ? and season = ?",(showid, season))
|
|
||||||
result = cursor.fetchone()
|
|
||||||
if(result == None):
|
|
||||||
utils.logMsg("Emby","Error adding episode to Kodi Library, season does not exist - ShowId: " + str(showid) + " SeasonNo: " + str(season) + " EmbyId: " + MBitem["Id"] + " Name: " + MBitem["Name"])
|
|
||||||
actionPerformed = False
|
|
||||||
return False
|
|
||||||
|
|
||||||
# build info
|
# build info
|
||||||
episode = 0
|
episode = 0
|
||||||
if MBitem.get("IndexNumber") != None:
|
if MBitem.get("IndexNumber") != None:
|
||||||
|
@ -893,12 +901,16 @@ class WriteKodiDB():
|
||||||
pathsql = "INSERT into episode(idEpisode, idFile, c00, c01, c03, c05, c09, c20, c12, c13, c14, idShow, c15, c16) values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
|
pathsql = "INSERT into episode(idEpisode, idFile, c00, c01, c03, c05, c09, c20, c12, c13, c14, idShow, c15, c16) values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
|
||||||
cursor.execute(pathsql, (episodeid, fileid, title, plot, rating, premieredate, runtime, MBitem["Id"], season, episode, title, showid, "-1", "-1"))
|
cursor.execute(pathsql, (episodeid, fileid, title, plot, rating, premieredate, runtime, MBitem["Id"], season, episode, title, showid, "-1", "-1"))
|
||||||
|
|
||||||
|
actionPerformed = False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
connection.commit()
|
connection.commit()
|
||||||
utils.logMsg("Emby","Added episode to Kodi Library - ID: " + MBitem["Id"] + " - " + MBitem["Name"])
|
utils.logMsg("Emby","Added episode to Kodi Library - ID: " + MBitem["Id"] + " - " + MBitem["Name"])
|
||||||
|
actionPerformed = True
|
||||||
except:
|
except:
|
||||||
utils.logMsg("Emby","Error adding episode to Kodi Library - ID: " + MBitem["Id"] + " - " + MBitem["Name"])
|
utils.logMsg("Emby","Error adding episode to Kodi Library - ID: " + MBitem["Id"] + " - " + MBitem["Name"])
|
||||||
actionPerformed = False
|
|
||||||
|
return actionPerformed
|
||||||
|
|
||||||
def deleteMovieFromKodiLibrary(self, id ):
|
def deleteMovieFromKodiLibrary(self, id ):
|
||||||
kodiItem = ReadKodiDB().getKodiMovie(id)
|
kodiItem = ReadKodiDB().getKodiMovie(id)
|
||||||
|
@ -970,6 +982,7 @@ class WriteKodiDB():
|
||||||
elif "/" in path:
|
elif "/" in path:
|
||||||
toplevelpathstr = path.rsplit("/",2)[1]
|
toplevelpathstr = path.rsplit("/",2)[1]
|
||||||
toplevelpath = path.replace(toplevelpathstr + "/","")
|
toplevelpath = path.replace(toplevelpathstr + "/","")
|
||||||
|
|
||||||
cursor.execute("SELECT idPath as tlpathid FROM path WHERE strPath = ?",(toplevelpath,))
|
cursor.execute("SELECT idPath as tlpathid FROM path WHERE strPath = ?",(toplevelpath,))
|
||||||
result = cursor.fetchone()
|
result = cursor.fetchone()
|
||||||
if result == None:
|
if result == None:
|
||||||
|
@ -997,12 +1010,16 @@ class WriteKodiDB():
|
||||||
pathsql="insert into tvshowlinkpath(idShow,idPath) values(?, ?)"
|
pathsql="insert into tvshowlinkpath(idShow,idPath) values(?, ?)"
|
||||||
cursor.execute(pathsql, (showid,pathid))
|
cursor.execute(pathsql, (showid,pathid))
|
||||||
|
|
||||||
|
actionPerformed = False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
connection.commit()
|
connection.commit()
|
||||||
utils.logMsg("Emby","Added TV Show to Kodi Library: " + MBitem["Id"] + " - " + MBitem["Name"])
|
utils.logMsg("Emby","Added TV Show to Kodi Library: " + MBitem["Id"] + " - " + MBitem["Name"])
|
||||||
|
actionPerformed = True
|
||||||
except:
|
except:
|
||||||
utils.logMsg("Emby","Error adding tvshow to Kodi Library: " + MBitem["Id"] + " - " + MBitem["Name"])
|
utils.logMsg("Emby","Error adding tvshow to Kodi Library: " + MBitem["Id"] + " - " + MBitem["Name"])
|
||||||
actionPerformed = False
|
|
||||||
|
return actionPerformed
|
||||||
|
|
||||||
def deleteTVShowFromKodiLibrary(self, id):
|
def deleteTVShowFromKodiLibrary(self, id):
|
||||||
xbmc.sleep(sleepVal)
|
xbmc.sleep(sleepVal)
|
||||||
|
|
Loading…
Reference in a new issue