Skip to content

feat(spotify): fetch the audio analysis - #758

Merged
LargeModGames merged 1 commit into
mainfrom
feat/analysis-data
Oct 12, 2026
Merged

LargeModGames merged 1 commit into
mainfrom
feat/analysis-data

Conversation

@LargeModGames

@LargeModGames LargeModGames commented Oct 12, 2026 •

Copy link
Copy Markdown
Owner

Summary

First half of bringing back the spotify-tui visualizer that read Spotify's audio analysis. Since #752 we have a Spotify session, and spclient /audio-attributes/v1/audio-analysis/{base62} returns the same JSON the Web API used to. This PR adds the data path only; #759 draws it. Nothing asks for an analysis in this PR, so users see no change.

  • infra/spotify: a router route GET audio-analysis/{id} answered from spclient on the app side with request_as_json, like the playlist reads, so no fork release is needed.
  • infra/network/mapping.rs: track_analysis maps the JSON into a slim TrackAnalysis (sections with tempo, key, mode and time signature; segments with their 12 pitches and loudness envelope). No rspotify type: its AudioAnalysis needs the fingerprint strings and rejects key -1.
  • core/app/audio_analysis.rs: AnalysisState with a stale-reply guard and one fetch per track. A 404 or an unreadable body is "no analysis"; any other failure (a 429, a timeout) is tried again after 10 s.
  • IoEvent::GetAudioAnalysis passes the auth gate on the pump and runs the fetch as a detached task through spotify_api_request_json_for, so a DJ library crawl cannot hold it up. It never opens the error screen.
  • want_audio_analysis and the audio_analysis() getter carry #[cfg_attr(not(test), allow(dead_code))] until feat(tui): bring back the pitch visualizer #759 uses them.

Testing

  • cargo fmt --all -- --check: ok
  • cargo clippy -- -D warnings, and the same with --no-default-features --features telemetry,tui, telemetry, and telemetry,gui,streaming,discord-rpc,self-update,scripting,mcp-server,mpris: all Finished
  • cargo test --no-default-features --features telemetry,tui: test result: ok. 1480 passed; 0 failed; 0 ignored
  • cargo test: test result: ok. 1928 passed; 0 failed; 6 ignored
  • Live, cargo test --lib infra::spotify::live_tests::audio_analysis -- --ignored --test-threads=1 --nocapture: sections: 14, segments: 1512, peak loudness -60.0 to -1.1 dB for "One More Time"

Additional notes

Stacked under #759. Merge both with gh stack merge.


💬 Questions or want to chat with other contributors? Join the spotatui Discord.

Summary by CodeRabbit

  • New Features
    • Added Spotify audio-analysis data fetching for tracks, including musical sections, tempo, key, time signature, loudness, and pitch information.
    • Analysis results are reused while available, and failed requests can be retried after a short delay.

@LargeModGames
LargeModGames added this pull request to stack #760 October 12, 2026 09:33
@coderabbitai

coderabbitai Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: LargeModGames/spotatui/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: dce2c013-0c0c-44e5-9778-f2c625d807ca

📥 Commits

Reviewing files that changed from the base of the PR and between dad318b and 7ba3b37.


📒 Files selected for processing (9)
  • src/core/app/audio_analysis.rs
  • src/core/app/construction.rs
  • src/core/app/mod.rs
  • src/infra/network/mapping.rs
  • src/infra/network/metadata.rs
  • src/infra/network/mod.rs
  • src/infra/spotify/catalog.rs
  • src/infra/spotify/live_tests.rs
  • src/infra/spotify/router.rs

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.



📝 Walkthrough
📝 Walkthrough

Walkthrough

The change adds Spotify track audio-analysis data types and application state, an audio-analysis endpoint and route, JSON mapping, and asynchronous fetching with result storage.

Changes

Audio Analysis Retrieval

Layer / File(s) Summary
Analysis data and application state
src/core/app/audio_analysis.rs, src/core/app/construction.rs, src/core/app/mod.rs
Adds section and segment data types and fetch states. The application initializes analysis as idle, avoids duplicate requests, retries failures after 10 seconds, and ignores results for tracks that are no longer loading.
Spotify audio-analysis endpoint
src/infra/spotify/catalog.rs, src/infra/spotify/router.rs, src/infra/spotify/live_tests.rs
Adds a GET route and catalogue request for track audio analysis. The request validates the track ID, and tests cover route parsing and live response parsing.
Fetch, map, and store analysis
src/infra/network/mapping.rs, src/infra/network/metadata.rs, src/infra/network/mod.rs
Maps Spotify JSON into analysis data, including time and pitch conversions. Adds a network event and asynchronous fetch handling for successful, missing, and failed results.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant App
  participant Network
  participant Fetch as metadata::fetch_audio_analysis
  participant Spotify as Spotify audio-analysis route
  participant Mapping as mapping::track_analysis
  App->>Network: Dispatch GetAudioAnalysis(track_id)
  Network->>Fetch: Start fetch for track_id
  Fetch->>Spotify: Request audio analysis
  Spotify-->>Fetch: Return JSON response
  Fetch->>Mapping: Map JSON to TrackAnalysis
  Mapping-->>Fetch: Return mapped analysis
  Fetch->>App: Store fetch result
Loading

Merge Risk: ⚪ Minimal · up to 7ba3b

This change adds the data path for fetching Spotify audio analysis. Nothing requests an analysis yet, so users see no behavior change. No merge-blocking risk was identified.

