Rewire Kodi library refreshs

This commit is contained in:
croneter 2018-10-06 14:40:14 +02:00
parent 9f35e1d99e
commit 8e1b3444ac

View file

@ -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']) @utils.thread_methods(add_suspends=['SUSPEND_LIBRARY_THREAD', 'STOP_SYNC'])
class LibrarySync(Thread): class LibrarySync(Thread):
""" """
@ -58,8 +77,8 @@ class LibrarySync(Thread):
# Need to be set accordingly later # Need to be set accordingly later
self.compare = None self.compare = None
self.new_items_only = None self.new_items_only = None
self.update_kodi_video_library = None self.update_kodi_video_library = False
self.update_kodi_music_library = None self.update_kodi_music_library = False
self.nodes = {} self.nodes = {}
self.playlists = {} self.playlists = {}
self.sorted_views = [] self.sorted_views = []
@ -288,9 +307,7 @@ class LibrarySync(Thread):
return False return False
# Let kodi update the views in any case, since we're doing a full sync # Let kodi update the views in any case, since we're doing a full sync
xbmc.executebuiltin('UpdateLibrary(video)') update_library(video=True, music=state.ENABLE_MUSIC)
if state.ENABLE_MUSIC:
xbmc.executebuiltin('UpdateLibrary(music)')
if utils.window('plex_scancrashed') == 'true': if utils.window('plex_scancrashed') == 'true':
# Show warning if itemtypes.py crashed at some point # Show warning if itemtypes.py crashed at some point
@ -1081,8 +1098,6 @@ class LibrarySync(Thread):
6: 'analyzing', 6: 'analyzing',
9: 'deleted' 9: 'deleted'
""" """
self.update_kodi_video_library = False
self.update_kodi_music_library = False
now = utils.unix_timestamp() now = utils.unix_timestamp()
delete_list = [] delete_list = []
for i, item in enumerate(self.items_to_process): 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, self.items_to_process = self.multi_delete(self.items_to_process,
delete_list) delete_list)
# Let Kodi know of the change # Let Kodi know of the change
if self.update_kodi_video_library is True: if self.update_kodi_video_library or self.update_kodi_music_library:
LOG.info("Doing Kodi Video Lib update") update_library(video=self.update_kodi_video_library,
xbmc.executebuiltin('UpdateLibrary(video)') music=self.update_kodi_music_library)
if self.update_kodi_music_library is True: self.update_kodi_video_library = False
LOG.info("Doing Kodi Music Lib update") self.update_kodi_music_library = False
xbmc.executebuiltin('UpdateLibrary(music)')
def process_newitems(self, item): def process_newitems(self, item):
xml = PF.GetPlexMetadata(item['ratingKey']) xml = PF.GetPlexMetadata(item['ratingKey'])
@ -1378,6 +1392,10 @@ class LibrarySync(Thread):
utils.unix_date_to_kodi( utils.unix_date_to_kodi(
utils.unix_timestamp()), utils.unix_timestamp()),
plex_type) 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): def sync_fanart(self, missing_only=True, refresh=False):
""" """