From 8e1b3444ac94632b3b86498defe0bde846b34b65 Mon Sep 17 00:00:00 2001 From: croneter Date: Sat, 6 Oct 2018 14:40:14 +0200 Subject: [PATCH] Rewire Kodi library refreshs --- resources/lib/librarysync.py | 44 +++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/resources/lib/librarysync.py b/resources/lib/librarysync.py index 8209b0ca..b068d30a 100644 --- a/resources/lib/librarysync.py +++ b/resources/lib/librarysync.py @@ -39,6 +39,25 @@ LOG = getLogger('PLEX.librarysync') ############################################################################### +def update_library(video=True, music=True): + """ + Updates the Kodi library and thus refreshes the Kodi views and widgets + """ + if xbmc.getCondVisibility('Container.Content(musicvideos)') or \ + xbmc.getCondVisibility('Window.IsMedia'): + # Prevent cursor from moving + LOG.debug("Refreshing container") + xbmc.executebuiltin('Container.Refresh') + else: + # Update widgets + if video: + LOG.debug("Doing Kodi Video Lib update") + xbmc.executebuiltin('UpdateLibrary(video)') + if music: + LOG.debug("Doing Kodi Music Lib update") + xbmc.executebuiltin('UpdateLibrary(music)') + + @utils.thread_methods(add_suspends=['SUSPEND_LIBRARY_THREAD', 'STOP_SYNC']) class LibrarySync(Thread): """ @@ -58,8 +77,8 @@ class LibrarySync(Thread): # Need to be set accordingly later self.compare = None self.new_items_only = None - self.update_kodi_video_library = None - self.update_kodi_music_library = None + self.update_kodi_video_library = False + self.update_kodi_music_library = False self.nodes = {} self.playlists = {} self.sorted_views = [] @@ -288,9 +307,7 @@ class LibrarySync(Thread): return False # Let kodi update the views in any case, since we're doing a full sync - xbmc.executebuiltin('UpdateLibrary(video)') - if state.ENABLE_MUSIC: - xbmc.executebuiltin('UpdateLibrary(music)') + update_library(video=True, music=state.ENABLE_MUSIC) if utils.window('plex_scancrashed') == 'true': # Show warning if itemtypes.py crashed at some point @@ -1081,8 +1098,6 @@ class LibrarySync(Thread): 6: 'analyzing', 9: 'deleted' """ - self.update_kodi_video_library = False - self.update_kodi_music_library = False now = utils.unix_timestamp() delete_list = [] for i, item in enumerate(self.items_to_process): @@ -1119,12 +1134,11 @@ class LibrarySync(Thread): self.items_to_process = self.multi_delete(self.items_to_process, delete_list) # Let Kodi know of the change - if self.update_kodi_video_library is True: - LOG.info("Doing Kodi Video Lib update") - xbmc.executebuiltin('UpdateLibrary(video)') - if self.update_kodi_music_library is True: - LOG.info("Doing Kodi Music Lib update") - xbmc.executebuiltin('UpdateLibrary(music)') + if self.update_kodi_video_library or self.update_kodi_music_library: + update_library(video=self.update_kodi_video_library, + music=self.update_kodi_music_library) + self.update_kodi_video_library = False + self.update_kodi_music_library = False def process_newitems(self, item): xml = PF.GetPlexMetadata(item['ratingKey']) @@ -1378,6 +1392,10 @@ class LibrarySync(Thread): utils.unix_date_to_kodi( utils.unix_timestamp()), plex_type) + if plex_type in (v.PLEX_TYPE_MOVIE, v.PLEX_TYPE_EPISODE): + update_library(video=True, music=False) + elif plex_type == v.PLEX_TYPE_SONG: + update_library(video=False, music=True) def sync_fanart(self, missing_only=True, refresh=False): """