Skip to content

Spotify: Batch Spotify spotifysync API calls#6485

Merged
snejus merged 29 commits intobeetbox:masterfrom
arsaboo:spotify_batch
Apr 29, 2026
Merged

Spotify: Batch Spotify spotifysync API calls#6485
snejus merged 29 commits intobeetbox:masterfrom
arsaboo:spotify_batch

Conversation

@arsaboo
Copy link
Copy Markdown
Contributor

@arsaboo arsaboo commented Mar 31, 2026

This changes the Spotify plugin to batch spotifysync lookups instead of making per-track API calls. It now:

  • batches track metadata requests through /v1/tracks
  • batches audio-features requests through /v1/audio-features
  • deduplicates repeated Spotify track IDs within a run
  • preserves the existing behavior that disables audio-features fetching after a Spotify 403

The previous implementation made one metadata request and one audio-features request per track, which was inefficient for larger libraries and increased the chance of hitting rate limits. Batching reduces request volume substantially while keeping the stored fields and user-facing behavior the same.

  • Changelog. (Add an entry to docs/changelog.rst to the bottom of one of the lists near the top of the document.)
  • Tests. (Very much encouraged but not strictly required.)

@arsaboo arsaboo requested a review from a team as a code owner March 31, 2026 23:38
Copilot AI review requested due to automatic review settings March 31, 2026 23:38
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

PR make Spotify spotifysync do fewer HTTP call. It batch track metadata and audio-features fetch, so big library not hit rate limit so fast.

Changes:

  • Add batch fetch for /v1/tracks (50 ids per request) and /v1/audio-features (100 ids per request).
  • Deduplicate repeated Spotify track IDs within one run of _fetch_info.
  • Add tests for chunking, endpoint usage, dedupe, and 403-disable behavior; add changelog entry.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
beetsplug/spotify.py Implement batch endpoints + ID chunking/dedupe and shared disable logic for audio features.
test/plugins/test_spotify.py Add response mocks + assertions for batching/dedupe/403 behavior.
docs/changelog.rst Add Unreleased changelog entry for Spotify batching change.

Comment thread beetsplug/spotify.py Outdated
Comment thread beetsplug/spotify.py Outdated
Comment thread docs/changelog.rst
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 31, 2026

Codecov Report

❌ Patch coverage is 83.13253% with 14 lines in your changes missing coverage. Please review.
✅ Project coverage is 72.02%. Comparing base (20b0dd3) to head (e84ce41).
⚠️ Report is 30 commits behind head on master.

Files with missing lines Patch % Lines
beetsplug/spotify.py 82.05% 6 Missing and 8 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6485      +/-   ##
==========================================
- Coverage   72.05%   72.02%   -0.04%     
==========================================
  Files         159      159              
  Lines       20562    20622      +60     
  Branches     3260     3272      +12     
==========================================
+ Hits        14816    14852      +36     
- Misses       5055     5063       +8     
- Partials      691      707      +16     
Files with missing lines Coverage Δ
beets/library/migrations.py 96.49% <100.00%> (-0.12%) ⬇️
beets/util/__init__.py 79.23% <100.00%> (+0.12%) ⬆️
beetsplug/spotify.py 62.59% <82.05%> (+11.99%) ⬆️

... and 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@JOJ0 JOJ0 added the plugin Pull requests that are plugins related label Apr 4, 2026
@snejus snejus added spotify spotify plugin and removed plugin Pull requests that are plugins related labels Apr 4, 2026
Copy link
Copy Markdown
Member

@snejus snejus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of comments

Comment thread beetsplug/spotify.py Outdated
Comment thread beetsplug/spotify.py Outdated
Comment thread docs/changelog.rst Outdated
Comment thread beetsplug/spotify.py Outdated
Comment thread beetsplug/spotify.py Outdated
Comment thread beetsplug/spotify.py Outdated
Comment thread beetsplug/spotify.py Outdated
Comment thread beetsplug/spotify.py Outdated
Comment thread beetsplug/spotify.py Outdated
Comment thread beetsplug/spotify.py Outdated
Comment thread beetsplug/spotify.py Outdated
Comment thread beetsplug/spotify.py Outdated
Comment thread beetsplug/spotify.py Outdated
Comment thread beetsplug/spotify.py Outdated
Comment thread beetsplug/spotify.py Outdated
Comment thread beetsplug/spotify.py
Comment thread beetsplug/spotify.py Outdated
Comment thread beetsplug/spotify.py
@snejus
Copy link
Copy Markdown
Member

snejus commented Apr 27, 2026

@arsaboo let me know once you've addressed all my comments (I see the edits to irrelevant docstrings are not yet fixed) and I will re-review!

@arsaboo
Copy link
Copy Markdown
Contributor Author

arsaboo commented Apr 27, 2026

@snejus, all comments are addressed, and the docstrings have been reverted (unless I missed something).

Comment thread beetsplug/spotify.py Outdated
Comment thread beetsplug/spotify.py Outdated
Comment thread beetsplug/spotify.py Outdated
Comment thread beetsplug/spotify.py Outdated
Comment thread test/plugins/test_spotify.py Outdated
Comment thread docs/changelog.rst
@snejus
Copy link
Copy Markdown
Member

snejus commented Apr 28, 2026

Apologies, I accidentally approved but I intended to select Request changes 😅

arsaboo and others added 3 commits April 28, 2026 07:46
Sync with upstream beets/master and resolve changelog conflict,
keeping only the Spotify batch entry in the Unreleased section.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@arsaboo
Copy link
Copy Markdown
Contributor Author

arsaboo commented Apr 29, 2026

@snejus most of the formatting changes are made by doctstrfmt for the build to pass; there are no meaningful changes there. I reverted everything else.

@snejus
Copy link
Copy Markdown
Member

snejus commented Apr 29, 2026

docstrfmt should only be used to format rst files, not Python files (using poe format-docs).

The issue with your unrelated changes in the docstrings is that this obfuscates the original author of that docstring. I often git blame specific lines in the codebase to find the relevant context for that line or change.

Please undo the adjustments that I reviewed above.

@arsaboo
Copy link
Copy Markdown
Contributor Author

arsaboo commented Apr 29, 2026

@snejus cleaned up everything. Apologies for the back and forth.

Copy link
Copy Markdown
Member

@snejus snejus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@snejus snejus merged commit 48582a3 into beetbox:master Apr 29, 2026
18 checks passed
@arsaboo arsaboo deleted the spotify_batch branch April 29, 2026 14:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

spotify spotify plugin

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants