From 10506a1fbe541db4f97d44952ed2df67ee6cb875 Mon Sep 17 00:00:00 2001 From: cloudwithax Date: Thu, 28 Oct 2021 17:55:48 -0400 Subject: [PATCH] Some code cleanup before release --- pomice/objects.py | 1 - pomice/spotify/client.py | 27 +++++++++++++-------------- pomice/spotify/exceptions.py | 1 + setup.py | 2 +- 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/pomice/objects.py b/pomice/objects.py index dc81c8a..a5ece2c 100644 --- a/pomice/objects.py +++ b/pomice/objects.py @@ -1,4 +1,3 @@ -from re import S from typing import Optional from discord.ext import commands diff --git a/pomice/spotify/client.py b/pomice/spotify/client.py index a19061b..0fceb84 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) \ No newline at end of file diff --git a/pomice/spotify/exceptions.py b/pomice/spotify/exceptions.py index bd67ec5..e421fbf 100644 --- a/pomice/spotify/exceptions.py +++ b/pomice/spotify/exceptions.py @@ -4,4 +4,5 @@ class SpotifyRequestException(Exception): class InvalidSpotifyURL(Exception): + """An invalid Spotify URL was passed""" pass diff --git a/setup.py b/setup.py index 544d84a..28950fb 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ setuptools.setup( long_description=readme, long_description_content_type="text/markdown", include_package_data=True, - install_requires=['discord.py>=1.7.1'], + install_requires=['discord.py>=2.0.0a'], extra_require=None, classifiers=[ "Framework :: AsyncIO",