mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2024-12-25 02:06:09 +00:00
Clean up shows emptied by web socket
This commit is contained in:
parent
ac4ea1f361
commit
9041f16ff9
2 changed files with 65 additions and 2 deletions
|
@ -61,6 +61,55 @@ class ReadKodiDB():
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def getShowIdByEmbyId(self, id, connection=None, cursor=None):
|
||||||
|
if not connection:
|
||||||
|
connection = utils.KodiSQL()
|
||||||
|
cursor = connection.cursor()
|
||||||
|
closeCon = True
|
||||||
|
else:
|
||||||
|
closeCon = False
|
||||||
|
cursor.execute("SELECT parent_id FROM emby WHERE emby_id=?",(id,))
|
||||||
|
result = cursor.fetchone()
|
||||||
|
if closeCon:
|
||||||
|
connection.close()
|
||||||
|
if result:
|
||||||
|
return result[0]
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
|
def getTypeByEmbyId(self, id, connection=None, cursor=None):
|
||||||
|
if not connection:
|
||||||
|
connection = utils.KodiSQL()
|
||||||
|
cursor = connection.cursor()
|
||||||
|
closeCon = True
|
||||||
|
else:
|
||||||
|
closeCon = False
|
||||||
|
cursor.execute("SELECT media_type FROM emby WHERE emby_id=?",(id,))
|
||||||
|
result = cursor.fetchone()
|
||||||
|
if closeCon:
|
||||||
|
connection.close()
|
||||||
|
if result:
|
||||||
|
return result[0]
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
|
def getShowTotalCount(self, id, connection=None, cursor=None):
|
||||||
|
if not connection:
|
||||||
|
connection = utils.KodiSQL()
|
||||||
|
cursor = connection.cursor()
|
||||||
|
closeCon = True
|
||||||
|
else:
|
||||||
|
closeCon = False
|
||||||
|
command = "SELECT totalCount FROM tvshowcounts WHERE idShow=%s" % str(id)
|
||||||
|
cursor.execute(command)
|
||||||
|
result = cursor.fetchone()
|
||||||
|
if closeCon:
|
||||||
|
connection.close()
|
||||||
|
if result:
|
||||||
|
return result[0]
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
def getKodiMusicArtists(self, connection, cursor):
|
def getKodiMusicArtists(self, connection, cursor):
|
||||||
#returns all artists in Kodi db
|
#returns all artists in Kodi db
|
||||||
cursor.execute("SELECT kodi_id, emby_id, checksum FROM emby WHERE media_type='artist'")
|
cursor.execute("SELECT kodi_id, emby_id, checksum FROM emby WHERE media_type='artist'")
|
||||||
|
|
|
@ -21,6 +21,7 @@ from PlaybackUtils import PlaybackUtils
|
||||||
from LibrarySync import LibrarySync
|
from LibrarySync import LibrarySync
|
||||||
from WriteKodiVideoDB import WriteKodiVideoDB
|
from WriteKodiVideoDB import WriteKodiVideoDB
|
||||||
from ReadEmbyDB import ReadEmbyDB
|
from ReadEmbyDB import ReadEmbyDB
|
||||||
|
from ReadKodiDB import ReadKodiDB
|
||||||
|
|
||||||
_MODE_BASICPLAY=12
|
_MODE_BASICPLAY=12
|
||||||
|
|
||||||
|
@ -253,9 +254,22 @@ class WebSocketThread(threading.Thread):
|
||||||
connection = utils.KodiSQL("video")
|
connection = utils.KodiSQL("video")
|
||||||
cursor = connection.cursor()
|
cursor = connection.cursor()
|
||||||
for item in itemsRemoved:
|
for item in itemsRemoved:
|
||||||
|
type=ReadKodiDB().getTypeByEmbyId(item, connection, cursor)
|
||||||
|
self.logMsg("Type: " + str(type))
|
||||||
self.logMsg("Message : Doing LibraryChanged : Items Removed : Calling deleteItemFromKodiLibrary: " + item, 0)
|
self.logMsg("Message : Doing LibraryChanged : Items Removed : Calling deleteItemFromKodiLibrary: " + item, 0)
|
||||||
|
if type == "episode":
|
||||||
|
showId=ReadKodiDB().getShowIdByEmbyId(item, connection, cursor) # Get the TV Show ID
|
||||||
|
self.logMsg("ShowID: " + str(showId),0)
|
||||||
WriteKodiVideoDB().deleteItemFromKodiLibrary(item, connection, cursor)
|
WriteKodiVideoDB().deleteItemFromKodiLibrary(item, connection, cursor)
|
||||||
connection.commit()
|
connection.commit() #Need to commit so that the count will be right - can't use one in case of multiple deletes
|
||||||
|
if type == "episode":
|
||||||
|
showTotalCount = ReadKodiDB().getShowTotalCount(showId, connection, cursor) # Check if there are no episodes left
|
||||||
|
self.logMsg("ShowTotalCount: " + str(showTotalCount),0)
|
||||||
|
if showTotalCount == 0 or showTotalCount == None: # Delete show if no episodes are left
|
||||||
|
embyId=ReadKodiDB().getEmbyIdByKodiId(showId, "tvshow", connection, cursor)
|
||||||
|
self.logMsg("Message : Doing LibraryChanged : Deleting show:" + embyId, 0)
|
||||||
|
WriteKodiVideoDB().deleteItemFromKodiLibrary(embyId, connection, cursor)
|
||||||
|
connection.commit()
|
||||||
cursor.close()
|
cursor.close()
|
||||||
|
|
||||||
#Process music library
|
#Process music library
|
||||||
|
|
Loading…
Reference in a new issue