-
-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LB-1700: Get all tracks for apple music playlist #154
base: main
Are you sure you want to change the base?
Conversation
The current implementation using the Apple Music API "?include=tracks" only returns the first 100 tracks. To get the rest if there are more, we need to fetch them separately using another endpoint ("/tracks")
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there are no error handling improvements, good to merge.
offset = len(tracks) | ||
# endpoint returns 100 tracks per call max -> run iteratively with an offset until there are no more tracks | ||
while True: | ||
url = f"{APPLE_MUSIC_URL}/me/library/playlists/{playlist_id}/tracks?limit=100&offset={offset}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does any more error checking need to be added here? rate limiting or otherwise?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to ensure that errors that might happen are not silently dropped.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A retry strategy is set up at the class level, not sure if that handles rate limiting though looks like urllib3 Retry class handles rate limiting headers by default
https://github.com/metabrainz/troi-recommendation-playground/blob/6293c4993d40048492e20270269ec546b1b21be9/troi/tools/utils.py#L183C5-L197C16
What should be the strategy for handling other errors?
The API will sometimes return a json body with an error
key, so I could try parsing for that and logging the error message (instead of the current caught KeyError) as an improvement.
Anything else that I should look out for?
Parse the response body for errors, log any error found
0e6eaaf
to
a82eaa3
Compare
Following #153, fixing the same issue for Apple Music.
The current implementation using the Apple Music API "?include=tracks" only returns the first 100 tracks with no pagination option.
To get the rest of the tracks if there are more, we need to fetch them separately using another endpoint ("/tracks"). Thankfully we can reuse the included tracks from the first call and start at offset 100.