From 6f5ae66c548cf2080a0292ef754f9781ce2203b7 Mon Sep 17 00:00:00 2001 From: im85288 Date: Sun, 3 May 2015 13:44:23 +0100 Subject: [PATCH] added initial box set support --- resources/lib/LibrarySync.py | 37 ++++++++++++++++++++++++ resources/lib/WriteKodiDB.py | 56 ++++++++++++++++++++++++++++++++---- 2 files changed, 88 insertions(+), 5 deletions(-) diff --git a/resources/lib/LibrarySync.py b/resources/lib/LibrarySync.py index a453a4b2..5e8cb15e 100644 --- a/resources/lib/LibrarySync.py +++ b/resources/lib/LibrarySync.py @@ -142,6 +142,31 @@ class LibrarySync(): else: if kodiMovie[2] != API().getChecksum(item): WriteKodiDB().addOrUpdateMovieToKodiLibrary(item["Id"],connection, cursor, view.get('title')) + + + + #### PROCESS BOX SETS ##### + if(pDialog != None): + utils.logMsg("Sync Movies", "BoxSet Sync Started", 1) + boxsets = ReadEmbyDB().getBoxSets() + + total = len(boxsets) + 1 + count = 1 + for boxset in boxsets: + progressTitle = "Processing BoxSets"+ " (" + str(count) + " of " + str(total) + ")" + pDialog.update(0, "Emby for Kodi - Running Sync", progressTitle) + count += 1 + if(self.ShouldStop()): + return False + boxsetMovies = ReadEmbyDB().getMoviesInBoxSet(boxset["Id"]) + WriteKodiDB().addBoxsetToKodiLibrary(boxset,connection, cursor) + + for boxsetMovie in boxsetMovies: + if(self.ShouldStop()): + return False + WriteKodiDB().updateBoxsetToKodiLibrary(boxsetMovie,boxset, connection, cursor) + + utils.logMsg("Sync Movies", "BoxSet Sync Finished", 1) #### PROCESS DELETES ##### allEmbyMovieIds = set(allEmbyMovieIds) @@ -335,7 +360,19 @@ class LibrarySync(): if not item.get('IsFolder'): WriteKodiDB().addOrUpdateMovieToKodiLibrary(item["Id"],connection, cursor, view.get('title')) + + + #### PROCESS BOX SETS ##### + boxsets = ReadEmbyDB().getBoxSets() + + for boxset in boxsets: + boxsetMovies = ReadEmbyDB().getMoviesInBoxSet(boxset["Id"]) + WriteKodiDB().addBoxsetToKodiLibrary(boxset,connection, cursor) + + for boxsetMovie in boxsetMovies: + WriteKodiDB().updateBoxsetToKodiLibrary(boxsetMovie,boxset, connection, cursor) + #### PROCESS TV SHOWS #### views = ReadEmbyDB().getCollections("tvshows") for view in views: diff --git a/resources/lib/WriteKodiDB.py b/resources/lib/WriteKodiDB.py index 96c42b2d..3cdd8951 100644 --- a/resources/lib/WriteKodiDB.py +++ b/resources/lib/WriteKodiDB.py @@ -992,15 +992,61 @@ class WriteKodiDB(): setssql="INSERT INTO sets (idSet, strSet) values(?, ?)" cursor.execute(setssql, (None,strSet)) #if OK: + cursor.execute("SELECT idSet FROM sets WHERE strSet = ?", (strSet,)) + result = cursor.fetchone() if result != None: setid = result[0] + + currentsetartsql = "SELECT type, url FROM art where media_type = ? and media_id = ? and url != ''" + cursor.execute(currentsetartsql, ("set", setid)) + existing_type_map = {} + rows = cursor.fetchall() + for row in rows: + existing_type_map[row[0] ] = row[1] + + artwork = {} + artwork["poster"] = API().getArtwork(boxset, "Primary") + artwork["banner"] = API().getArtwork(boxset, "Banner") + artwork["clearlogo"] = API().getArtwork(boxset, "Logo") + artwork["clearart"] = API().getArtwork(boxset, "Art") + artwork["landscape"] = API().getArtwork(boxset, "Thumb") + artwork["discart"] = API().getArtwork(boxset, "Disc") + artwork["fanart"] = API().getArtwork(boxset, "Backdrop") + + art_types = ['poster','fanart','landscape','clearlogo','clearart','banner','discart'] + for update_type in art_types: + if ( update_type in existing_type_map ): + if ( existing_type_map[update_type] != artwork[update_type] ) and artwork[update_type] != '': + setupdateartsql = "UPDATE art SET url = ? where media_type = ? and media_id = ? and type = ?" + cursor.execute(setupdateartsql,(artwork[update_type],"set",setid,update_type)) + elif artwork[update_type] != '': + setartsql = "INSERT INTO art(media_id, media_type, type, url) VALUES(?,?,?,?)" + cursor.execute(setartsql,(setid,"set",update_type,artwork[update_type])) return True - def updateBoxsetToKodiLibrary(self, boxsetmovie, boxset): + def updateBoxsetToKodiLibrary(self, boxsetmovie, boxset, connection, cursor): strSet = boxset["Name"] - kodiMovie = ReadKodiDB().getKodiMovie(boxsetmovie["Id"]) - if kodiMovie != None: - WriteKodiDB().updateProperty(kodiMovie,"set",strSet,"movie",True) - \ No newline at end of file + cursor.execute("SELECT kodi_id FROM emby WHERE emby_id = ?",(boxsetmovie["Id"],)) + result = cursor.fetchone() + if result != None: + movieid = result[0] + else: + movieid = None + if movieid != None: + # check if exists + cursor.execute("SELECT idSet FROM sets WHERE strSet = ?", (strSet,)) + result = cursor.fetchone() + setid = None + if result != None: + setid = result[0] + + pathsql="update movie SET idSet = ? WHERE idMovie = ?" + cursor.execute(pathsql, (setid, movieid)) + + #update the checksum in emby table + cursor.execute("UPDATE emby SET checksum = ? WHERE emby_id = ?", (API().getChecksum(boxsetmovie),boxsetmovie["Id"])) + + + \ No newline at end of file