From: Marcel van der Veldt Date: Tue, 25 Feb 2025 13:44:27 +0000 (+0100) Subject: Fix: Spotify searchresults higher than 50 items X-Git-Url: https://git.kitaultman.com/?a=commitdiff_plain;h=d66f80ef0b3d88336b127bd12e58e232d06eaff0;p=music-assistant-server.git Fix: Spotify searchresults higher than 50 items --- diff --git a/music_assistant/providers/spotify/__init__.py b/music_assistant/providers/spotify/__init__.py index 3245c15d..0b76dc24 100644 --- a/music_assistant/providers/spotify/__init__.py +++ b/music_assistant/providers/spotify/__init__.py @@ -315,31 +315,46 @@ class SpotifyProvider(MusicProvider): return searchresult searchtype = ",".join(searchtypes) search_query = search_query.replace("'", "") - api_result = await self._get_data("search", q=search_query, type=searchtype, limit=limit) - if "artists" in api_result: - searchresult.artists += [ - self._parse_artist(item) - for item in api_result["artists"]["items"] - if (item and item["id"] and item["name"]) - ] - if "albums" in api_result: - searchresult.albums += [ - self._parse_album(item) - for item in api_result["albums"]["items"] - if (item and item["id"]) - ] - if "tracks" in api_result: - searchresult.tracks += [ - self._parse_track(item) - for item in api_result["tracks"]["items"] - if (item and item["id"]) - ] - if "playlists" in api_result: - searchresult.playlists += [ - self._parse_playlist(item) - for item in api_result["playlists"]["items"] - if (item and item["id"]) - ] + offset = 0 + page_limit = min(limit, 50) + while True: + items_received = 0 + api_result = await self._get_data( + "search", q=search_query, type=searchtype, limit=page_limit, offset=offset + ) + if "artists" in api_result: + searchresult.artists += [ + self._parse_artist(item) + for item in api_result["artists"]["items"] + if (item and item["id"] and item["name"]) + ] + items_received += len(api_result["artists"]["items"]) + if "albums" in api_result: + searchresult.albums += [ + self._parse_album(item) + for item in api_result["albums"]["items"] + if (item and item["id"]) + ] + items_received += len(api_result["albums"]["items"]) + if "tracks" in api_result: + searchresult.tracks += [ + self._parse_track(item) + for item in api_result["tracks"]["items"] + if (item and item["id"]) + ] + items_received += len(api_result["tracks"]["items"]) + if "playlists" in api_result: + searchresult.playlists += [ + self._parse_playlist(item) + for item in api_result["playlists"]["items"] + if (item and item["id"]) + ] + items_received += len(api_result["playlists"]["items"]) + offset += page_limit + if offset >= limit: + break + if items_received < page_limit: + break return searchresult async def get_library_artists(self) -> AsyncGenerator[Artist, None]: