Update client.py
This commit is contained in:
parent
13d0df8f97
commit
f8094f0c5a
|
|
@ -5,6 +5,7 @@ import aiohttp
|
||||||
|
|
||||||
from base64 import b64encode
|
from base64 import b64encode
|
||||||
|
|
||||||
|
from .artist import Artist
|
||||||
from .album import Album
|
from .album import Album
|
||||||
from .exceptions import InvalidSpotifyURL, SpotifyRequestException
|
from .exceptions import InvalidSpotifyURL, SpotifyRequestException
|
||||||
from .playlist import Playlist
|
from .playlist import Playlist
|
||||||
|
|
@ -44,7 +45,6 @@ class Client:
|
||||||
raise SpotifyRequestException(
|
raise SpotifyRequestException(
|
||||||
f"Error fetching bearer token: {resp.status} {resp.reason}"
|
f"Error fetching bearer token: {resp.status} {resp.reason}"
|
||||||
)
|
)
|
||||||
|
|
||||||
data: dict = await resp.json()
|
data: dict = await resp.json()
|
||||||
|
|
||||||
self._bearer_token = data["access_token"]
|
self._bearer_token = data["access_token"]
|
||||||
|
|
@ -71,7 +71,6 @@ class Client:
|
||||||
raise SpotifyRequestException(
|
raise SpotifyRequestException(
|
||||||
f"Error while fetching results: {resp.status} {resp.reason}"
|
f"Error while fetching results: {resp.status} {resp.reason}"
|
||||||
)
|
)
|
||||||
|
|
||||||
data: dict = await resp.json()
|
data: dict = await resp.json()
|
||||||
|
|
||||||
if spotify_type == "track":
|
if spotify_type == "track":
|
||||||
|
|
@ -79,28 +78,29 @@ class Client:
|
||||||
elif spotify_type == "album":
|
elif spotify_type == "album":
|
||||||
return Album(data)
|
return Album(data)
|
||||||
elif spotify_type == "artist":
|
elif spotify_type == "artist":
|
||||||
logging.info(data)
|
|
||||||
tracks = []
|
tracks = []
|
||||||
|
|
||||||
for album in data["items"]:
|
for album in data["items"]:
|
||||||
logging.info(album)
|
|
||||||
|
|
||||||
async with self.session.get(BASE_URL + f"/albums/{album['id']}/tracks", headers=self._bearer_headers) as resp:
|
async with self.session.get(BASE_URL + f"/albums/{album['id']}/tracks", headers=self._bearer_headers) as resp:
|
||||||
if resp.status != 200:
|
if resp.status != 200:
|
||||||
raise SpotifyRequestException(
|
raise SpotifyRequestException(
|
||||||
f"Error while fetching results: {resp.status} {resp.reason}"
|
f"Error while fetching results: {resp.status} {resp.reason}"
|
||||||
)
|
)
|
||||||
|
|
||||||
data: dict = await resp.json()
|
data: dict = await resp.json()
|
||||||
|
|
||||||
for track in data["items"]:
|
for track in data["items"]:
|
||||||
tracks.append(Track(track))
|
tracks.append(Track(track, image=album["images"][0]["url"]))
|
||||||
|
|
||||||
logging.info(tracks)
|
async with self.session.get(BASE_URL + f"/artists/{spotify_id}", headers=self._bearer_headers) as resp:
|
||||||
data = {"name": "testt"}
|
if resp.status != 200:
|
||||||
return Playlist(data, tracks)
|
raise SpotifyRequestException(
|
||||||
|
f"Error while fetching results: {resp.status} {resp.reason}"
|
||||||
|
)
|
||||||
|
data: dict = await resp.json()
|
||||||
|
|
||||||
else:
|
return Artist(data, tracks)
|
||||||
|
|
||||||
|
else:
|
||||||
tracks = [
|
tracks = [
|
||||||
Track(track["track"])
|
Track(track["track"])
|
||||||
for track in data["tracks"]["items"] if track["track"] is not None
|
for track in data["tracks"]["items"] if track["track"] is not None
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue