From 8c6b90923e1a04e0c95ee79c77449d0cb96ad5e1 Mon Sep 17 00:00:00 2001 From: Marcel van der Veldt Date: Sat, 2 May 2015 12:51:46 +0200 Subject: [PATCH] fixed some errors --- resources/lib/LibrarySync.py | 98 +++++++++++++++++++----------------- resources/lib/WriteKodiDB.py | 14 +++++- 2 files changed, 63 insertions(+), 49 deletions(-) diff --git a/resources/lib/LibrarySync.py b/resources/lib/LibrarySync.py index b542d9b8..0baa13d8 100644 --- a/resources/lib/LibrarySync.py +++ b/resources/lib/LibrarySync.py @@ -64,6 +64,7 @@ class LibrarySync(): self.MoviesFullSync(connection,cursor,pDialog) #sync Tvshows and episodes self.TvShowsFullSync(connection,cursor,pDialog) + # set the install done setting if(syncInstallRunDone == False and completed): @@ -115,7 +116,7 @@ class LibrarySync(): if(pDialog != None): progressTitle = "Processing " + view.get('title') + " (" + str(count) + " of " + str(total) + ")" pDialog.update(0, "Emby for Kodi - Running Sync", progressTitle) - count = 1 + count += 1 kodiMovie = None for kodimovie in allKodiMovies: @@ -128,12 +129,12 @@ class LibrarySync(): if kodiMovie[2] != API().getChecksum(item): WriteKodiDB().addOrUpdateMovieToKodiLibrary(item["Id"],connection, cursor, view.get('title')) - #### PROCESS DELETES ##### - allEmbyMovieIds = set(allEmbyMovieIds) - for kodiId in allKodiMovieIds: - if not kodiId in allEmbyMovieIds: - WINDOW.setProperty(kodiId,"deleted") - WriteKodiDB().deleteItemFromKodiLibrary(kodiId, connection, cursor) + #### PROCESS DELETES ##### + allEmbyMovieIds = set(allEmbyMovieIds) + for kodiId in allKodiMovieIds: + if not kodiId in allEmbyMovieIds: + WINDOW.setProperty(kodiId,"deleted") + WriteKodiDB().deleteItemFromKodiLibrary(kodiId, connection, cursor) def TvShowsFullSync(self,connection,cursor,pDialog): @@ -164,7 +165,7 @@ class LibrarySync(): if(pDialog != None): progressTitle = "Processing " + view.get('title') + " (" + str(count) + " of " + str(total) + ")" pDialog.update(0, "Emby for Kodi - Running Sync", progressTitle) - count = 1 + count += 1 #build a list with all Id's and get the existing entry (if exists) in Kodi DB kodiShow = None @@ -184,12 +185,12 @@ class LibrarySync(): #### PROCESS EPISODES ###### self.EpisodesFullSync(connection,cursor,item["Id"], kodiId) - #### TVSHOW: PROCESS DELETES ##### - allEmbyTvShowIds = set(allEmbyTvShowIds) - for kodiId in allKodiTvShowIds: - if not kodiId in allEmbyTvShowIds: - WINDOW.setProperty(kodiId,"deleted") - WriteKodiDB().deleteItemFromKodiLibrary(kodiId, connection, cursor) + #### TVSHOW: PROCESS DELETES ##### + allEmbyTvShowIds = set(allEmbyTvShowIds) + for kodiId in allKodiTvShowIds: + if not kodiId in allEmbyTvShowIds: + WINDOW.setProperty(kodiId,"deleted") + WriteKodiDB().deleteItemFromKodiLibrary(kodiId, connection, cursor) def EpisodesFullSync(self,connection,cursor,embyShowId, kodiShowId): @@ -241,43 +242,46 @@ class LibrarySync(): connection = utils.KodiSQL() cursor = connection.cursor() - #### PROCESS MOVIES #### - views = ReadEmbyDB().getCollections("movies") - for view in views: - allEmbyMovies = ReadEmbyDB().getMovies(view.get('id'), itemList) - for item in allEmbyMovies: + try: + #### PROCESS MOVIES #### + views = ReadEmbyDB().getCollections("movies") + for view in views: + allEmbyMovies = ReadEmbyDB().getMovies(view.get('id'), itemList) + for item in allEmbyMovies: + + if not item.get('IsFolder'): + WriteKodiDB().addOrUpdateMovieToKodiLibrary(item["Id"],connection, cursor, view.get('title')) + + #### PROCESS TV SHOWS #### + views = ReadEmbyDB().getCollections("tvshows") + for view in views: + allEmbyTvShows = ReadEmbyDB().getTvShows(view.get('id'),itemList) + for item in allEmbyTvShows: + if item.get('IsFolder') and item.get('RecursiveItemCount') != 0: + kodiId = WriteKodiDB().addOrUpdateTvShowToKodiLibrary(item["Id"],connection, cursor, view.get('title')) + + #### PROCESS EPISODES ###### + for item in itemList: - if not item.get('IsFolder'): - WriteKodiDB().addOrUpdateMovieToKodiLibrary(item["Id"],connection, cursor, view.get('title')) + MBitem = ReadEmbyDB().getItem(item) + print MBitem + if MBitem["Type"] == "Episode": - #### PROCESS TV SHOWS #### - views = ReadEmbyDB().getCollections("tvshows") - for view in views: - allEmbyTvShows = ReadEmbyDB().getTvShows(view.get('id'),itemList) - for item in allEmbyTvShows: - if item.get('IsFolder') and item.get('RecursiveItemCount') != 0: - kodiId = WriteKodiDB().addOrUpdateTvShowToKodiLibrary(item["Id"],connection, cursor, view.get('title')) + #get the tv show + cursor.execute("SELECT kodi_id FROM emby WHERE media_type='tvshow' AND emby_id=?", (MBitem["SeriesId"],)) + result = cursor.fetchall() + if result: + kodi_show_id = result[0] + else: + kodi_show_id = None + print "show id not found!" - #### PROCESS EPISODES ###### - for item in itemList: - - MBitem = ReadEmbyDB().getItem(item) - - if MBitem["Type"] == "Episode": - - #get the tv show - cursor.execute("SELECT kodi_id FROM emby WHERE media_type='tvshow' AND emby_id=?", (MBitem["SeriesId"],)) - result = cursor.fetchall() - if result: - kodi_show_id = result[0] - else: - kodi_show_id = None - - if kodi_show_id: - WriteKodiDB().addOrUpdateEpisodeToKodiLibrary(item["Id"], kodi_show_id, connection, cursor) + if kodi_show_id: + WriteKodiDB().addOrUpdateEpisodeToKodiLibrary(item["Id"], kodi_show_id, connection, cursor) + finally: + cursor.close() - - cursor.close() + #close the progress dialog if(pDialog != None): pDialog.close() diff --git a/resources/lib/WriteKodiDB.py b/resources/lib/WriteKodiDB.py index b50ba2c2..070f35e5 100644 --- a/resources/lib/WriteKodiDB.py +++ b/resources/lib/WriteKodiDB.py @@ -147,7 +147,10 @@ class WriteKodiDB(): ##### ADD THE MOVIE ############ - if movieid == None: + if movieid == None: + + utils.logMsg("ADD movie to Kodi library","Id: %s - Title: %s" % (embyId, title)) + #create the movie cursor.execute("select coalesce(max(idMovie),0) as movieid from movie") movieid = cursor.fetchone()[0] @@ -167,6 +170,7 @@ class WriteKodiDB(): #### UPDATE THE MOVIE ##### else: + utils.logMsg("UPDATE movie to Kodi library","Id: %s - Title: %s" % (embyId, title)) pathsql="update movie SET c00 = ?, c01 = ?, c02 = ?, c05 = ?, c06 = ?, c07 = ?, c09 = ?, c10 = ?, c11 = ?, c12 = ?, c14 = ?, c15 = ?, c16 = ?, c18 = ?, c19 = ? WHERE idMovie = ?" cursor.execute(pathsql, (title, plot, shortplot, rating, writer, year, imdb, sorttitle, runtime, mpaa, genre, director, title, studio, trailerUrl, movieid)) @@ -255,6 +259,8 @@ class WriteKodiDB(): #### ADD THE TV SHOW TO KODI ############## if showid == None: + utils.logMsg("ADD tvshow to Kodi library","Id: %s - Title: %s" % (embyId, title)) + #create the tv show path cursor.execute("select coalesce(max(idPath),0) as pathid from path") pathid = cursor.fetchone()[0] @@ -293,6 +299,8 @@ class WriteKodiDB(): #### UPDATE THE TV SHOW ############# else: + utils.logMsg("UPDATE tvshow to Kodi library","Id: %s - Title: %s" % (embyId, title)) + pathsql="UPDATE tvshow SET c00 = ?, c01 = ?, c04 = ?, c05 = ?, c08 = ?, c09 = ?, c13 = ?, c14 = ?, c15 = ? WHERE idShow = ?" cursor.execute(pathsql, (title, plot, rating, premieredate, title, genre, mpaa, studio, sorttitle, showid)) @@ -496,7 +504,7 @@ class WriteKodiDB(): # ADD EPISODE TO KODI if episodeid == None: - + utils.logMsg("ADD episode to Kodi library","Id: %s - Title: %s" % (embyId, title)) #create the episode cursor.execute("select coalesce(max(idEpisode),0) as episodeid from episode") episodeid = cursor.fetchone()[0] @@ -513,6 +521,8 @@ class WriteKodiDB(): # UPDATE THE EPISODE IN KODI (for now, we just send in all data) else: + utils.logMsg("UPDATE episode to Kodi library","Id: %s - Title: %s" % (embyId, title)) + pathsql = "UPDATE episode SET c00 = ?, c01 = ?, c03 = ?, c04 = ?, c05 = ?, c09 = ?, c10 = ?, c12 = ?, c13 = ?, c14 = ?, c15 = ?, c16 = ? WHERE idEpisode = ?" cursor.execute(pathsql, (title, plot, rating, writer, premieredate, runtime, director, season, episode, title, "-1", "-1", episodeid))