From 09dba218c24e37042a860cb116e9cbe20d371264 Mon Sep 17 00:00:00 2001 From: RemixDev Date: Sun, 20 Sep 2020 18:32:39 +0200 Subject: [PATCH] Added simple spotifyCache validation --- deemix/__init__.py | 2 +- deemix/app/spotifyhelper.py | 17 ++++++++++++++++- setup.py | 2 +- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/deemix/__init__.py b/deemix/__init__.py index 92a77ae..314405e 100644 --- a/deemix/__init__.py +++ b/deemix/__init__.py @@ -1,3 +1,3 @@ #!/usr/bin/env python3 -__version__ = "1.4.0" +__version__ = "1.4.1" diff --git a/deemix/app/spotifyhelper.py b/deemix/app/spotifyhelper.py index 8d1f5c3..f86b2c1 100644 --- a/deemix/app/spotifyhelper.py +++ b/deemix/app/spotifyhelper.py @@ -1,7 +1,7 @@ import eventlet import json import os.path as path -from os import mkdir +from os import mkdir, remove eventlet.import_patched('requests.adapters') @@ -50,6 +50,21 @@ class SpotifyHelper: with open(path.join(self.configFolder, 'authCredentials.json'), 'r') as credentialsFile: self.credentials = json.load(credentialsFile) self.checkCredentials() + self.checkValidCache() + + def checkValidCache(self): + if path.isfile(path.join(self.configFolder, 'spotifyCache.json')): + with open(path.join(self.configFolder, 'spotifyCache.json'), 'r') as spotifyCache: + try: + cache = json.load(spotifyCache) + except Exception as e: + print(str(e)) + remove(path.join(self.configFolder, 'spotifyCache.json')) + return + # Remove old versions of cache + if len(cache['tracks'].values()) and isinstance(list(cache['tracks'].values())[0], int) or \ + len(cache['albums'].values()) and isinstance(list(cache['albums'].values())[0], int): + remove(path.join(self.configFolder, 'spotifyCache.json')) def checkCredentials(self): if self.credentials['clientId'] == "" or self.credentials['clientSecret'] == "": diff --git a/setup.py b/setup.py index 3b50bdc..683700a 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ README = (HERE / "README.md").read_text() setup( name="deemix", - version="1.4.0", + version="1.4.1", description="A barebone deezer downloader library", long_description=README, long_description_content_type="text/markdown",