diff --git a/core/spotify_client.py b/core/spotify_client.py index fc4ac624..eb530c1d 100644 --- a/core/spotify_client.py +++ b/core/spotify_client.py @@ -336,7 +336,7 @@ class SpotifyClient: self._auth_cache_lock = threading.Lock() self._auth_cached_result: Optional[bool] = None self._auth_cache_time: float = 0 - self._AUTH_CACHE_TTL = 60 # seconds + self._AUTH_CACHE_TTL = 300 # 5 minutes — auth status rarely changes, no need to probe often self._setup_client() def _is_spotify_id(self, id_str: str) -> bool: diff --git a/core/spotify_worker.py b/core/spotify_worker.py index dfbd97c6..5074e73e 100644 --- a/core/spotify_worker.py +++ b/core/spotify_worker.py @@ -97,15 +97,14 @@ class SpotifyWorker: is_idle = is_actually_running and not self.paused and self.stats['pending'] == 0 and self.current_item is None try: - # During rate limit or post-ban cooldown, report as authenticated - # but don't call is_spotify_authenticated() — that would trigger an - # auth probe which resets the rate limit timer. + # NEVER call is_spotify_authenticated() here — get_stats() is called + # every 2 seconds by the WebSocket status loop. The auth probe has a + # 60-second cache, so it would fire a real Spotify API call (current_user) + # every 60 seconds indefinitely, wasting API quota and risking rate limits. + # Instead, use sp presence as a lightweight proxy for "configured". rate_limited = self.client.is_rate_limited() in_cooldown = self.client.get_post_ban_cooldown_remaining() > 0 - if rate_limited or in_cooldown: - authenticated = True # We're authenticated, just banned/cooling down - else: - authenticated = self.client.is_spotify_authenticated() + authenticated = self.client.sp is not None except Exception: authenticated = False rate_limited = False