From d1da07a8bf56d023196705a132ab597b18e2946d Mon Sep 17 00:00:00 2001 From: tomkat83 Date: Sat, 3 Dec 2016 15:43:23 +0100 Subject: [PATCH] Speed up replacing Plex paths --- resources/lib/PlexAPI.py | 33 +++++++++++---------------------- resources/lib/PlexFunctions.py | 14 ++++++++++++++ resources/lib/kodimonitor.py | 12 ++++++++++-- resources/lib/librarysync.py | 7 +++++++ resources/settings.xml | 1 - 5 files changed, 42 insertions(+), 25 deletions(-) diff --git a/resources/lib/PlexAPI.py b/resources/lib/PlexAPI.py index 01d9ea08..24d5e7d9 100644 --- a/resources/lib/PlexAPI.py +++ b/resources/lib/PlexAPI.py @@ -49,7 +49,8 @@ import clientinfo import downloadutils from utils import window, settings, language as lang, tryDecode, tryEncode, \ DateToKodi, KODILANGUAGE -from PlexFunctions import PLEX_TO_KODI_TIMEFACTOR, PMSHttpsEnabled +from PlexFunctions import PLEX_TO_KODI_TIMEFACTOR, PMSHttpsEnabled, \ + REMAP_TYPE_FROM_PLEXTYPE import embydb_functions as embydb ############################################################################### @@ -2515,29 +2516,17 @@ class API(): """ if path is None: return None - types = { - 'movie': 'movie', - 'show': 'tv', - 'season': 'tv', - 'episode': 'tv', - 'artist': 'music', - 'album': 'music', - 'song': 'music', - 'track': 'music', - 'clip': 'clip', - 'photo': 'photo' - } - typus = types[typus] - if settings('remapSMB') == 'true': - path = path.replace(settings('remapSMB%sOrg' % typus), - settings('remapSMB%sNew' % typus), + typus = REMAP_TYPE_FROM_PLEXTYPE[typus] + if window('remapSMB') == 'true': + path = path.replace(window('remapSMB%sOrg' % typus), + window('remapSMB%sNew' % typus), 1) # There might be backslashes left over: path = path.replace('\\', '/') - elif settings('replaceSMB') == 'true': + elif window('replaceSMB') == 'true': if path.startswith('\\\\'): path = 'smb:' + path.replace('\\', '/') - if settings('plex_pathverified') == 'true' and forceCheck is False: + if window('plex_pathverified') == 'true' and forceCheck is False: return path # exist() needs a / or \ at the end to work for directories @@ -2558,12 +2547,12 @@ class API(): if self.askToValidate(path): window('plex_shouldStop', value="true") path = None - settings('plex_pathverified', value='true') + window('plex_pathverified', value='true') else: path = None elif forceCheck is False: - if settings('plex_pathverified') != 'true': - settings('plex_pathverified', value='true') + if window('plex_pathverified') != 'true': + window('plex_pathverified', value='true') return path def askToValidate(self, url): diff --git a/resources/lib/PlexFunctions.py b/resources/lib/PlexFunctions.py index 70776f38..6f77546b 100644 --- a/resources/lib/PlexFunctions.py +++ b/resources/lib/PlexFunctions.py @@ -61,6 +61,20 @@ KODITYPE_FROM_PLEXTYPE = { } +REMAP_TYPE_FROM_PLEXTYPE = { + 'movie': 'movie', + 'show': 'tv', + 'season': 'tv', + 'episode': 'tv', + 'artist': 'music', + 'album': 'music', + 'song': 'music', + 'track': 'music', + 'clip': 'clip', + 'photo': 'photo' +} + + def ConvertPlexToKodiTime(plexTime): """ Converts Plextime to Koditime. Returns an int (in seconds). diff --git a/resources/lib/kodimonitor.py b/resources/lib/kodimonitor.py index d81e705e..8898e25f 100644 --- a/resources/lib/kodimonitor.py +++ b/resources/lib/kodimonitor.py @@ -13,7 +13,7 @@ import embydb_functions as embydb import kodidb_functions as kodidb import playbackutils as pbutils from utils import window, settings, CatchExceptions, tryDecode, tryEncode -from PlexFunctions import scrobble +from PlexFunctions import scrobble, REMAP_TYPE_FROM_PLEXTYPE ############################################################################### @@ -50,8 +50,16 @@ class KodiMonitor(xbmc.Monitor): 'logLevel': 'plex_logLevel', 'enableContext': 'plex_context', 'plex_restricteduser': 'plex_restricteduser', - 'dbSyncIndicator': 'dbSyncIndicator' + 'dbSyncIndicator': 'dbSyncIndicator', + 'remapSMB': 'remapSMB', + 'replaceSMB': 'replaceSMB', } + # Path replacement + for typus in REMAP_TYPE_FROM_PLEXTYPE.values(): + for arg in ('Org', 'New'): + key = 'remapSMB%s%s' % (typus, arg) + items[key] = key + # Reset the window variables from the settings variables for settings_value, window_value in items.iteritems(): if window(window_value) != settings(settings_value): log.debug('PKC settings changed: %s is now %s' diff --git a/resources/lib/librarysync.py b/resources/lib/librarysync.py index f5513930..30585170 100644 --- a/resources/lib/librarysync.py +++ b/resources/lib/librarysync.py @@ -392,6 +392,13 @@ class LibrarySync(Thread): 'enableBackgroundSync') == "true" self.limitindex = int(settings('limitindex')) + # Init for replacing paths + window('remapSMB', value=settings('remapSMB')) + window('replaceSMB', value=settings('replaceSMB')) + for typus in PF.REMAP_TYPE_FROM_PLEXTYPE.values(): + for arg in ('Org', 'New'): + key = 'remapSMB%s%s' % (typus, arg) + window(key, value=settings(key)) # Just in case a time sync goes wrong self.timeoffset = int(settings('kodiplextimeoffset')) window('kodiplextimeoffset', value=str(self.timeoffset)) diff --git a/resources/settings.xml b/resources/settings.xml index dd533c4a..e7ddcf5e 100644 --- a/resources/settings.xml +++ b/resources/settings.xml @@ -68,7 +68,6 @@ -