From ce9a72e7567ccb2e178ae9a2e0ec4558a6483aaf Mon Sep 17 00:00:00 2001 From: angelblue05 Date: Wed, 23 Jan 2019 12:28:14 -0600 Subject: [PATCH 1/3] Adjust subtitles behavior --- resources/lib/helper/playutils.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/resources/lib/helper/playutils.py b/resources/lib/helper/playutils.py index fd525d5f..9af3a72d 100644 --- a/resources/lib/helper/playutils.py +++ b/resources/lib/helper/playutils.py @@ -466,10 +466,10 @@ class PlayUtils(object): for stream in source['MediaStreams']: - if stream['Type'] == 'Subtitle' and stream['IsExternal'] and stream['IsTextSubtitleStream']: + if stream['Type'] == 'Subtitle' and stream['IsExternal']: index = stream['Index'] - if 'DeliveryUrl' in stream and stream['DeliveryUrl'].lower().startswith('http'): + if 'DeliveryUrl' in stream and stream['DeliveryUrl'].lower().startswith('/videos'): url = "%s/emby%s" % (self.info['ServerAddress'], stream['DeliveryUrl']) else: url = self.get_subtitles(source, stream, index) @@ -625,7 +625,7 @@ class PlayUtils(object): def get_subtitles(self, source, stream, index): - if 'DeliveryUrl' in stream and stream['DeliveryUrl'].lower().startswith('http'): + if stream['IsTextSubtitleStream'] and 'DeliveryUrl' in stream and stream['DeliveryUrl'].lower().startswith('/videos'): url = "%s/emby%s" % (self.info['ServerAddress'], stream['DeliveryUrl']) else: url = ("%s/emby/Videos/%s/%s/Subtitles/%s/Stream.%s?api_key=%s" % From 50c2b8153e36750665bcda7c4ea49b945f296f22 Mon Sep 17 00:00:00 2001 From: angelblue05 Date: Wed, 23 Jan 2019 18:13:32 -0600 Subject: [PATCH 2/3] Fix string typo --- resources/language/resource.language.en_gb/strings.po | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/language/resource.language.en_gb/strings.po b/resources/language/resource.language.en_gb/strings.po index a0f99277..a43bf70d 100644 --- a/resources/language/resource.language.en_gb/strings.po +++ b/resources/language/resource.language.en_gb/strings.po @@ -223,7 +223,7 @@ msgid "Verify connection" msgstr "" msgctxt "#30504" -msgid "Use altername device name" +msgid "Use alternate device name" msgstr "" msgctxt "#30506" From 48b2cf731547ad48fc5ae700ad19bb72feb96497 Mon Sep 17 00:00:00 2001 From: angelblue05 Date: Wed, 23 Jan 2019 18:40:36 -0600 Subject: [PATCH 3/3] Only run one full sync instance Prevent user from launching multiple syncs and freezing the add-on. --- .../resource.language.en_gb/strings.po | 4 ++ resources/lib/full_sync.py | 61 ++++++++++++------- 2 files changed, 44 insertions(+), 21 deletions(-) diff --git a/resources/language/resource.language.en_gb/strings.po b/resources/language/resource.language.en_gb/strings.po index a43bf70d..897396a3 100644 --- a/resources/language/resource.language.en_gb/strings.po +++ b/resources/language/resource.language.en_gb/strings.po @@ -945,3 +945,7 @@ msgstr "" msgctxt "#33196" msgid "Advanced options" msgstr "" + +msgctxt "#33197" +msgid "A sync is already running, please wait until it completes and try again." +msgstr "" diff --git a/resources/lib/full_sync.py b/resources/lib/full_sync.py index 921bce82..cf3bbd79 100644 --- a/resources/lib/full_sync.py +++ b/resources/lib/full_sync.py @@ -27,39 +27,55 @@ LOG = logging.getLogger("EMBY."+__name__) class FullSync(object): + # Borg - multiple instances, shared state + _shared_state = {} sync = None + running = False def __init__(self, library, library_id=None, update=False): - self.library = library - self.direct_path = settings('useDirectPaths') == "1" - self.update_library = update - self.server = Emby() - self.sync = get_sync() + ''' Map the syncing process and start the sync. Ensure only one sync is running. + ''' + self.__dict__ = self._shared_state - if library_id: - libraries = library_id.split(',') + if not self.running: - for selected in libraries: + self.running = True + self.library = library + self.direct_path = settings('useDirectPaths') == "1" + self.update_library = update + self.server = Emby() + self.sync = get_sync() - if selected not in [x.replace('Mixed:', "") for x in self.sync['Libraries']]: - library = self.get_libraries(selected) + if library_id: + libraries = library_id.split(',') - if library: + for selected in libraries: - self.sync['Libraries'].append("Mixed:%s" % selected if library[1] == 'mixed' else selected) + if selected not in [x.replace('Mixed:', "") for x in self.sync['Libraries']]: + library = self.get_libraries(selected) - if library[1] in ('mixed', 'movies'): - self.sync['Libraries'].append('Boxsets:%s' % selected) - else: - self.sync['Libraries'].append(selected) + if library: + + self.sync['Libraries'].append("Mixed:%s" % selected if library[1] == 'mixed' else selected) + + if library[1] in ('mixed', 'movies'): + self.sync['Libraries'].append('Boxsets:%s' % selected) + else: + self.sync['Libraries'].append(selected) + else: + self.mapping() + + xmls.sources() + + if not xmls.advanced_settings() and self.sync['Libraries']: + self.start() + else: + self.running = False else: - self.mapping() + dialog("ok", heading="{emby}", line1=_(33197)) - xmls.sources() - - if not xmls.advanced_settings() and self.sync['Libraries']: - self.start() + raise Exception("Sync is already running.") def get_libraries(self, library_id=None): @@ -169,6 +185,8 @@ class FullSync(object): xbmc.executebuiltin('InhibitIdleShutdown(false)') set_screensaver(value=screensaver) + self.running = False + raise elapsed = datetime.datetime.now() - start_time @@ -180,6 +198,7 @@ class FullSync(object): dialog("notification", heading="{emby}", message="%s %s" % (_(33025), str(elapsed).split('.')[0]), icon="{emby}", sound=False) LOG.info("Full sync completed in: %s", str(elapsed).split('.')[0]) + self.running = False def process_library(self, library_id):