This crate is heavily inspired by spotipy- A spotify api wrapper implemented in Python
Rspotify is a lightweight wrapper for the Spotify Web API It includes helper functions for all Spotify's endpoints, such as fetching metadata (search and look-up of albums, artists, tracks, playlists, new releases) and user's information (follow users, artists and playlists, and saved tracks management).
rspotify supports all of the features of the Spotify Web API including access to all end points, and support for user authorization, notes that before accessing to any end points, you need to be authorized. For details on the capabilities you are encouraged to review the Spotify Web Endpoint Reference documentation.
Nowaday, thanks to reqwest
, rspotify
now supports system proxy by default. Reqwest
System proxies look in environment variables to set HTTP or HTTPS proxies. HTTP_PROXY
or http_proxy
provide http proxies for http connections while HTTPS_PROXY
or https_proxy
provide HTTPS proxies for HTTPS connections.(Notes that check this issue for more details)reqwest
system proxy doesn't support socks proxy for now,
cargo install rspotify
Or you could get it from github
Since all methods require user authorization now, you will need to generate an authorization token that indicates that the user has granted permission for your application to perform the given task. You will need to register your app to get the credentials necessary to make authorized calls.
Even if your script does not have an accessible URL you need to specify one when registering your application where the spotify authentication API will redirect to after successful login. The URL doesn't need to work or be accessible, you can specify "http://localhost/", after successful login you just need to copy the "http://localhost/?code=..." URL from your browser and paste it to the console where your application is running. For example:
In order to help other developers to get used to rspotify
, I registerd a Spotify account with temporary email. Your guys could test rspotify
with this account's CLIENT_ID
and CLIENT_SECRET
, check .env file for more details.
If you have a use case you are interested in, you could check the examples, which has all kinds of detailed examples. For example, If you want to get recently played history, you could check current_user_recently_played. This is the example code:
[dependencies]
rspotify = { version = "0.9"}
tokio = { version = "0.2", features = ["full"] }
extern crate rspotify;
use rspotify::client::Spotify;
use rspotify::oauth2::SpotifyClientCredentials;
use rspotify::senum::Country;
#[tokio::main]
async fn main() {
// Set client_id and client_secret in .env file or
// export CLIENT_ID="your client_id"
// export CLIENT_SECRET="secret"
let client_credential = SpotifyClientCredentials::default().build();
// Or set client_id and client_secret explictly
// let client_credential = SpotifyClientCredentials::default()
// .client_id("this-is-my-client-id")
// .client_secret("this-is-my-client-secret")
// .build();
let spotify = Spotify::default()
.client_credentials_manager(client_credential)
.build();
let birdy_uri = "spotify:artist:2WX2uTcsvV5OnS0inACecP";
let tracks = spotify
.artist_top_tracks(birdy_uri, Country::UnitedStates)
.await;
println!("{:?}", tracks.unwrap());
}
There is an optional "blocking" client API that can be enabled:
[dependencies]
rspotify = { version = "0.9", features=["blocking"]}
extern crate rspotify;
use rspotify::blocking::client::Spotify;
use rspotify::blocking::oauth2::SpotifyClientCredentials;
use rspotify::senum::Country;
fn main() {
let client_credential = SpotifyClientCredentials::default().build();
let spotify = Spotify::default()
.client_credentials_manager(client_credential)
.build();
let birdy_uri = "spotify:artist:2WX2uTcsvV5OnS0inACecP";
let tracks = spotify.artist_top_tracks(birdy_uri, Country::UnitedStates);
println!("{:?}", tracks.unwrap());
}
-
Albums:
-
Artists:
-
Browse:
-
Track:
- Get a Track
- Get several tracks
- Get current user's currently playing track
- Get current user's saved tracks
- Remove current user's saved tracks
- Check current user's saved tracks
- Current user add tracks
- Get current user's top tracks
- Get current user's recently played tracks
- Get audio features for a track
- Get audio features for several tracks
- Get audio analysis for a track
-
Player
- Get current user's available devices
- Get information about current user's current playback
- Get current user's currently playing track
- Transfer current user's playback
- Start/Resume current user’s playback
- Pause current user's playback
- Skip current user's playback to next track
- Skip current user's playback to previous track
- Seek to position in currently playing track
- Set repeat mode on current user's playback
- Set volume for current user's playback
- Toggle shuffle for current user's playback
- Add an item to the end of current user's playback queue
-
Show:
-
Episodes
-
Search:
-
User:
-
Playlist:
- Get a Playlist
- Get a List of a User's Playlist
- Get a Playlists's tracks
- Creates a playlist for a user
- Change playlist's details
- Unfollowsa playlist for a user
- Adds tracks to a playlist
- Replace all tracks in a playlist
- Reorder tracks in a playlist
- Remove tracks from a playlist
- Remove specific tracks from a playlist
- User follow a playlist
- Check user following playlist
- Get a list of Spotify featured playlists
-
Misc
For more API information, you could check rspotify Api documentation
Please see the CHANGELOG for a release history.
If you find any problem or have suggestions about this crate, please submit an issue. Moreover, any pull request ,code review and feedback are welcome.