diff --git a/resources/lib/kodimonitor.py b/resources/lib/kodimonitor.py index 7686d734..d81e705e 100644 --- a/resources/lib/kodimonitor.py +++ b/resources/lib/kodimonitor.py @@ -49,7 +49,8 @@ class KodiMonitor(xbmc.Monitor): items = { 'logLevel': 'plex_logLevel', 'enableContext': 'plex_context', - 'plex_restricteduser': 'plex_restricteduser' + 'plex_restricteduser': 'plex_restricteduser', + 'dbSyncIndicator': 'dbSyncIndicator' } for settings_value, window_value in items.iteritems(): if window(window_value) != settings(settings_value): diff --git a/resources/lib/librarysync.py b/resources/lib/librarysync.py index 01677a05..f5513930 100644 --- a/resources/lib/librarysync.py +++ b/resources/lib/librarysync.py @@ -386,7 +386,7 @@ class LibrarySync(Thread): self.syncThreadNumber = int(settings('syncThreadNumber')) self.installSyncDone = settings('SyncInstallRunDone') == 'true' - self.showDbSync = settings('dbSyncIndicator') == 'true' + window('dbSyncIndicator', value=settings('dbSyncIndicator')) self.enableMusic = settings('enableMusic') == "true" self.enableBackgroundSync = settings( 'enableBackgroundSync') == "true" @@ -560,18 +560,32 @@ class LibrarySync(Thread): # True: we're syncing only the delta, e.g. different checksum self.compare = not repair + self.new_items_only = True + log.info('Running fullsync for NEW PMS items with rapair=%s' % repair) + if self._fullSync() is False: + return False + self.new_items_only = False + log.info('Running fullsync for CHANGED PMS items with repair=%s' + % repair) + if self._fullSync() is False: + return False + return True + + def _fullSync(self): xbmc.executebuiltin('InhibitIdleShutdown(true)') screensaver = getScreensaver() setScreensaver(value="") - # Add sources - sourcesXML() + if self.new_items_only is True: + # Only do the following once for new items + # Add sources + sourcesXML() - # Set views. Abort if unsuccessful - if not self.maintainViews(): - xbmc.executebuiltin('InhibitIdleShutdown(false)') - setScreensaver(value=screensaver) - return False + # Set views. Abort if unsuccessful + if not self.maintainViews(): + xbmc.executebuiltin('InhibitIdleShutdown(false)') + setScreensaver(value=screensaver) + return False process = { 'movies': self.PlexMovies, @@ -864,14 +878,34 @@ class LibrarySync(Thread): self.allPlexElementsId APPENDED(!!) dict = {itemid: checksum} """ + if self.new_items_only is True: + # Only process Plex items that Kodi does not already have in lib + for item in xml: + itemId = item.attrib.get('ratingKey') + if not itemId: + # Skipping items 'title=All episodes' without a 'ratingKey' + continue + self.allPlexElementsId[itemId] = ("K%s%s" % + (itemId, item.attrib.get('updatedAt', ''))) + if itemId not in self.allKodiElementsId: + self.updatelist.append({ + 'itemId': itemId, + 'itemType': itemType, + 'method': method, + 'viewName': viewName, + 'viewId': viewId, + 'title': item.attrib.get('title', 'Missing Title'), + 'mediaType': item.attrib.get('type') + }) + return + if self.compare: # Only process the delta - new or changed items for item in xml: itemId = item.attrib.get('ratingKey') - # Skipping items 'title=All episodes' without a 'ratingKey' if not itemId: + # Skipping items 'title=All episodes' without a 'ratingKey' continue - title = item.attrib.get('title', 'Missing Title Name') plex_checksum = ("K%s%s" % (itemId, item.attrib.get('updatedAt', ''))) self.allPlexElementsId[itemId] = plex_checksum @@ -885,31 +919,29 @@ class LibrarySync(Thread): 'method': method, 'viewName': viewName, 'viewId': viewId, - 'title': title, + 'title': item.attrib.get('title', 'Missing Title'), 'mediaType': item.attrib.get('type') }) else: # Initial or repair sync: get all Plex movies for item in xml: itemId = item.attrib.get('ratingKey') - # Skipping items 'title=All episodes' without a 'ratingKey' if not itemId: + # Skipping items 'title=All episodes' without a 'ratingKey' continue - title = item.attrib.get('title', 'Missing Title Name') - plex_checksum = ("K%s%s" - % (itemId, item.attrib.get('updatedAt', ''))) - self.allPlexElementsId[itemId] = plex_checksum + self.allPlexElementsId[itemId] = ("K%s%s" + % (itemId, item.attrib.get('updatedAt', ''))) self.updatelist.append({ 'itemId': itemId, 'itemType': itemType, 'method': method, 'viewName': viewName, 'viewId': viewId, - 'title': title, + 'title': item.attrib.get('title', 'Missing Title'), 'mediaType': item.attrib.get('type') }) - def GetAndProcessXMLs(self, itemType, showProgress=True): + def GetAndProcessXMLs(self, itemType): """ Downloads all XMLs for itemType (e.g. Movies, TV-Shows). Processes them by then calling itemtypes.() @@ -961,19 +993,18 @@ class LibrarySync(Thread): thread.start() threads.append(thread) log.info("Processing thread spawned") - # Start one thread to show sync progress - if showProgress: - if self.showDbSync: - dialog = xbmcgui.DialogProgressBG() - thread = ThreadedShowSyncInfo( - dialog, - [getMetadataLock, processMetadataLock], - itemNumber, - itemType) - thread.setDaemon(True) - thread.start() - threads.append(thread) - log.info("Kodi Infobox thread spawned") + # Start one thread to show sync progress ONLY for new PMS items + if self.new_items_only is True and window('dbSyncIndicator') == 'true': + dialog = xbmcgui.DialogProgressBG() + thread = ThreadedShowSyncInfo( + dialog, + [getMetadataLock, processMetadataLock], + itemNumber, + itemType) + thread.setDaemon(True) + thread.start() + threads.append(thread) + log.info("Kodi Infobox thread spawned") # Wait until finished getMetadataQueue.join()