From 36dbb3357ef0a88a3e84e34bca0b988b786b9e70 Mon Sep 17 00:00:00 2001 From: Antti Kettunen Date: Sat, 11 Apr 2026 13:14:50 +0300 Subject: [PATCH] Add rate-limit handling for Spotify searches --- core/spotify_client.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/core/spotify_client.py b/core/spotify_client.py index 2017dfa4..ffc71209 100644 --- a/core/spotify_client.py +++ b/core/spotify_client.py @@ -1125,6 +1125,7 @@ class SpotifyClient: return tracks except Exception as e: + _detect_and_set_rate_limit(e, 'search_tracks') logger.error(f"Error searching tracks via Spotify: {e}") # Fall through to fallback @@ -1153,6 +1154,10 @@ class SpotifyClient: artists.sort(key=lambda a: (0 if a.name.lower().strip() == query_lower else 1)) return artists + if self.is_rate_limited(): + logger.debug(f"Spotify rate limited, skipping artist search for: {query}") + use_spotify = False + if use_spotify: try: search_query = f'artist:{query}' if len(query.strip()) <= 4 else query @@ -1178,6 +1183,7 @@ class SpotifyClient: return artists except Exception as e: + _detect_and_set_rate_limit(e, 'search_artists') logger.error(f"Error searching artists via Spotify: {e}") # Fall through to iTunes fallback @@ -1232,6 +1238,7 @@ class SpotifyClient: return albums except Exception as e: + _detect_and_set_rate_limit(e, 'search_albums') logger.error(f"Error searching albums via Spotify: {e}") # Fall through to iTunes fallback @@ -1600,4 +1607,4 @@ class SpotifyClient: except Exception as e: logger.error(f"Error in batch artist fetch: {e}") - return found \ No newline at end of file + return found