From 33ba485b0bd2ae57963ce6d73db20b3c0535d403 Mon Sep 17 00:00:00 2001 From: angelblue05 Date: Thu, 29 Sep 2016 01:59:30 -0500 Subject: [PATCH] Update window property If .json in property name, it will automatically apply json.loads/dumps. This is to avoid importing json in every files. --- resources/lib/downloadutils.py | 6 +++--- resources/lib/entrypoint.py | 3 +-- resources/lib/userclient.py | 2 +- resources/lib/utils.py | 13 +++++++++---- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/resources/lib/downloadutils.py b/resources/lib/downloadutils.py index 1f90ec72..066faa46 100644 --- a/resources/lib/downloadutils.py +++ b/resources/lib/downloadutils.py @@ -49,7 +49,7 @@ class DownloadUtils(object): info[key] = kwargs[key] self.session.update(info) - window('emby_server.json', value=json.dumps(self.session)) + window('emby_server.json', value=self.session) log.debug("Set info for server %s: %s", self.session['ServerId'], self.session) @@ -66,7 +66,7 @@ class DownloadUtils(object): if s == server_id: s.update(info) # Set window prop - self._set_server_properties(server_id, server['Name'], json.dumps(info)) + self._set_server_properties(server_id, server['Name'], info) log.info("updating %s to available servers: %s", server_id, self.servers) break else: @@ -351,7 +351,7 @@ class DownloadUtils(object): server = window('emby_server%s.json' % server_id) if server: - info.update(json.loads(server)) + info.update(server) return info diff --git a/resources/lib/entrypoint.py b/resources/lib/entrypoint.py index aa33ffec..fea42ceb 100644 --- a/resources/lib/entrypoint.py +++ b/resources/lib/entrypoint.py @@ -98,9 +98,8 @@ def doMainListing(): ''' TODO: Create plugin listing for servers - servers = window('emby_servers') + servers = window('emby_servers.json') if servers: - servers = json.loads(servers) for server in servers: log.info(window('emby_server%s.name' % server)) addDirectoryItem(window('emby_server%s.name' % server), "plugin://plugin.video.emby/?mode=%s" % server)''' diff --git a/resources/lib/userclient.py b/resources/lib/userclient.py index cca36332..5c103aa9 100644 --- a/resources/lib/userclient.py +++ b/resources/lib/userclient.py @@ -249,7 +249,7 @@ class UserClient(threading.Thread): # Set properties log.info(added_servers) - window('emby_servers', value=json.dumps(added_servers)) + window('emby_servers.json', value=added_servers) def _reset_client(self): diff --git a/resources/lib/utils.py b/resources/lib/utils.py index b1850682..f24941db 100644 --- a/resources/lib/utils.py +++ b/resources/lib/utils.py @@ -26,16 +26,21 @@ log = logging.getLogger("EMBY."+__name__) ################################################################################################# # Main methods -def window(property, value=None, clear=False, window_id=10000): +def window(property_, value=None, clear=False, window_id=10000): # Get or set window property WINDOW = xbmcgui.Window(window_id) if clear: - WINDOW.clearProperty(property) + WINDOW.clearProperty(property_) elif value is not None: - WINDOW.setProperty(property, value) + if ".json" in property_: + value = json.dumps(value) + WINDOW.setProperty(property_, value) else: - return WINDOW.getProperty(property) + result = WINDOW.getProperty(property_) + if result and ".json" in property_: + result = json.loads(result) + return result def settings(setting, value=None): # Get or add addon setting