From aef53f7b4d99b306e8cd33526eb50a193fced4f4 Mon Sep 17 00:00:00 2001 From: Broque Thomas Date: Tue, 18 Nov 2025 22:46:24 -0800 Subject: [PATCH] grab paginated albums --- core/spotify_client.py | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/core/spotify_client.py b/core/spotify_client.py index b6e1d249..d3a63e5b 100644 --- a/core/spotify_client.py +++ b/core/spotify_client.py @@ -519,14 +519,37 @@ class SpotifyClient: @rate_limited def get_album_tracks(self, album_id: str) -> Optional[Dict[str, Any]]: - """Get album tracks""" + """Get album tracks with pagination to fetch all tracks""" if not self.is_authenticated(): return None - + try: - tracks_data = self.sp.album_tracks(album_id) - return tracks_data - + # Get first page of tracks + first_page = self.sp.album_tracks(album_id) + if not first_page or 'items' not in first_page: + return None + + # Collect all tracks starting with first page + all_tracks = first_page['items'][:] + + # Fetch remaining pages if they exist + next_page = first_page + while next_page.get('next'): + next_page = self.sp.next(next_page) + if next_page and 'items' in next_page: + all_tracks.extend(next_page['items']) + + # Log success + logger.info(f"Retrieved {len(all_tracks)} tracks for album {album_id}") + + # Return structure with all tracks + result = first_page.copy() + result['items'] = all_tracks + result['next'] = None # No more pages + result['limit'] = len(all_tracks) # Update to reflect all tracks fetched + + return result + except Exception as e: logger.error(f"Error fetching album tracks: {e}") return None