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