Rspotify - a Rust client for The Spotify Web API
Disclaimer
This crate is heavily inspired by spotipy- A spotify api wrapper implemented in Python
Description
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).
Features
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,
Installation
cargo install rspotify
Or you could get it from github
Getting Started
Authorization
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.
Examples
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:
[]
= { = "0.9"}
= { = "0.2", = ["full"] }
extern crate rspotify;
use Spotify;
use SpotifyClientCredentials;
use Country;
async
Blocking API example
There is an optional "blocking" client API that can be enabled:
[]
= { = "0.9", =["blocking"]}
extern crate rspotify;
use Spotify;
use SpotifyClientCredentials;
use Country;
Examples
-
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
API Documentation
For more API information, you could check rspotify Api documentation
CHANGELOG
Please see the CHANGELOG for a release history.
Contribution
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.