Wolframe Spotify Canvas
Rust library for fetching Spotify Canvas (looping visuals) via the internal GraphQL Pathfinder API.
This Rust library reverse-engineers the internal Spotify GraphQL Pathfinder API used by the official Spotify Web Player. It replaces the deprecated and non-functional REST API endpoints (canvaz-cache).
🚀 Features
- Pathfinder API: Uses the correct
api-partner.spotify.com/pathfinder/v2endpoint with Persisted Queries. - Client Token Autonomy: Automatically fetches, generates, and manages the required
client-token(imitating a real Web Player session). - Configurable: Built to withstand frontend updates. You can override the Persisted Query Hash and Operation Name if Spotify changes them.
- Type-Safe: Robust error handling for network failures, missing tokens, and API changes.
📦 Installation
Add this to your Cargo.toml:
[]
= "1.0.0"
= { = "1", = ["full", "macros"] }
Minimum Supported Rust Version (MSRV)
This crate requires Rust 1.83 or newer.
⚡ Usage
use ;
use env;
async
Check examples/simple.rs for a runnable example.
🔍 Observability
This crate uses tracing for structured logging.
Log Levels
INFO— Canvas fetch operations (default)DEBUG— Token management internalsTRACE— Device ID generation, low-level details
Example Setup
fmt
.with_env_filter
.init;
OpenTelemetry Integration
Spans are automatically propagated to distributed tracing backends (Jaeger, Datadog) when using tracing-opentelemetry.
🛠 Technical Details (Reverse Engineering)
Spotify moved away from the simple canvaz-cache REST API to a complex GraphQL implementation. This library bridges that gap.
The "Hash Trap"
Spotify's GraphQL API does not accept raw queries. It uses Persisted Queries, where the client sends a SHA-256 hash of the query.
- Default Hash:
575138ab27cd5c1b3e54da54d0a7cc8d85485402de26340c2145f0f6bb5e7a9f(Hardcoded default, but overridable). - Operation Name:
canvas(Crucial distinction: older attempts usedgetCanvaswhich returns 400). - Variable Name:
trackUri(Crucial distinction: formerlyuri).
Authentication
A standard access token is not enough. The API requires a client-token header.
- This library emulates the flow of
clienttoken.spotify.com, generating a randomdevice_idand exchanging it for a valid, short-livedclient-token.
🤝 Contributing
Contributions are welcome! Especially if Spotify updates their API hash—pull requests updating the DEFAULT_CANVAS_HASH are highly appreciated.
📄 License
MIT License. See LICENSE for details.
Built with ❤️ by the Wolframe Team.