Skip to content

Commit dc6a88a

Browse files
authored
Add method to get top track of an artist (#474)
1 parent 88483c4 commit dc6a88a

File tree

5 files changed

+5170
-1
lines changed

5 files changed

+5170
-1
lines changed

src/spotifyaio/models.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,13 @@ class TopTracksResponse(DataClassORJSONMixin):
274274
items: list[Track]
275275

276276

277+
@dataclass
278+
class ArtistTopTracksResponse(DataClassORJSONMixin):
279+
"""Artist top tracks response model."""
280+
281+
tracks: list[Track]
282+
283+
277284
@dataclass
278285
class SimplifiedTrack(DataClassORJSONMixin):
279286
"""SimplifiedTrack model."""

src/spotifyaio/spotify.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
AlbumTracksResponse,
2020
Artist,
2121
ArtistResponse,
22+
ArtistTopTracksResponse,
2223
Audiobook,
2324
AudiobooksResponse,
2425
AudioFeatures,
@@ -267,7 +268,11 @@ async def get_artist_albums(self, artist_id: str) -> list[SimplifiedAlbum]:
267268
response = await self._get(f"v1/artists/{identifier}/albums", params=params)
268269
return NewReleasesResponseInner.from_json(response).items
269270

270-
# Get an artist's top tracks
271+
async def get_artist_top_tracks(self, artist_id: str) -> list[Track]:
272+
"""Get artist top tracks."""
273+
identifier = artist_id.split(":")[-1]
274+
response = await self._get(f"v1/artists/{identifier}/top-tracks")
275+
return ArtistTopTracksResponse.from_json(response).tracks
271276

272277
# Get an artist's related artists
273278

0 commit comments

Comments
 (0)