From b0c795bdf4b2ad3cc34f8db6ff41c2036d1e61eb Mon Sep 17 00:00:00 2001 From: Marcel van der Veldt Date: Thu, 19 Mar 2015 09:44:25 +0100 Subject: [PATCH] fixed incremental sync for tvshows --- resources/lib/CreateFiles.py | 8 ++++---- resources/lib/LibrarySync.py | 26 ++++++++++++-------------- resources/lib/WriteKodiDB.py | 12 ++++++------ 3 files changed, 22 insertions(+), 24 deletions(-) diff --git a/resources/lib/CreateFiles.py b/resources/lib/CreateFiles.py index 41063fa4..6c86d468 100644 --- a/resources/lib/CreateFiles.py +++ b/resources/lib/CreateFiles.py @@ -25,7 +25,7 @@ movieLibrary = os.path.join(dataPath,'movies') tvLibrary = os.path.join(dataPath,'tvshows') class CreateFiles(): - def createSTRM(self,item,parentId=None): + def createSTRM(self,item): item_type=str(item.get("Type")).encode('utf-8') if item_type == "Movie": @@ -37,7 +37,7 @@ class CreateFiles(): strmFile = os.path.join(itemPath,item["Id"] + ".strm") if item_type == "Episode": - itemPath = os.path.join(tvLibrary,parentId) + itemPath = os.path.join(tvLibrary,item["SeriesId"]) if str(item.get("IndexNumber")) != None: filenamestr = self.CleanName(item.get("SeriesName")).encode('utf-8') + " S" + str(item.get("ParentIndexNumber")) + "E" + str(item.get("IndexNumber")) + " (" + item["Id"] + ").strm" else: @@ -57,7 +57,7 @@ class CreateFiles(): return changes - def createNFO(self,item, parentId=None): + def createNFO(self,item): downloadUtils = DownloadUtils() timeInfo = API().getTimeInfo(item) userData=API().getUserData(item) @@ -79,7 +79,7 @@ class CreateFiles(): nfoFile = os.path.join(itemPath,"tvshow.nfo") rootelement = "tvshow" if item_type == "Episode": - itemPath = os.path.join(tvLibrary,parentId) + itemPath = os.path.join(tvLibrary,item["SeriesId"]) if str(item.get("ParentIndexNumber")) != None: filenamestr = self.CleanName(item.get("SeriesName")).encode('utf-8') + " S" + str(item.get("ParentIndexNumber")) + "E" + str(item.get("IndexNumber")) + " (" + item["Id"] + ").nfo" else: diff --git a/resources/lib/LibrarySync.py b/resources/lib/LibrarySync.py index 26b0e566..bd9f7912 100644 --- a/resources/lib/LibrarySync.py +++ b/resources/lib/LibrarySync.py @@ -245,17 +245,17 @@ class LibrarySync(): count = 1 # process new episodes - for tvshow in latestMBEpisodes: - if tvshow["SeriesId"] in allKodiTvShowsIds: + for episode in latestMBEpisodes: + if episode["SeriesId"] in allKodiTvShowsIds: #only process tvshows that already exist in the db at incremental updates - kodiEpisodes = ReadKodiDB().getKodiEpisodes(tvshow["SeriesId"]) + kodiEpisodes = ReadKodiDB().getKodiEpisodes(episode["SeriesId"]) if(self.ShouldStop()): return True #we have to compare the lists somehow xbmc.sleep(sleepVal) - comparestring1 = str(tvshow.get("ParentIndexNumber")) + "-" + str(tvshow.get("IndexNumber")) + comparestring1 = str(episode.get("ParentIndexNumber")) + "-" + str(episode.get("IndexNumber")) matchFound = False if kodiEpisodes != None: for KodiItem in kodiEpisodes: @@ -266,7 +266,7 @@ class LibrarySync(): if not matchFound: #no match so we have to create it - WriteKodiDB().addEpisodeToKodiLibrary(tvshow,tvshow) + WriteKodiDB().addEpisodeToKodiLibrary(episode) updateNeeded = True if(self.ShouldStop()): @@ -289,26 +289,24 @@ class LibrarySync(): total = len(latestMBEpisodes) + 1 count = 1 - for tvshow in latestMBEpisodes: - if tvshow["SeriesId"] in allKodiTvShowsIds: + for episode in latestMBEpisodes: + if episode["SeriesId"] in allKodiTvShowsIds: #only process tvshows that already exist in the db at incremental updates - kodiEpisodes = ReadKodiDB().getKodiEpisodes(tvshow["SeriesId"]) + kodiEpisodes = ReadKodiDB().getKodiEpisodes(episode["SeriesId"]) if(self.ShouldStop()): return True #we have to compare the lists somehow xbmc.sleep(sleepVal) - comparestring1 = str(tvshow.get("ParentIndexNumber")) + "-" + str(tvshow.get("IndexNumber")) + comparestring1 = str(episode.get("ParentIndexNumber")) + "-" + str(episode.get("IndexNumber")) if kodiEpisodes != None: for KodiItem in kodiEpisodes: comparestring2 = str(KodiItem["season"]) + "-" + str(KodiItem["episode"]) if comparestring1 == comparestring2: #match found - update episode - #WriteKodiDB().updateEpisodeToKodiLibrary(tvshow,KodiItem,tvshow) - #TODO not sure but how to update the show - print "TODO: Actual do the update" + WriteKodiDB().updateEpisodeToKodiLibrary(episode,KodiItem) if(self.ShouldStop()): @@ -402,14 +400,14 @@ class LibrarySync(): comparestring2 = str(KodiItem["season"]) + "-" + str(KodiItem["episode"]) if comparestring1 == comparestring2: #match found - update episode - WriteKodiDB().updateEpisodeToKodiLibrary(item,KodiItem,tvshow) + WriteKodiDB().updateEpisodeToKodiLibrary(item,KodiItem) matchFound = True progMessage = "Updating" if not matchFound: #no match so we have to create it print "episode not found...creating it: " - WriteKodiDB().addEpisodeToKodiLibrary(item,tvshow) + WriteKodiDB().addEpisodeToKodiLibrary(item) updateNeeded = True progMessage = "Adding" diff --git a/resources/lib/WriteKodiDB.py b/resources/lib/WriteKodiDB.py index 5138cd47..24df1357 100644 --- a/resources/lib/WriteKodiDB.py +++ b/resources/lib/WriteKodiDB.py @@ -219,7 +219,7 @@ class WriteKodiDB(): utils.logMsg("Updated item to Kodi Library", MBitem["Id"] + " - " + MBitem["Name"]) - def updateEpisodeToKodiLibrary( self, MBitem, KodiItem, tvshowId ): + def updateEpisodeToKodiLibrary( self, MBitem, KodiItem ): addon = xbmcaddon.Addon(id='plugin.video.mb3sync') port = addon.getSetting('port') @@ -271,8 +271,8 @@ class WriteKodiDB(): #add actors changes = self.AddActorsToMedia(KodiItem,MBitem.get("People"),"episode") - CreateFiles().createNFO(MBitem, tvshowId) - CreateFiles().createSTRM(MBitem, tvshowId) + CreateFiles().createNFO(MBitem) + CreateFiles().createSTRM(MBitem) if changes: utils.logMsg("Updated item to Kodi Library", MBitem["Id"] + " - " + MBitem["Name"]) @@ -394,15 +394,15 @@ class WriteKodiDB(): if changes: utils.logMsg("MB3 Sync","Added movie to Kodi Library",item["Id"] + " - " + item["Name"]) - def addEpisodeToKodiLibrary(self, item, tvshowId): + def addEpisodeToKodiLibrary(self, item): changes = False #create nfo file - changes = CreateFiles().createNFO(item, tvshowId) + changes = CreateFiles().createNFO(item) # create strm file - changes = CreateFiles().createSTRM(item, tvshowId) + changes = CreateFiles().createSTRM(item) if changes: utils.logMsg("MB3 Sync","Added episode to Kodi Library",item["Id"] + " - " + item["Name"])