From 843cc4a9137c1b38c835168299b51c30f9610be3 Mon Sep 17 00:00:00 2001 From: marco Date: Mon, 13 Apr 2020 10:09:08 +0200 Subject: [PATCH] ottimizzato downloader --- core/downloader.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/core/downloader.py b/core/downloader.py index 3add5285..1dc652f5 100644 --- a/core/downloader.py +++ b/core/downloader.py @@ -205,6 +205,8 @@ class Downloader(object): self._part_size = part_size self._max_buffer = max_buffer self._json_path = json_path + self._json_text = '' + self._json_item = Item() try: import xbmc @@ -587,12 +589,18 @@ class Downloader(object): logger.info("Thread stopped: %s" % threading.current_thread().name) def __update_json(self, started=True): - item = Item().fromjson(filetools.read(self._json_path)) + text = filetools.read(self._json_path) + # load item only if changed + if self._json_text != text: + self._json_text = text + self._json_item = Item().fromjson(text) + logger.info('item loaded') progress = int(self.progress) - if started and item.downloadStatus == 0: # stopped + if started and self._json_item.downloadStatus == 0: # stopped logger.info('Download paused') self.stop() - elif item.downloadProgress != progress or not started: + elif self._json_item.downloadProgress != progress or not started: params = {"downloadStatus": 4, "downloadComplete": 0, "downloadProgress": progress} - item.__dict__.update(params) - filetools.write(self._json_path, item.tojson()) + self._json_item.__dict__.update(params) + self._json_text = self._json_item.tojson() + filetools.write(self._json_path, self._json_text)