diff --git a/.gitignore b/.gitignore index f173f672..9d95456c 100644 --- a/.gitignore +++ b/.gitignore @@ -83,4 +83,5 @@ msbuild.wrn test/userdata/cache/ test/userdata/credentials.json test/userdata/search_history.json +test/userdata/tokens/ test/userdata/*.tkn diff --git a/resources/lib/kodiwrapper.py b/resources/lib/kodiwrapper.py index ccc38c33..58d0e578 100644 --- a/resources/lib/kodiwrapper.py +++ b/resources/lib/kodiwrapper.py @@ -123,6 +123,7 @@ def __init__(self, addon): self._max_log_level = log_levels.get(self.get_setting('max_log_level', 'Debug'), 3) self._usemenucaching = self.get_setting('usemenucaching', 'true') == 'true' self._cache_path = self.get_userdata_path() + 'cache/' + self._tokens_path = self.get_userdata_path() + 'tokens/' self._system_locale_works = None def url_for(self, name, *args, **kwargs): @@ -449,6 +450,10 @@ def get_userdata_path(self): ''' Return the profile's userdata path ''' return xbmc.translatePath(self._addon.getAddonInfo('profile')) + def get_tokens_path(self): + ''' Return the userdata tokens path ''' + return self._tokens_path + def get_addon_path(self): ''' Return the addon path ''' return xbmc.translatePath(self._addon.getAddonInfo('path')) diff --git a/resources/lib/tokenresolver.py b/resources/lib/tokenresolver.py index f7cbfb69..c85889f3 100644 --- a/resources/lib/tokenresolver.py +++ b/resources/lib/tokenresolver.py @@ -84,7 +84,7 @@ def get_xvrttoken(self, token_variant=None): def _get_token_path(self, token_name, token_variant): ''' Create token path following predefined file naming rules ''' prefix = token_variant + '_' if token_variant else '' - token_path = self._kodi.get_userdata_path() + prefix + token_name.replace('-', '') + '.tkn' + token_path = self._kodi.get_tokens_path() + prefix + token_name.replace('-', '') + '.tkn' return token_path def _get_cached_token(self, token_name, token_variant=None): @@ -112,6 +112,10 @@ def _set_cached_token(self, token, token_variant=None): ''' Save token to cache''' token_name = list(token.keys())[0] path = self._get_token_path(token_name, token_variant) + + if not self._kodi.check_if_path_exists(self._kodi.get_tokens_path()): + self._kodi.mkdir(self._kodi.get_tokens_path()) + with self._kodi.open_file(path, 'w') as f: json.dump(token, f) @@ -307,8 +311,14 @@ def _create_token_dictionary(cookie_data, cookie_name='X-VRT-Token'): def delete_tokens(self): ''' Delete all cached tokens ''' + # Remove old tokens + # FIXME: Deprecate and simplify this part in a future version dirs, files = self._kodi.listdir(self._kodi.get_userdata_path()) # pylint: disable=unused-variable token_files = [item for item in files if item.endswith('.tkn')] + # Empty userdata/tokens/ directory + if self._kodi.check_if_path_exists(self._kodi.get_tokens_path()): + dirs, files = self._kodi.listdir(self._kodi.get_tokens_path()) # pylint: disable=unused-variable + token_files += ['tokens/' + item for item in files] if token_files: for item in token_files: self._kodi.delete_file(self._kodi.get_userdata_path() + item) diff --git a/resources/lib/vrtplayer.py b/resources/lib/vrtplayer.py index b9b4628c..65e1db73 100644 --- a/resources/lib/vrtplayer.py +++ b/resources/lib/vrtplayer.py @@ -78,10 +78,13 @@ def _version_check(self): # 2.0.0 version: changed plugin:// url interface: show warning that favourites and what-was-watched will break if settings_version == '' and self._kodi.credentials_filled_in(): self._kodi.show_ok_dialog(self._kodi.localize(30978), self._kodi.localize(30979)) - # 2.2.0 version: changed artwork: delete old cached artwork if addon_version == '2.2.0': + # 2.2.0 version: changed artwork: delete old cached artwork self._kodi.delete_cached_thumbnail(self._kodi.get_addon_info('fanart').replace('.png', '.jpg')) self._kodi.delete_cached_thumbnail(self._kodi.get_addon_info('icon')) + # 2.2.0 version: moved tokens: delete old tokens + from tokenresolver import TokenResolver + TokenResolver(self._kodi).delete_tokens() def _first_run(self): '''Check if this add-on version is run for the first time'''