Pre-merge checks | Passed 4
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title uses the allowed conventional-commit prefix and scope. It concisely and accurately describes the audio-analysis fetching changes.

✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR

🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

✨ Simplify code
  • Commit to this branch
  • Create a new PR

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@LargeModGames LargeModGames changed the title feat(spotify): fetch the audio analysis from the internal API feat(spotify): fetch the audio analysis Oct 12, 2026
GET audio-analysis/{id} is answered from spclient audio-attributes, mapped into a slim TrackAnalysis with the segment loudness envelope, and fetched by a detached task into App state. A 404 is no analysis; any other failure is tried again after 10 s. Nothing asks for it yet.
@codecov

codecov Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

@LargeModGames
LargeModGames merged commit adfb522 into main Oct 12, 2026
35 checks passed
@LargeModGames
LargeModGames deleted the feat/analysis-data branch October 12, 2026 09:52
LargeModGames added a commit that referenced this pull request Oct 12, 2026
# Summary

Second half: the Spotify Pitch view on the analysis screen, drawn from
the audio analysis that #758 fetches.

- While a Spotify track plays, `v` opens Spotify Pitch: the 12 pitch
classes (C to B) of the segment playing now, with a row of note names,
and the tempo, key and time signature of the current section with their
confidence. Every other source opens on the saved capture style, as
before. "Spotify track" means what plays now, so it also works when
Spotify plays on another Connect device.
- It looks and moves like Cava: the 12 values glide between segments,
are scaled by the segment's loudness envelope (-40 dB empty, 0 dB full),
and feed the same `render_cava` renderer through a small meter that
rises in about 30 ms and falls with gravity. My first versions drew the
raw data and looked jumpy; this is the version I tested and kept.
- A local clock moves the position on between the native player's 1 s
`PositionChanged` updates, and blends a correction under 1 s in over 400
ms, so the bars do not jump each second. A seek still applies at once.
- `V` cycles Cava, Bar Graph and Spotify Pitch while a Spotify track
plays. Pitch is never written to `config.yml`, so the config stays
readable by older releases, and leaving Pitch with `V` holds until the
screen is opened again. Audio capture is closed while Pitch shows.
- The analysis stays while its track plays, so the help overlay or
leaving the screen does not fetch it again.
- Compared with the old spotify-tui view: the bars show the segment
playing now instead of the next one, the last section no longer blanks
the screen, and an undetected key shows "?" instead of C.

# Testing

- `cargo fmt --all -- --check`: ok
- `cargo clippy -- -D warnings`, and the same with
`--no-default-features --features telemetry,tui`, `telemetry`, and
`telemetry,gui,streaming,discord-rpc,self-update,scripting,mcp-server,mpris`:
all `Finished`
- `cargo test --no-default-features --features telemetry,tui`: `test
result: ok. 1502 passed; 0 failed; 0 ignored`
- `cargo test`: `test result: ok. 1950 passed; 0 failed; 6 ignored`
- Manual on Windows with native streaming: Pitch opens for a Spotify
track, `V` cycles through the three styles, a Qobuz track opens on Cava.
A temporary log probe (not committed) confirmed that the clock moves 16
ms per frame between position updates.

# Additional notes

Stacked on #758. Not covered: the GUI frontend has no analysis screen,
so it never asks for an analysis. The view needs no audio capture, so it
also works in builds without `audio-viz`.

---
<sub>💬 Questions or want to chat with other contributors? Join the
[spotatui Discord](https://spotatui.com/discord).</sub>


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Added a Spotify Pitch visualizer that shows pitch-class levels for the
current section, along with tempo, key, time signature, and confidence.
* Press `v` during Spotify playback to open Spotify Pitch. Press `V` to
cycle among Cava, Bar Graph, and Spotify Pitch; other audio sources
continue to use the saved visualizer style.
* Pitch levels now respond to playback timing, and the view displays
distinct states when analysis is loading, unavailable, or unsuccessful.
* **Documentation**
* Updated the feature guide and changelog with Spotify Pitch controls
and details.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
LargeModGames added a commit that referenced this pull request Oct 12, 2026
# Summary

Version bump and changelog for v0.45.0, the first release with the
desktop app. No application code changes.

- `Cargo.toml`, `Cargo.lock`, `desktop/Cargo.toml` and
`desktop/Cargo.lock` go to 0.45.0. The desktop version must match the
root package, a desktop test pins that.
- `CHANGELOG.md`: `## [Unreleased]` is now `## [v0.45.0] 2026-10-12`. I
checked every PR merged since v0.44.0 against it: #757, #758 (in the
pitch visualizer entry), #759, #734, #751 and #763 have entries; #622,
#755 and #762 are docs only. The four desktop entries got the empty line
between them that the other entries have.
- `SECURITY.md` names 0.45 as the supported version.

# Testing

```
cargo metadata --locked --format-version 1 > /dev/null
root metadata --locked: ok
cargo metadata --locked --manifest-path desktop/Cargo.toml --format-version 1 > /dev/null
desktop metadata --locked: ok
cargo check --locked
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 31.36s
cargo package --list --allow-dirty
394 files; none under desktop/ or gui/
```

# Additional notes

This tag is the first run of the `desktop` and `desktop-manifest`
release jobs. The updater signing secrets are set and the public key is
in `desktop/tauri.conf.json`, so the release attaches signed installers
and `latest.json`, and installed desktop apps update themselves from
then on.

---
<sub>💬 Questions or want to chat with other contributors? Join the
[spotatui Discord](https://spotatui.com/discord).</sub>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant