Gateway: Apple Music API client (paginated, paced, 429-retry) #6
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Context
Gateway service (see #18). The gateway is the only component that talks to
the Apple Music API.
Task
app/apple_api.py: portbeets-appleplaylists/beetsplug/appleplaylists/ apple_api.pyalmost verbatim (it is already tested):AppleTrack(title, artist, album, isrc, track_number)andApplePlaylist(id, name, tracks)— keep the field names identical so theplugin's parsing is unchanged
AppleAPIClient(dev_token, user_token, session=None)with headersAuthorization: Bearer <dev token>andMusic-User-Token: <user token>fetch_playlists()-> list ofApplePlaylist; tracks via/v1/me/library/playlists/{id}/tracks; nestedlibrary-playlistsentries spliced into their parent at the position where they appear
(queue[0:0] expansion);
library-music-videos/library-albumsskippedlimit=100+offset, pause 0.25s between pagessanitized
AppleAPIError(no token data in messages)Acceptance criteria
tests/test_apple_api.py(FakeSession/FakeResponsepattern) and keep it green: pagination offsets, nested splicing, video
skipping, 429 retry, non-200 error.
Done in
coop/apple-music-gateway(commit491b188):app/apple_api.pyported from the plugin —AppleTrack/ApplePlaylistdataclasses with identical field names,AppleAPIClientwithAuthorization: Bearer <dev>+Music-User-Tokenheaders, paginated fetch (limit 100 + offset, 0.25s page pause), nestedlibrary-playlistssplicing at the queue position,library-music-videos/library-albumsskipped, 429 retried up to 3x with 1s sleep, other non-200s raise a sanitizedAppleAPIError. Gateway additions:AppleAPIError.status_code(routes map Apple 401/403 to the re-login hint) andfetch_playlist_summaries()/fetch_playlist_tracks()so the /api/v1 endpoints fetch one playlist at a time. Portedtests/test_apple_api.pygreen: pagination offsets, nested splicing, video skipping, 429 retry, non-200 error (plus status_code and the two new methods).uv run pytest: 62 passed.