|
12 | 12 | import orjson |
13 | 13 | from yarl import URL |
14 | 14 |
|
15 | | -from spotifyaio.exceptions import ( |
16 | | - SpotifyConnectionError, |
17 | | - SpotifyNotFoundError, |
18 | | - SpotifyRateLimitError, |
19 | | -) |
| 15 | +from spotifyaio.exceptions import SpotifyConnectionError, SpotifyNotFoundError |
20 | 16 | from spotifyaio.models import ( |
21 | 17 | Album, |
22 | 18 | AlbumsResponse, |
|
36 | 32 | Devices, |
37 | 33 | Episode, |
38 | 34 | FeaturedPlaylistResponse, |
| 35 | + FollowedArtistResponse, |
39 | 36 | NewReleasesResponse, |
40 | 37 | NewReleasesResponseInner, |
41 | 38 | PlaybackState, |
@@ -136,10 +133,6 @@ async def _request( |
136 | 133 | msg = f"Resource not found: {uri}" |
137 | 134 | raise SpotifyNotFoundError(msg) |
138 | 135 |
|
139 | | - if '"status": 429' in text: |
140 | | - msg = "Ratelimit exceeded" |
141 | | - raise SpotifyRateLimitError(msg) |
142 | | - |
143 | 136 | return text |
144 | 137 |
|
145 | 138 | async def _get(self, uri: str, params: dict[str, Any] | None = None) -> str: |
@@ -254,7 +247,18 @@ async def get_artist(self, artist_id: str) -> Artist: |
254 | 247 | response = await self._get(f"v1/artists/{identifier}") |
255 | 248 | return Artist.from_json(response) |
256 | 249 |
|
257 | | - # Get several artists |
| 250 | + async def get_artists(self, artist_ids: list[str]) -> list[Artist]: |
| 251 | + """Get several artists.""" |
| 252 | + if not artist_ids: |
| 253 | + return [] |
| 254 | + if len(artist_ids) > 50: |
| 255 | + msg = "Maximum of 50 artists can be requested at once" |
| 256 | + raise ValueError(msg) |
| 257 | + params: dict[str, Any] = { |
| 258 | + "ids": ",".join([get_identifier(i) for i in artist_ids]) |
| 259 | + } |
| 260 | + response = await self._get("v1/artists", params=params) |
| 261 | + return ArtistResponse.from_json(response).artists |
258 | 262 |
|
259 | 263 | async def get_artist_albums(self, artist_id: str) -> list[SimplifiedAlbum]: |
260 | 264 | """Get artist albums.""" |
@@ -569,7 +573,7 @@ async def get_followed_artists(self) -> list[Artist]: |
569 | 573 | """Get followed artists.""" |
570 | 574 | params: dict[str, Any] = {"limit": 48, "type": "artist"} |
571 | 575 | response = await self._get("v1/me/following", params=params) |
572 | | - return ArtistResponse.from_json(response).artists.items |
| 576 | + return FollowedArtistResponse.from_json(response).artists.items |
573 | 577 |
|
574 | 578 | # Follow an artist or user |
575 | 579 |
|
|
0 commit comments