From 723b8f1c57a7dc86842b08594a54e2c7491dedbb Mon Sep 17 00:00:00 2001 From: Niko Date: Fri, 26 Jul 2024 15:00:00 +0200 Subject: [PATCH] add unique_hash to CacheFileHandler and SpotifyOAuth --- spotipy/cache_handler.py | 3 +++ spotipy/oauth2.py | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/spotipy/cache_handler.py b/spotipy/cache_handler.py index 7ae94a23..9f2c9812 100644 --- a/spotipy/cache_handler.py +++ b/spotipy/cache_handler.py @@ -51,6 +51,7 @@ class CacheFileHandler(CacheHandler): def __init__(self, cache_path=None, + unique_hash=None, username=None, encoder_cls=None): """ @@ -67,6 +68,8 @@ def __init__(self, self.cache_path = cache_path else: cache_path = ".cache" + if unique_hash: + cache_path += "-" + str(unique_hash) username = (username or os.getenv(CLIENT_CREDS_ENV_VARS["client_username"])) if username: cache_path += "-" + str(username) diff --git a/spotipy/oauth2.py b/spotipy/oauth2.py index 4c0cd906..3c4e6f13 100644 --- a/spotipy/oauth2.py +++ b/spotipy/oauth2.py @@ -13,6 +13,7 @@ import time import warnings import webbrowser +import hashlib import requests import urllib.parse as urllibparse @@ -349,8 +350,9 @@ def __init__( else: username = (username or os.getenv(CLIENT_CREDS_ENV_VARS["client_username"])) self.cache_handler = CacheFileHandler( + unique_hash=hashlib.sha256(client_secret.encode('utf-8')).hexdigest()[:7], username=username, - cache_path=cache_path + cache_path=cache_path, ) self.proxies = proxies self.requests_timeout = requests_timeout