From 6d191fef1d518ea823fd0bd9f0fd3884f1bba8b9 Mon Sep 17 00:00:00 2001 From: Marcel van der Veldt Date: Sat, 2 May 2015 03:47:05 +0200 Subject: [PATCH] fixed some small issues --- resources/lib/LibrarySync.py | 29 +++++++++++++++-------------- resources/lib/WriteKodiDB.py | 19 ++++++++++++------- 2 files changed, 27 insertions(+), 21 deletions(-) diff --git a/resources/lib/LibrarySync.py b/resources/lib/LibrarySync.py index 114e00e2..11a3498e 100644 --- a/resources/lib/LibrarySync.py +++ b/resources/lib/LibrarySync.py @@ -49,11 +49,10 @@ class LibrarySync(): connection = utils.KodiSQL() cursor = connection.cursor() - #TEMP --> add new columns - try: + #Add the special emby table + if not startupDone: cursor.execute("CREATE TABLE IF NOT EXISTS emby(emby_id TEXT, kodi_id INTEGER, media_type TEXT, checksum TEXT, parent_id INTEGER)") connection.commit() - except: pass # sync movies self.MoviesSync(connection,cursor,True) @@ -89,6 +88,9 @@ class LibrarySync(): allMB3Movies = ReadEmbyDB().getMovies(view.get('id')) allKodiMovies = ReadKodiDB().getKodiMovies(connection, cursor) + + for kodimovie in allKodiMovies: + allKodiMovieIds.append(kodimovie[1]) #### PROCESS ADDS AND UPDATES ### for item in allMB3Movies: @@ -98,12 +100,10 @@ class LibrarySync(): kodiMovie = None for kodimovie in allKodiMovies: - allKodiMovieIds.append(kodimovie[1]) if kodimovie[1] == item["Id"]: kodiMovie = kodimovie if kodiMovie == None: - allKodiMovieIds.append(item["Id"]) WriteKodiDB().addOrUpdateMovieToKodiLibrary(item["Id"],connection, cursor, view.get('title')) else: if kodiMovie[2] != API().getChecksum(item) or item["Id"] in itemList: @@ -128,11 +128,15 @@ class LibrarySync(): allKodiTvShowIds = list() allEmbyTvShowIds = list() - + for view in views: allEmbyTvShows = ReadEmbyDB().getTvShows(view.get('id')) allKodiTvShows = ReadKodiDB().getKodiTvShows(connection, cursor) + + for kodishow in allKodiTvShows: + allKodiTvShowIds.append(kodishow[1]) + #### TVSHOW: PROCESS ADDS AND UPDATES ### for item in allEmbyTvShows: @@ -143,13 +147,11 @@ class LibrarySync(): #build a list with all Id's and get the existing entry (if exists) in Kodi DB kodiShow = None for kodishow in allKodiTvShows: - allKodiTvShowIds.append(kodishow[1]) if kodishow[1] == item["Id"]: kodiShow = kodishow if kodiShow == None: # Tv show doesn't exist in Kodi yet so proceed and add it - allKodiTvShowIds.append(item["Id"]) kodiId = WriteKodiDB().addOrUpdateTvShowToKodiLibrary(item["Id"],connection, cursor, view.get('title')) else: kodiId = kodishow[0] @@ -180,22 +182,23 @@ class LibrarySync(): allEmbyEpisodes = ReadEmbyDB().getEpisodes(embyShowId) allKodiEpisodes = ReadKodiDB().getKodiEpisodes(connection, cursor, kodiShowId) + + for kodiepisode in allKodiEpisodes: + allKodiEpisodeIds.append(kodiepisode[1]) #### EPISODES: PROCESS ADDS AND UPDATES ### for item in allEmbyEpisodes: allEmbyEpisodeIds.append(item["Id"]) - #build a list with all Id's and get the existing entry (if exists) in Kodi DB + #get the existing entry (if exists) in Kodi DB kodiEpisode = None for kodiepisode in allKodiEpisodes: - allKodiEpisodeIds.append(kodiepisode[1]) if kodiepisode[1] == item["Id"]: kodiEpisode = kodiepisode if kodiEpisode == None: # Episode doesn't exist in Kodi yet so proceed and add it - allKodiEpisodeIds.append(item["Id"]) WriteKodiDB().addOrUpdateEpisodeToKodiLibrary(item["Id"], kodiShowId, connection, cursor) else: # If there are changes to the item, perform a full sync of the item @@ -204,10 +207,8 @@ class LibrarySync(): #### EPISODES: PROCESS DELETES ##### allEmbyEpisodeIds = set(allEmbyEpisodeIds) - print allEmbyEpisodeIds for kodiId in allKodiEpisodeIds: - print "kodiId-->" + kodiId - if not kodiId in allEmbyEpisodeIds: + if (not kodiId in allEmbyEpisodeIds): WINDOW.setProperty(kodiId,"deleted") WriteKodiDB().deleteEpisodeFromKodiLibrary(kodiId, connection, cursor) diff --git a/resources/lib/WriteKodiDB.py b/resources/lib/WriteKodiDB.py index 6e47a853..9580b7b0 100644 --- a/resources/lib/WriteKodiDB.py +++ b/resources/lib/WriteKodiDB.py @@ -26,17 +26,22 @@ class WriteKodiDB(): def updatePlayCountFromKodi(self, id, type, playcount=0): #when user marks item watched from kodi interface update this in MB3 - xbmc.sleep(sleepVal) - utils.logMsg("Emby", "updatePlayCountFromKodi Called") - mb3Id = ReadKodiDB().getEmbyIdByKodiId(id, type) + utils.logMsg("Emby", "updatePlayCountFromKodi Called") + connection = utils.KodiSQL() + cursor = connection.cursor() + cursor.execute("SELECT emby_id FROM emby WHERE media_type=? AND kodi_id=?",(type,id)) + + emby_id = cursor.fetchone()[0] + cursor.close - if(mb3Id != None): + if(emby_id != None): addon = xbmcaddon.Addon(id='plugin.video.emby') downloadUtils = DownloadUtils() - - watchedurl = "{server}/mediabrowser/Users/{UserId}/PlayedItems/%s" % mb3Id + + #FIXME --> This is no longer working ??!! + watchedurl = "{server}/mediabrowser/Users/{UserId}/PlayedItems/%s" % emby_id utils.logMsg("Emby","watchedurl -->" + watchedurl) if playcount != 0: downloadUtils.downloadUrl(watchedurl, postBody="", type="POST") @@ -162,7 +167,7 @@ class WriteKodiDB(): #### UPDATE THE MOVIE ##### else: - pathsql="update movie SET c00 = ?, c01 = ?, c02 = ?, c05 = ?, c06 = ?, c07 = ?, c09 = ? c10 = ?, c11 = ?, c12 = ?, c14 = ?, c15 = ?, c16 = ?, c18 = ?, c19 = ? WHERE idMovie = ?" + 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)) #update the checksum in emby table