fix: playlist field: tracks -> items

This commit is contained in:
2026-05-14 12:23:33 +02:00
parent e42cddd645
commit ee5a1376ee

25
api.py
View File

@@ -680,22 +680,25 @@ def playlist(playlist_id):
access_token,
)
# The playlist response embeds a `tracks` paging object whose first page
# contains up to 100 items. For playlists larger than that, follow the
# dedicated tracks endpoint until exhausted and splice the full list back
# into the response.
tracks_obj = playlist_data.get("tracks") or {}
if tracks_obj.get("next"):
all_tracks = spotify_get_paginated(
# Full playlist objects use a paging object at `items` (current Spotify shape)
# or legacy `tracks`. Follow `next` on whichever is present.
paging_key = (
"items"
if isinstance(playlist_data.get("items"), dict)
else "tracks"
)
paging = playlist_data.get(paging_key) or {}
if paging.get("next"):
all_items = spotify_get_paginated(
f"https://api.spotify.com/v1/playlists/{playlist_id}/tracks",
access_token,
limit=100,
)
playlist_data["tracks"] = {
**tracks_obj,
"items": all_tracks,
playlist_data[paging_key] = {
**paging,
"items": all_items,
"offset": 0,
"limit": len(all_tracks),
"limit": len(all_items),
"next": None,
"previous": None,
}