From 60261f2e91ac02fc80b5463e609e7c541639ddd4 Mon Sep 17 00:00:00 2001 From: Broque Thomas <26755000+Nezreka@users.noreply.github.com> Date: Sat, 14 Mar 2026 14:58:12 -0700 Subject: [PATCH] Fix watchlist scan failing entirely when Spotify is rate limited by adding iTunes provider fallback and missing rate limit ban detection --- core/spotify_client.py | 3 +++ core/watchlist_scanner.py | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/core/spotify_client.py b/core/spotify_client.py index 8bcdc4ab..176e8fe4 100644 --- a/core/spotify_client.py +++ b/core/spotify_client.py @@ -1096,6 +1096,7 @@ class SpotifyClient: return track_data except Exception as e: + _detect_and_set_rate_limit(e, 'get_track_details') logger.error(f"Error fetching track details via Spotify: {e}") # Fall through to iTunes fallback @@ -1246,6 +1247,7 @@ class SpotifyClient: return result except Exception as e: + _detect_and_set_rate_limit(e, 'get_album_tracks') logger.error(f"Error fetching album tracks via Spotify: {e}") # Fall through to iTunes fallback @@ -1287,6 +1289,7 @@ class SpotifyClient: return albums except Exception as e: + _detect_and_set_rate_limit(e, 'get_artist_albums') logger.error(f"Error fetching artist albums via Spotify: {e}") # Fall through to iTunes fallback diff --git a/core/watchlist_scanner.py b/core/watchlist_scanner.py index c067be68..0a6d9759 100644 --- a/core/watchlist_scanner.py +++ b/core/watchlist_scanner.py @@ -478,7 +478,40 @@ class WatchlistScanner: logger.warning(f"No valid client/ID for {watchlist_artist.artist_name}") return None - return self._get_artist_discography_with_client(client, artist_id, last_scan_timestamp) + albums = self._get_artist_discography_with_client(client, artist_id, last_scan_timestamp) + + # If primary provider returned nothing, try the other provider as fallback + if not albums: + fallback_id = None + fallback_client = None + + if provider == 'spotify': + fallback_client = self.metadata_service.itunes + fallback_id = watchlist_artist.itunes_artist_id + # If no iTunes ID stored, search by name and cache it + if not fallback_id: + try: + search_results = fallback_client.search_artists(watchlist_artist.artist_name, limit=1) + if search_results: + fallback_id = search_results[0].id + logger.info(f"Resolved iTunes ID {fallback_id} for {watchlist_artist.artist_name}") + self.database.update_watchlist_artist_itunes_id( + watchlist_artist.spotify_artist_id or str(watchlist_artist.id), + fallback_id + ) + watchlist_artist.itunes_artist_id = fallback_id + except Exception as e: + logger.debug(f"Could not resolve iTunes ID for {watchlist_artist.artist_name}: {e}") + + elif provider == 'itunes': + fallback_client = self.metadata_service.spotify + fallback_id = watchlist_artist.spotify_artist_id + + if fallback_client and fallback_id: + logger.info(f"{provider.capitalize()} returned no albums for {watchlist_artist.artist_name}, falling back to {'iTunes' if provider == 'spotify' else 'Spotify'}") + albums = self._get_artist_discography_with_client(fallback_client, fallback_id, last_scan_timestamp) + + return albums def scan_all_watchlist_artists(self) -> List[ScanResult]: """