From c3e0012762e7664aa28396b75c95f442ac819c72 Mon Sep 17 00:00:00 2001 From: Crussader <75786691+Crussader@users.noreply.github.com> Date: Sat, 30 Oct 2021 17:11:37 +0400 Subject: [PATCH] Update client.py --- pomice/spotify/client.py | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/pomice/spotify/client.py b/pomice/spotify/client.py index a19061b..3a781ac 100644 --- a/pomice/spotify/client.py +++ b/pomice/spotify/client.py @@ -74,21 +74,20 @@ class Client: return Track(data) elif spotify_type == "album": return Album(data) + else: + tracks = [Track(track["track"]) for track in data["tracks"]["items"]] + next_page_url = data["tracks"]["next"] - # processing a playlist result - tracks = [Track(track["track"]) for track in data["tracks"]["items"]] - next_page_url = data["tracks"]["next"] + while next_page_url is not None: + async with self.session.get(next_page_url, headers=self._bearer_headers) as resp: + if resp.status != 200: + raise SpotifyRequestException( + f"Error while fetching results: {resp.status} {resp.reason}" + ) - while next_page_url is not None: - async with self.session.get(next_page_url, headers=self._bearer_headers) as resp: - if resp.status != 200: - raise SpotifyRequestException( - f"Error while fetching results: {resp.status} {resp.reason}" - ) + next_data: dict = await resp.json() - next_data: dict = await resp.json() + tracks += [Track(track["track"]) for track in next_data["items"]] + next_page_url = next_data["next"] - tracks += [Track(track["track"]) for track in next_data["items"]] - next_page_url = next_data["next"] - - return Playlist(data, tracks) + return Playlist(data, tracks)