Skip to content

Commit 23cb926

Browse files
authored
Get tracks of album (#350)
1 parent 5bed6b2 commit 23cb926

6 files changed

Lines changed: 3349 additions & 3 deletions

File tree

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ repos:
7373
exclude: ^poetry\.lock$
7474
entry: poetry run codespell
7575
args:
76-
- --ignore-words-list=doen,te,ons,Racoon,Crate,Ede,succes
76+
- --ignore-words-list=doen,te,ons,Racoon,Crate,Ede,succes,alle
7777
- id: detect-private-key
7878
name: 🕵️ Detect Private Keys
7979
language: system

src/spotifyaio/models.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,3 +526,10 @@ class AlbumsResponse(DataClassORJSONMixin):
526526
"""Albums response model."""
527527

528528
albums: list[Album]
529+
530+
531+
@dataclass
532+
class AlbumTracksResponse(DataClassORJSONMixin):
533+
"""Album tracks response model."""
534+
535+
items: list[SimplifiedTrack]

src/spotifyaio/spotify.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from spotifyaio.models import (
1616
Album,
1717
AlbumsResponse,
18+
AlbumTracksResponse,
1819
Artist,
1920
ArtistResponse,
2021
BasePlaylist,
@@ -51,7 +52,7 @@
5152
from spotifyaio.util import get_identifier
5253

5354
if TYPE_CHECKING:
54-
from spotifyaio import SimplifiedAlbum, Track
55+
from spotifyaio import SimplifiedAlbum, SimplifiedTrack, Track
5556

5657
VERSION = metadata.version(__package__)
5758

@@ -162,7 +163,12 @@ async def get_albums(self, album_ids: list[str]) -> list[Album]:
162163
response = await self._get("v1/albums", params=params)
163164
return AlbumsResponse.from_json(response).albums
164165

165-
# Get an album's tracks
166+
async def get_album_tracks(self, album_id: str) -> list[SimplifiedTrack]:
167+
"""Get album tracks."""
168+
identifier = get_identifier(album_id)
169+
params: dict[str, Any] = {"limit": 48}
170+
response = await self._get(f"v1/albums/{identifier}/tracks", params=params)
171+
return AlbumTracksResponse.from_json(response).items
166172

167173
async def get_saved_albums(self) -> list[SavedAlbum]:
168174
"""Get saved albums."""

0 commit comments

Comments
 (0)