From eb1214f0c721c2a03677ae83f68e4b5c8d55c43b Mon Sep 17 00:00:00 2001 From: croneter Date: Sun, 14 Apr 2019 14:20:03 +0200 Subject: [PATCH] New setting to reloade Plex video nodes --- default.py | 4 +++ .../resource.language.en_gb/strings.po | 5 +++ resources/lib/library_sync/sections.py | 15 +++++++++ resources/lib/service_entry.py | 31 +++++++++++++++++++ resources/settings.xml | 2 ++ 5 files changed, 57 insertions(+) diff --git a/default.py b/default.py index b4483c4c..131c923a 100644 --- a/default.py +++ b/default.py @@ -138,6 +138,10 @@ class Main(): LOG.info('User requested to select Plex libraries') transfer.plex_command('select-libraries') + elif mode == 'refreshplaylist': + LOG.info('User requested to refresh Kodi playlists and nodes') + transfer.plex_command('refreshplaylist') + else: entrypoint.show_main_menu(content_type=params.get('content_type')) diff --git a/resources/language/resource.language.en_gb/strings.po b/resources/language/resource.language.en_gb/strings.po index ba4650ea..69dc13e1 100644 --- a/resources/language/resource.language.en_gb/strings.po +++ b/resources/language/resource.language.en_gb/strings.po @@ -1102,6 +1102,11 @@ msgctxt "#39084" msgid "Enter PMS port" msgstr "" +# PKC settings - Appearance Tweaks +msgctxt "#39085" +msgid "Reload Kodi node files to apply all the settings below" +msgstr "" + msgctxt "#39200" msgid "Log-out Plex Home User " msgstr "" diff --git a/resources/lib/library_sync/sections.py b/resources/lib/library_sync/sections.py index b37a32f4..f08a32f3 100644 --- a/resources/lib/library_sync/sections.py +++ b/resources/lib/library_sync/sections.py @@ -644,7 +644,22 @@ def clear_window_vars(): """ Removes all references to sections stored in window vars 'Plex.nodes...' """ + LOG.info('Clearing all the Plex video node variables') number_of_nodes = int(utils.window('Plex.nodes.total') or 0) utils.window('Plex.nodes.total', clear=True) for index in range(number_of_nodes): _clear_window_vars(index) + + +def delete_videonode_files(): + """ + Removes all the PKC video node files under userdata/library/video that + start with 'Plex-' + """ + for root, dirs, _ in path_ops.walk(LIBRARY_PATH): + for directory in dirs: + if directory.startswith('Plex-'): + abs_path = path_ops.path.join(root, directory) + LOG.info('Removing video node directory %s', abs_path) + path_ops.rmtree(abs_path, ignore_errors=True) + break diff --git a/resources/lib/service_entry.py b/resources/lib/service_entry.py index fa929595..a1243e93 100644 --- a/resources/lib/service_entry.py +++ b/resources/lib/service_entry.py @@ -302,6 +302,35 @@ class Service(object): finally: app.APP.resume_threads() + def reset_playlists_and_nodes(self): + """ + Resets the Kodi playlists and nodes for all the PKC libraries by + deleting all of them first, then rewriting everything + """ + app.APP.suspend_threads() + from .library_sync import sections + try: + sections.clear_window_vars() + sections.delete_videonode_files() + # Get newest sections from the PMS + if not sections.sync_from_pms(self, pick_libraries=False): + LOG.warn('We could not successfully reset the playlists!') + # "Plex playlists/nodes refresh failed" + utils.dialog('notification', + utils.lang(29999), + utils.lang(39406), + icon='{plex}', + sound=False) + return + # "Plex playlists/nodes refreshed" + utils.dialog('notification', + utils.lang(29999), + utils.lang(39405), + icon='{plex}', + sound=False) + finally: + app.APP.resume_threads() + def _do_auth(self): LOG.info('Authenticating user') if app.ACCOUNT.plex_username and not app.ACCOUNT.force_login: # Found a user in the settings, try to authenticate @@ -449,6 +478,8 @@ class Service(object): app.SYNC.run_lib_scan = 'textures' elif plex_command == 'select-libraries': self.choose_plex_libraries() + elif plex_command == 'refreshplaylist': + self.reset_playlists_and_nodes() elif plex_command == 'RESET-PKC': utils.reset() elif plex_command == 'EXIT-PKC': diff --git a/resources/settings.xml b/resources/settings.xml index d1fc8f1e..b68c8bfe 100644 --- a/resources/settings.xml +++ b/resources/settings.xml @@ -157,6 +157,8 @@ --> + +