diff --git a/resources/lib/kodiutils.py b/resources/lib/kodiutils.py index 947ab741f..f89d1e69c 100644 --- a/resources/lib/kodiutils.py +++ b/resources/lib/kodiutils.py @@ -791,13 +791,11 @@ def get_cache(path, ttl=None): # pylint: disable=redefined-outer-name log(3, "Cache '{path}' is forced from cache.", path=path) else: log(3, "Cache '{path}' is fresh, expires in {time}.", path=path, time=human_delta(mtime + ttl - now)) - from json import load with open_file(fullpath, 'r') as fdesc: try: - return load(fdesc) - except (TypeError, ValueError) as exc: # No JSON object could be decoded - fdesc.seek(0, 0) - log_error('{exc}\nDATA: {data}', exc=exc, data=fdesc.read()) + return get_json_data(fdesc) + except ValueError as exc: # No JSON object could be decoded + log_error('JSON Error: {exc}', exc=exc) return None diff --git a/resources/lib/search.py b/resources/lib/search.py index 7b43d1aa8..c9609fbe0 100644 --- a/resources/lib/search.py +++ b/resources/lib/search.py @@ -5,9 +5,9 @@ from __future__ import absolute_import, division, unicode_literals from favorites import Favorites -from kodiutils import (addon_profile, container_refresh, end_of_directory, get_search_string, - get_setting, localize, log_error, ok_dialog, open_file, show_listing, ttl, - url_for) +from kodiutils import (addon_profile, container_refresh, end_of_directory, get_json_data, + get_search_string, get_setting, localize, log_error, ok_dialog, open_file, + show_listing, ttl, url_for) from resumepoints import ResumePoints @@ -25,12 +25,10 @@ def read_history(self): from json import load with open_file(self._search_history, 'r') as fdesc: try: - history = load(fdesc) - except (TypeError, ValueError) as exc: # No JSON object could be decoded - fdesc.seek(0, 0) - log_error('{exc}\nDATA: {data}', exc=exc, data=fdesc.read()) - history = [] - return history + return get_json_data(fdesc) + except ValueError as exc: # No JSON object could be decoded + log_error('JSON Error: {exc}', exc=exc) + return [] def write_history(self, history): ''' Write search history to disk ''' diff --git a/resources/lib/tokenresolver.py b/resources/lib/tokenresolver.py index 6e6d87eec..8695dcce3 100644 --- a/resources/lib/tokenresolver.py +++ b/resources/lib/tokenresolver.py @@ -3,10 +3,10 @@ ''' This module contains all functionality for VRT NU API authentication. ''' from __future__ import absolute_import, division, unicode_literals -from kodiutils import (addon_profile, delete, exists, get_proxies, get_setting, get_tokens_path, - get_url_json, has_credentials, invalidate_caches, listdir, localize, log, - log_error, mkdir, notification, ok_dialog, open_file, open_settings, - set_setting) +from kodiutils import (addon_profile, delete, exists, get_json_data, get_proxies, get_setting, + get_tokens_path, get_url_json, has_credentials, invalidate_caches, listdir, + localize, log, log_error, mkdir, notification, ok_dialog, open_file, + open_settings, set_setting) from vrtutils import from_unicode try: # Python 3 @@ -97,13 +97,11 @@ def _get_cached_token(self, token_name, token_variant=None): if not exists(path): return None - from json import load with open_file(path) as fdesc: try: - token = load(fdesc) - except (TypeError, ValueError) as exc: # No JSON object could be decoded - fdesc.seek(0, 0) - log_error('{exc}\nDATA: {data}', exc=exc, data=fdesc.read()) + token = get_json_data(fdesc) + except ValueError as exc: # No JSON object could be decoded + log_error('JSON Error: {exc}', exc=exc) return None from datetime import datetime