Add include/extend/fields scoped query params to all catalog methods#26
Open
ParkJeongseop wants to merge 1 commit into
Open
Add include/extend/fields scoped query params to all catalog methods#26ParkJeongseop wants to merge 1 commit into
ParkJeongseop wants to merge 1 commit into
Conversation
Apple Music API accepts scoped parameters (include[songs]=albums, extend[songs]=..., fields[artists]=name) on most catalog endpoints, including /search, but the wrapper had no way to send them. - Add _build_scoped_params helper that turns dict/str/list inputs into the appropriate query parameter shape (include[type]=... vs include=...). - Wire automatic scoping into _get so any method passing include / extend / fields kwargs gets dict-form support transparently. - Extend signatures of every catalog fetch / relationship / by-isrc / search / charts method with include, extend, fields keyword arguments. Backward compatible: passing a plain string still produces the unscoped include=... form, matching previous behavior. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add
include/extend/fieldsscoped query params to all catalog methodsSummary
Apple Music's catalog API accepts scoped query parameters such as
include[songs]=albums,extend[songs]=extendedAssetUrls, andfields[artists]=name,urlon most endpoints — including/search— to embedrelationships, request additional attributes, or trim response payloads. The
wrapper currently exposes only
include(as a plain string) on a subset ofmethods, and not at all on
search(),charts(), or any of the*_relationship/*_relationship_viewmethods. As a result, callers can'task for relationship data in search results, can't use
extendorfieldsanywhere, and have no way to send the scoped
include[<resource>]=...formthat the search endpoint requires.
This PR adds
include,extend, andfieldsto every catalog-fetching methodin a single, consistent shape, with full backward compatibility.
What changed
_build_scoped_paramshelper — Static method that converts the threescoped inputs into the correct query-parameter shape:
include={'songs': ['albums', 'artists']}→include[songs]=albums,artistsinclude={'songs': 'albums,artists'}→include[songs]=albums,artistsinclude=['albums', 'artists']→include=albums,artistsinclude='albums'→include=albumsNone/ empty → omitted entirelyAutomatic translation in
_get— When any caller passesinclude,extend, orfieldsas a kwarg to_get, those values are routed through_build_scoped_paramsbefore being sent torequests. This means new andexisting methods alike get dict-form support without each one re-implementing
the conversion.
Method signatures extended —
include,extend, andfieldskeywordarguments added to every catalog method that accepts query parameters:
album,albums,song,songs,songs_by_isrc,artist,artists,playlist,playlists,music_video,music_videos,music_videos_by_isrc,station,stations,curator,curators,activity,activities,apple_curator,apple_curatorsalbum_relationship,album_relationship_view,music_video_relationship,music_video_relationship_view,playlist_relationship,playlist_relationship_view,song_relationship,artist_relationship,artist_relationship_view,curator_relationship,activity_relationship,apple_curator_relationshipsearch,chartsgenre*andstorefront*are unchanged because the Apple Music API doesnot expose relationships on those resources.
Backward compatibility
Fully backward compatible. All three new parameters default to
None, inwhich case nothing is sent. The existing string form (
include='albums') isstill accepted on every method that previously accepted it and produces the
exact same query string as before:
The new dict form unlocks scoped params on
search()and similar methods thatneed
include[<resource>]rather than the bareinclude:No method signatures had positional parameters removed or reordered. The new
keyword arguments are appended at the end.
Verification
Live calls against the Apple Music catalog API (
storefront='kr').search()with scoped include — previously impossibleBefore:
relationshipskey not present in response — the search endpointsilently ignored any
include=because the wrapper had no way to sendinclude[songs]=.... To find the album id you had to make a secondsong()request per result.
After:
songs_by_isrc()withinclude— pre-existing form, unchangedSame behavior and same query string as before this PR.
Unit-level shape check on
_build_scoped_paramsTest plan
_build_scoped_paramsproduces the expected query-parameter dict fordict, str, list, mixed, and empty inputs
include,extend, andfieldskeyword arguments (inspect.signaturecheck across all 34methods)
am.song(track_id, include='albums')(existing string form) stillembeds
relationships.albumsagainst the live API — no regressionam.search(..., include={'songs': ['albums']})(new scoped form)embeds
relationships.albumsin search results against the live APIam.songs_by_isrc([isrc], include='albums')continues to embedrelationships against the live API
requestscorrectly percent-encodes the bracketed parameter names(
include[songs]→include%5Bsongs%5D); Apple Music accepts theencoded form