rate limiting

This commit is contained in:
Broque Thomas 2025-08-16 10:24:07 -07:00
parent 3bd6a29bfd
commit 1bf7995864
2 changed files with 10 additions and 0 deletions

View file

@ -432,6 +432,7 @@ class SpotifyClient:
logger.error(f"Error fetching track features: {e}") logger.error(f"Error fetching track features: {e}")
return None return None
@rate_limited
def get_album(self, album_id: str) -> Optional[Dict[str, Any]]: def get_album(self, album_id: str) -> Optional[Dict[str, Any]]:
"""Get album information including tracks""" """Get album information including tracks"""
if not self.is_authenticated(): if not self.is_authenticated():
@ -445,6 +446,7 @@ class SpotifyClient:
logger.error(f"Error fetching album: {e}") logger.error(f"Error fetching album: {e}")
return None return None
@rate_limited
def get_album_tracks(self, album_id: str) -> Optional[Dict[str, Any]]: def get_album_tracks(self, album_id: str) -> Optional[Dict[str, Any]]:
"""Get album tracks""" """Get album tracks"""
if not self.is_authenticated(): if not self.is_authenticated():

View file

@ -116,6 +116,10 @@ class WatchlistScanWorker(QThread):
else: else:
total_singles_eps_releases += 1 # Count the release, not the tracks total_singles_eps_releases += 1 # Count the release, not the tracks
# Rate limiting: small delay between album fetches to avoid hitting Spotify limits
import time
time.sleep(0.1) # 100ms delay between albums
except Exception as e: except Exception as e:
logger.warning(f"Error analyzing album {album.name} for totals: {e}") logger.warning(f"Error analyzing album {album.name} for totals: {e}")
continue continue
@ -167,6 +171,10 @@ class WatchlistScanWorker(QThread):
# Emit release completion signal # Emit release completion signal
self.release_completed.emit(watchlist_artist.artist_name, album.name, len(tracks)) self.release_completed.emit(watchlist_artist.artist_name, album.name, len(tracks))
# Rate limiting: small delay between album processing to avoid hitting Spotify limits
import time
time.sleep(0.1) # 100ms delay between albums
except Exception as e: except Exception as e:
logger.warning(f"Error checking album {album.name}: {e}") logger.warning(f"Error checking album {album.name}: {e}")
continue continue