From 6eba8db57ab5e7b38d38aa4d2879400867cc8ae1 Mon Sep 17 00:00:00 2001 From: Marcel van der Veldt Date: Fri, 20 Mar 2015 11:08:22 +0100 Subject: [PATCH] improvement to tvshows sync: also process updates at tv show level at first sync --- resources/lib/CreateFiles.py | 5 ++++- resources/lib/LibrarySync.py | 42 +++++++++++++++++++++++++----------- resources/lib/ReadKodiDB.py | 4 +--- resources/lib/WriteKodiDB.py | 2 +- 4 files changed, 36 insertions(+), 17 deletions(-) diff --git a/resources/lib/CreateFiles.py b/resources/lib/CreateFiles.py index 0f8a4ca4..ef2a266b 100644 --- a/resources/lib/CreateFiles.py +++ b/resources/lib/CreateFiles.py @@ -119,7 +119,10 @@ class CreateFiles(): if seasonData != None: for season in seasonData: if season.has_key("IndexNumber"): - SubElement(root, "thumb",{"type":"season","season":str(season["IndexNumber"])}).text = API().getArtwork(season, "Primary") + seasonart = API().getArtwork(season, "Primary") + if seasonart == None: + seasonart = API().getArtwork(item, "Primary") + SubElement(root, "thumb",{"type":"season","season":str(season["IndexNumber"])}).text = seasonart SubElement(root, "thumb",{"type":"season","season":"0"}).text = API().getArtwork(item, "Primary") SubElement(root, "fanart").text = API().getArtwork(item, "Backdrop") diff --git a/resources/lib/LibrarySync.py b/resources/lib/LibrarySync.py index a2ee5e5c..19467b14 100644 --- a/resources/lib/LibrarySync.py +++ b/resources/lib/LibrarySync.py @@ -324,7 +324,7 @@ class LibrarySync(): allEpisodes = list() #FIXME --> for now pull all tv shows and use the incremental update only at episode level tvShowData = ReadEmbyDB().getTVShows(True,True) - + allKodiIds = set(ReadKodiDB().getKodiTvShowsIds(True)) updateNeeded = False if(self.ShouldStop(pDialog)): @@ -341,16 +341,11 @@ class LibrarySync(): for item in tvShowData: if item.get('IsFolder'): - kodiItem = ReadKodiDB().getKodiTVShow(item["Id"]) allTVShows.append(item["Id"]) progMessage = "Processing" - if kodiItem == None: - WriteKodiDB().addTVShowToKodiLibrary(item) + if item["Id"] not in allKodiIds: + WriteKodiDB().addMovieToKodiLibrary(item) updateNeeded = True - progMessage = "Adding" - else: - WriteKodiDB().updateTVShowToKodiLibrary(item, kodiItem) - progMessage = "Updating" if(self.ShouldStop(pDialog)): return True @@ -358,7 +353,7 @@ class LibrarySync(): # update progress bar if(pDialog != None): percentage = int(((float(count) / float(total)) * 100)) - pDialog.update(percentage, progressTitle, progMessage + " Tv Show: " + str(count)) + pDialog.update(percentage, progressTitle, "Adding Tv Show: " + str(count)) count += 1 #initiate library update and wait for finish before processing any updates @@ -373,9 +368,32 @@ class LibrarySync(): if(pDialog != None and type(pDialog) == xbmcgui.DialogProgressBG): pDialog.create('Sync DB', 'Sync DB') - - #process episodes (will only be possible when tv show is scanned to library) - #TODO --> maybe pull full info only when needed ? + if(pDialog != None): + progressTitle = "Sync DB : Processing TV Shows" + pDialog.update(0, progressTitle, "") + total = len(allMB3Movies) + 1 + count = 1 + + #process updates at TV Show level + allKodiTVShows = ReadKodiDB().getKodiTvShows(True) + for item in tvShowData: + if item.get('IsFolder'): + + kodishow = allKodiTVShows.get(item["Id"],None) + + if(kodishow != None): + WriteKodiDB().updateTVShowToKodiLibrary(item,kodishow) + + if(self.ShouldStop(pDialog)): + return True + + # update progress bar + if(pDialog != None): + percentage = int(((float(count) / float(total)) * 100)) + pDialog.update(percentage, progressTitle, "Updating Tv Show: " + str(count)) + count += 1 + + #process episodes allEpisodes = list() showTotal = len(allTVShows) diff --git a/resources/lib/ReadKodiDB.py b/resources/lib/ReadKodiDB.py index e5b78a87..51aa5399 100644 --- a/resources/lib/ReadKodiDB.py +++ b/resources/lib/ReadKodiDB.py @@ -94,9 +94,7 @@ class ReadKodiDB(): allKodiTvShowsIds.append(id) return allKodiTvShowsIds - - - + def getKodiTvShows(self,fullInfo = False): #returns all tvshows in Kodi db inserted by MB xbmc.sleep(sleepVal) diff --git a/resources/lib/WriteKodiDB.py b/resources/lib/WriteKodiDB.py index af31e604..cc133413 100644 --- a/resources/lib/WriteKodiDB.py +++ b/resources/lib/WriteKodiDB.py @@ -176,7 +176,7 @@ class WriteKodiDB(): changes = False #update artwork - #changes |= self.updateArtWork(KodiItem,"poster", API().getArtwork(MBitem, "Primary"),"tvshow") + changes |= self.updateArtWork(KodiItem,"poster", API().getArtwork(MBitem, "Primary"),"tvshow") changes |= self.updateArtWork(KodiItem,"clearlogo", API().getArtwork(MBitem, "Logo"),"tvshow") changes |= self.updateArtWork(KodiItem,"clearart", API().getArtwork(MBitem, "Art"),"tvshow") changes |= self.updateArtWork(KodiItem,"banner", API().getArtwork(MBitem, "Banner"),"tvshow")