Spotify-rs
Spotify-rs provides an easy-to-use abstraction over the Spotify Local API.
⚠️ DEPRECATION WARNING
This library is deprecated and no longer maintained. Spotify has removed the Local API and SpotifyWebHelper from their desktop clients, so this library is no longer useful. I'm keeping it around for historical purposes, but there's no point in using it anymore.
What can I do with it
Features:
- Play a track using track ID or URI
- Pause/resume the currently played track
- Get currently played track (including album, artist, etc.)
- Get current volume
- Get Spotify client version and online status
- React to changes by long polling in a separate thread
And a few goodies:
- Automatically fixes broken (but recoverable) track IDs and URIs
- Check whether SpotifyWebHelper is running (Windows only)
Is the project still alive?
I haven't really worked on this library for a long time, but that's mostly because it's pretty much done. There aren't any significant bugs that I know of and the cli should work just fine. I've made an effort to port everything over from 2015 to 2021 edition and the code compiles (tested using Rust 1.64).
Examples
The following is a minimal example to show you what's possible with spotify-rs.
Please note that this example lacks proper error handling for the sake of brevity.
extern crate spotify;
use Spotify;
Example output:
Spotify Client (Version 1.0.42.151.g19de0aa6)
Playing: Rick Astley - Never Gonna Give You Up
Here's a complete example with long polling and better error handling:
extern crate spotify;
use ;
Example output:
Spotify Client (Version 1.0.42.151.g19de0aa6)
Now playing: Tim Minchin - White Wine In The Sun
Volume: 100%
Now playing: Tim Minchin - Encore
Volume: 50%
Volume: 76%
Now playing: Tim Minchin - Ready For This ?
Volume: 100%
F.A.Q.
It doesn't connect, what's wrong?
Make sure that Spotify is running and the SpotifyWebHelper process is active.
If you can't find SpotifyWebHelper.exe in your process list, you might have disabled it by accident. Here's how you enable it:
- Open Spotify
- Press
Ctrl+Pto open the preferences - Scroll down and click 'Show advanced settings'
- In the
Startup and Window Behavioursection,
enableAllow Spotify to be opened from the web.
You might wanna restart Spotify after doing that.
Update: I'm not sure if this option is still exposed nowadays. Spotify 1.1.95 (2022) on macOS doesn't seem to have this anymore, and I'm not sure if Spotify still exposes the local API at all. If it doesn't, this library is pretty much useless. If you know whether this still works, please open an issue and let me know!