pub struct Spotify { /* private fields */ }
Expand description
An authenticated instance of the Spotify API client. Can be used to make requests in the given scope.
Implementations§
source§impl Spotify
impl Spotify
sourcepub fn get_album(
&self,
album_id: &str,
market: Option<&str>
) -> Result<Album, SpotifyError>
pub fn get_album( &self, album_id: &str, market: Option<&str> ) -> Result<Album, SpotifyError>
Get an album: https://developer.spotify.com/documentation/web-api/reference/#/operations/get-an-album
Required scope: none
Arguments
album_id
- The Spotify ID of the album.market
- An ISO 3166-1 alpha-2 country code.
sourcepub fn get_albums(
&self,
album_ids: Vec<&str>,
market: Option<&str>
) -> Result<Vec<Album>, SpotifyError>
pub fn get_albums( &self, album_ids: Vec<&str>, market: Option<&str> ) -> Result<Vec<Album>, SpotifyError>
Get several albums: https://developer.spotify.com/documentation/web-api/reference/#/operations/get-multiple-albums
Required scope: none
Arguments
album_ids
- A vector of Spotify IDs for the albums.market
- An ISO 3166-1 alpha-2 country code.
sourcepub fn get_album_tracks(
&self,
album_id: &str,
market: Option<&str>,
limit: Option<u32>,
offset: Option<u32>
) -> Result<SpotifyCollection<Track>, SpotifyError>
pub fn get_album_tracks( &self, album_id: &str, market: Option<&str>, limit: Option<u32>, offset: Option<u32> ) -> Result<SpotifyCollection<Track>, SpotifyError>
Get an album’s tracks: https://developer.spotify.com/documentation/web-api/reference/#/operations/get-an-albums-tracks
Required scope: none
Arguments
album_id
- The Spotify ID of the album.market
- An ISO 3166-1 alpha-2 country code.limit
- The maximum number of tracks to return. Default: 20. Minimum: 1. Maximum: 50.offset
- The index of the first track to return. Default: 0 (the first object). Use with limit to get the next set of tracks.
sourcepub fn get_saved_albums(
&self,
limit: Option<u32>,
market: Option<&str>,
offset: Option<u32>
) -> Result<SpotifyCollection<DatedAlbum>, SpotifyError>
pub fn get_saved_albums( &self, limit: Option<u32>, market: Option<&str>, offset: Option<u32> ) -> Result<SpotifyCollection<DatedAlbum>, SpotifyError>
Get albums saved in user’s library: https://developer.spotify.com/documentation/web-api/reference/#/operations/get-users-saved-albums
Required scope: user-library-read
Arguments
limit
- The maximum number of albums to return. Default: 20. Minimum: 1. Maximum: 50.offset
- The index of the first album to return. Default: 0 (the first object). Use with limit to get the next set of albums.
sourcepub fn save_albums(&self, album_ids: Vec<&str>) -> Result<(), SpotifyError>
pub fn save_albums(&self, album_ids: Vec<&str>) -> Result<(), SpotifyError>
Save albums for current user: https://developer.spotify.com/documentation/web-api/reference/#/operations/save-albums-user
Required scope: user-library-modify
Arguments
album_ids
- A vector of Spotify IDs for the albums.
sourcepub fn remove_albums(&self, album_ids: Vec<&str>) -> Result<(), SpotifyError>
pub fn remove_albums(&self, album_ids: Vec<&str>) -> Result<(), SpotifyError>
Remove saved albums from current user’s library: https://developer.spotify.com/documentation/web-api/reference/#/operations/remove-albums-user
Required scope: user-library-modify
Arguments
album_ids
- A vector of Spotify IDs for the albums.
sourcepub fn check_saved_albums(
&self,
album_ids: Vec<&str>
) -> Result<Vec<bool>, SpotifyError>
pub fn check_saved_albums( &self, album_ids: Vec<&str> ) -> Result<Vec<bool>, SpotifyError>
Checks to see if albums are already saved to user’s library: https://developer.spotify.com/documentation/web-api/reference/#/operations/check-users-saved-albums
Required scope: user-library-read
Arguments
album_ids
- A vector of Spotify IDs for the albums.
sourcepub fn get_new_releases(
&self,
country: Option<&str>,
limit: Option<u32>,
offset: Option<u32>
) -> Result<SpotifyCollection<Album>, SpotifyError>
pub fn get_new_releases( &self, country: Option<&str>, limit: Option<u32>, offset: Option<u32> ) -> Result<SpotifyCollection<Album>, SpotifyError>
Get a list of new album releases featured in Spotify: https://developer.spotify.com/documentation/web-api/reference/#/operations/get-new-releases
Required scope: none
Arguments
country
- An ISO 3166-1 alpha-2 country code.limit
- The maximum number of albums to return. Default: 20. Minimum: 1. Maximum: 50.offset
- The index of the first album to return. Default: 0 (the first object). Use with limit to get the next set of albums.
source§impl Spotify
impl Spotify
sourcepub fn get_artist(&self, artist_id: &str) -> Result<Artist, SpotifyError>
pub fn get_artist(&self, artist_id: &str) -> Result<Artist, SpotifyError>
Get information on a single aritst: https://developer.spotify.com/documentation/web-api/reference/#/operations/get-an-artist
Required scope: none
Arguments
artist_id
- The Spotify ID of the artist.
sourcepub fn get_several_artists(
&self,
artist_ids: Vec<&str>
) -> Result<Vec<Artist>, SpotifyError>
pub fn get_several_artists( &self, artist_ids: Vec<&str> ) -> Result<Vec<Artist>, SpotifyError>
Gets information on several artists: https://developer.spotify.com/documentation/web-api/reference/#/operations/get-multiple-artists
Required scope: none
Arguments
artist_ids
- A vector of the Spotify IDs for the artists. Maximum: 50 IDs.
sourcepub fn get_artist_albums(
&self,
artist_id: &str,
include_groups: Option<Vec<&str>>,
limit: Option<u32>,
market: Option<&str>,
offset: Option<u32>
) -> Result<SpotifyCollection<Album>, SpotifyError>
pub fn get_artist_albums( &self, artist_id: &str, include_groups: Option<Vec<&str>>, limit: Option<u32>, market: Option<&str>, offset: Option<u32> ) -> Result<SpotifyCollection<Album>, SpotifyError>
Get artist’s albums: https://developer.spotify.com/documentation/web-api/reference/#/operations/get-an-artists-albums
Required scope: none
Arguments
artist_id
- The Spotify ID of the artist.include_groups
- A list of keywords that will be used to filter the response. If not supplied, all album types will be returned. Valid values: album, single, appears_on, compilation.market
- An ISO 3166-1 alpha-2 country code.limit
- The maximum number of items to return. Default: 20. Minimum: 1. Maximum: 50.offset
- The index of the first item to return. Default: 0 (the first object). Use with limit to get the next set of items.
sourcepub fn get_artist_top_tracks(
&self,
artist_id: &str,
market: &str
) -> Result<Vec<Artist>, SpotifyError>
pub fn get_artist_top_tracks( &self, artist_id: &str, market: &str ) -> Result<Vec<Artist>, SpotifyError>
Get artist’s top tracks: https://developer.spotify.com/documentation/web-api/reference/#/operations/get-an-artists-top-tracks
Required scope: none
Arguments
artist_id
- The Spotify ID of the artist.market
- An ISO 3166-1 alpha-2 country code.
Get artist’s related to specified artist: https://developer.spotify.com/documentation/web-api/reference/#/operations/get-an-artists-related-artists
Required scope: none
Arguments
artist_id
- The Spotify ID of the artist.
source§impl Spotify
impl Spotify
sourcepub fn get_several_browse_categories(
&mut self,
country: Option<&str>,
locale: Option<&str>,
limit: Option<i32>,
offset: Option<i32>
) -> Result<SpotifyCollection<Category>, SpotifyError>
pub fn get_several_browse_categories( &mut self, country: Option<&str>, locale: Option<&str>, limit: Option<i32>, offset: Option<i32> ) -> Result<SpotifyCollection<Category>, SpotifyError>
Get a set of categories used to tag items in Spotify: https://developer.spotify.com/documentation/web-api/reference/#/operations/get-categories
Requires scope: None
Arguments
country
- An ISO 3166-1 alpha-2 country code.locale
- The desired language, consisting of an ISO 639 language code and an ISO 3166-1 alpha-2 country code, joined by an underscore.limit
- The maximum number of categories to return. Default: 20. Minimum: 1. Maximum: 50.offset
- The index of the first category to return. Default: 0 (the first object). Use with limit to get the next set of categories.
sourcepub fn get_single_browse_category(
&mut self,
category_id: &str,
country: Option<&str>,
locale: Option<&str>
) -> Result<Category, SpotifyError>
pub fn get_single_browse_category( &mut self, category_id: &str, country: Option<&str>, locale: Option<&str> ) -> Result<Category, SpotifyError>
Gets a single Spotify category: https://developer.spotify.com/documentation/web-api/reference/#/operations/get-a-category
Requires scope: None
Arguments
category_id
- The Spotify category ID for the category.country
- An ISO 3166-1 alpha-2 country code.locale
- The desired language, consisting of an ISO 639 language code and an ISO 3166-1 alpha-2 country code, joined by an underscore.
source§impl Spotify
impl Spotify
sourcepub fn get_available_genre_seeds(&self) -> Result<Vec<String>, SpotifyError>
pub fn get_available_genre_seeds(&self) -> Result<Vec<String>, SpotifyError>
Gets set of available genres: https://developer.spotify.com/documentation/web-api/reference/#/operations/get-recommendation-genres
Requires scope: none
source§impl Spotify
impl Spotify
sourcepub fn get_available_markets(&self) -> Result<Vec<String>, SpotifyError>
pub fn get_available_markets(&self) -> Result<Vec<String>, SpotifyError>
Gets a vector of all markets where Spotify is available: https://developer.spotify.com/documentation/web-api/reference/#/operations/get-available-markets
Requires scope: none
source§impl Spotify
impl Spotify
sourcepub fn get_playback_state(
&self,
market: Option<&str>
) -> Result<Playback, SpotifyError>
pub fn get_playback_state( &self, market: Option<&str> ) -> Result<Playback, SpotifyError>
Gets current playback state of current user: https://developer.spotify.com/documentation/web-api/reference/#/operations/get-information-about-the-users-current-playback Note: currently only supports Tracks and not Episodes. Unexpected behavior may occur with Episodes.
Requires scope: user-read-playback-state
Arguments
market
- An ISO 3166-1 alpha-2 country code.
sourcepub fn transfer_playback(
&self,
device_id: &str,
play: bool
) -> Result<(), SpotifyError>
pub fn transfer_playback( &self, device_id: &str, play: bool ) -> Result<(), SpotifyError>
Transfers playback to another device and whether or not the new device should play: https://developer.spotify.com/documentation/web-api/reference/#/operations/transfer-a-users-playback
Requires scope: user-modify-playback-state
Arguments
device_id
- The device id to transfer playback toplay
- Whether or not to start playback on the new device
sourcepub fn get_available_devices(&self) -> Result<Vec<Device>, SpotifyError>
pub fn get_available_devices(&self) -> Result<Vec<Device>, SpotifyError>
Gets all the available spotify devices for playback: https://developer.spotify.com/documentation/web-api/reference/#/operations/get-a-users-available-devices
Requires scope: user-read-playback-state
sourcepub fn get_currently_playing_track(
&self,
market: Option<&str>
) -> Result<Playback, SpotifyError>
pub fn get_currently_playing_track( &self, market: Option<&str> ) -> Result<Playback, SpotifyError>
Gets the currently playing track: https://developer.spotify.com/documentation/web-api/reference/#/operations/get-the-users-currently-playing-track Note: Currently this only supports tracks and not episodes. Weird behavior may occur if an episode is being played.
Requires scope: user-read-currently-playing
Arguments
market
- An ISO 3166-1 alpha-2 country code which the returned track should be in the market of
sourcepub fn start_resume_playback(
&self,
device_id: Option<&str>,
context: Option<SpotifyContext>,
track_ids: Option<Vec<&str>>,
offset_position: Option<i32>,
offset_track: Option<&str>,
position_ms: Option<i32>
) -> Result<(), SpotifyError>
pub fn start_resume_playback( &self, device_id: Option<&str>, context: Option<SpotifyContext>, track_ids: Option<Vec<&str>>, offset_position: Option<i32>, offset_track: Option<&str>, position_ms: Option<i32> ) -> Result<(), SpotifyError>
Start a new context in player or resume playback of a device: https://developer.spotify.com/documentation/web-api/reference/#/operations/start-a-users-playback
Requires scope: user-modify-playback-state
Arguments
device_id
- The id of the device to start playback oncontext
- The context to start playback on. Valid contexts: Album, Artist, Playlisttrack_ids
- The track ids to start playback onoffset_position
- Indicates where in the context the playback should start. For example, starting on the 2nd song of an album with offset=1.offset_track
- Indicates which track in context to begin playback on. This is a track id. Note: this will be ignored if offset_position is set.position_ms
- Where in the song to begin playback
sourcepub fn pause_playback(
&self,
device_id: Option<&str>
) -> Result<(), SpotifyError>
pub fn pause_playback( &self, device_id: Option<&str> ) -> Result<(), SpotifyError>
Pauses the user’s playback: https://developer.spotify.com/documentation/web-api/reference/#/operations/pause-a-users-playback
Requires scope: user-modify-playback-state
Arguments
device_id
- The id of the device to pause playback on
sourcepub fn skip_next(&self, device_id: Option<&str>) -> Result<(), SpotifyError>
pub fn skip_next(&self, device_id: Option<&str>) -> Result<(), SpotifyError>
Skips the currently playing track to the next track: https://developer.spotify.com/documentation/web-api/reference/#/operations/skip-users-playback-to-next-track
Requires scope: user-modify-playback-state
Arguments
device_id
- The id of the device to skip on
sourcepub fn skip_previous(&self, device_id: Option<&str>) -> Result<(), SpotifyError>
pub fn skip_previous(&self, device_id: Option<&str>) -> Result<(), SpotifyError>
Skips the currently playing track to the previous track: https://developer.spotify.com/documentation/web-api/reference/#/operations/skip-users-playback-to-previous-track
Requires scope: user-modify-playback-state
Arguments
device_id
- The id of the device to skip on
sourcepub fn seek_position(
&self,
position: i32,
device_id: Option<&str>
) -> Result<(), SpotifyError>
pub fn seek_position( &self, position: i32, device_id: Option<&str> ) -> Result<(), SpotifyError>
Seeks to specified position in currently playing track: https://developer.spotify.com/documentation/web-api/reference/#/operations/seek-to-position-in-currently-playing-track
Requires scope: user-modify-playback-state
Arguments
position
- The position in milliseconds to seek todevice_id
- The id of the device to seek on
sourcepub fn set_repeat_mode(
&self,
state: RepeatState,
device_id: Option<&str>
) -> Result<(), SpotifyError>
pub fn set_repeat_mode( &self, state: RepeatState, device_id: Option<&str> ) -> Result<(), SpotifyError>
Sets the repeat mode for the user’s playback: https://developer.spotify.com/documentation/web-api/reference/#/operations/set-repeat-mode-on-users-playback
Requires scope: user-modify-playback-state
Arguments
state
- The repeat state to set. Valid values are: track, context, offdevice_id
- The id of the device to set repeat mode on
sourcepub fn set_playback_volume(
&self,
volume: i32,
device_id: Option<&str>
) -> Result<(), SpotifyError>
pub fn set_playback_volume( &self, volume: i32, device_id: Option<&str> ) -> Result<(), SpotifyError>
Sets the volume for the user’s playback: https://developer.spotify.com/documentation/web-api/reference/#/operations/set-volume-for-users-playback
Requires scope: user-modify-playback-state
Arguments
volume
- The volume to set. Must be a value from 0 to 100 inclusivedevice_id
- The id of the device to set volume on
sourcepub fn toggle_shuffle(
&self,
state: bool,
device_id: Option<&str>
) -> Result<(), SpotifyError>
pub fn toggle_shuffle( &self, state: bool, device_id: Option<&str> ) -> Result<(), SpotifyError>
Toggles shuffle state: https://developer.spotify.com/documentation/web-api/reference/#/operations/toggle-shuffle-for-users-playback
Requires scope: user-modify-playback-state
Arguments
state
- The shuffle state to set. Valid values are: true, falsedevice_id
- The id of the device to set shuffle on
sourcepub fn get_recently_played_tracks(
&self,
after: Option<NaiveDateTime>,
before: Option<NaiveDateTime>,
limit: Option<i32>
) -> Result<SpotifyCollection<PlayedTrack>, SpotifyError>
pub fn get_recently_played_tracks( &self, after: Option<NaiveDateTime>, before: Option<NaiveDateTime>, limit: Option<i32> ) -> Result<SpotifyCollection<PlayedTrack>, SpotifyError>
Returns user’s recently played items: https://developer.spotify.com/documentation/web-api/reference/#/operations/get-recently-played
Requires scope: user-read-recently-played
Arguments
after
- Returns all items after this time stamp.before
- Returns all items before this time stamp. Will be ignored if after is specifiedlimit
- The maximum number of items to return. Default: 20. Minimum: 1. Maximum: 50
sourcepub fn get_users_queue(&self) -> Result<(Track, Vec<Track>), SpotifyError>
pub fn get_users_queue(&self) -> Result<(Track, Vec<Track>), SpotifyError>
Returns the user’s currently playing track and queue: https://developer.spotify.com/documentation/web-api/reference/#/operations/get-queue Note: This wrapper currently only supports tracks and unexpected errors may occur if the queue contains episodes
Requires scope: user-read-currently-playing user-read-playback-state
sourcepub fn add_track_to_queue(
&self,
track_id: &str,
device_id: Option<&str>
) -> Result<(), SpotifyError>
pub fn add_track_to_queue( &self, track_id: &str, device_id: Option<&str> ) -> Result<(), SpotifyError>
Adds specified item to the playback queue: https://developer.spotify.com/documentation/web-api/reference/#/operations/add-to-queue Note: currently only tracks are supported, episode ids will have unexpected results
Requires scope: user-modify-playback-state
Arguments
track_id
- The id of the track to add to the queuedevice_id
- The id of the device to add the track to
source§impl Spotify
impl Spotify
sourcepub fn get_playlist(
&self,
playlist_id: &str,
market: Option<&str>
) -> Result<Playlist, SpotifyError>
pub fn get_playlist( &self, playlist_id: &str, market: Option<&str> ) -> Result<Playlist, SpotifyError>
Get a playlist owned by a Spotify user: https://developer.spotify.com/documentation/web-api/reference/#/operations/get-playlist Note: no support for episodes at the moment so unexpected results may occur with playlists that contain episodes
Required scope: none
Arguments
playlist_id
- The Spotify ID of the playlist.market
- An ISO 3166-1 alpha-2 country code.
sourcepub fn change_playlist_details(
&self,
playlist_id: &str,
name: Option<&str>,
public: Option<bool>,
collaborative: Option<bool>,
description: Option<&str>
) -> Result<(), SpotifyError>
pub fn change_playlist_details( &self, playlist_id: &str, name: Option<&str>, public: Option<bool>, collaborative: Option<bool>, description: Option<&str> ) -> Result<(), SpotifyError>
Change a playlist’s name, public/private state, collaborative state, and description: https://developer.spotify.com/documentation/web-api/reference/#/operations/change-playlist-details
Required scope: playlist-modify-public playlist-modify-private
Arguments
playlist_id
- The Spotify ID of the playlist.name
- The new name for the playlist.public
- If true the playlist will be public, if false it will be private.collaborative
- If true the playlist will become collaborative and other users will be able to modify the playlist in their Spotify client. Note: You can only set collaborative to true on non-public playlists.description
- Value for playlist description as displayed in Spotify Clients and in the Web API.
sourcepub fn get_playlist_tracks(
&self,
playlist_id: &str,
market: Option<&str>,
limit: Option<i32>,
offset: Option<i32>
) -> Result<SpotifyCollection<PlaylistTrack>, SpotifyError>
pub fn get_playlist_tracks( &self, playlist_id: &str, market: Option<&str>, limit: Option<i32>, offset: Option<i32> ) -> Result<SpotifyCollection<PlaylistTrack>, SpotifyError>
Get all items in playlist: https://developer.spotify.com/documentation/web-api/reference/#/operations/get-playlists-tracks Note: no support for episodes at the moment so unexpected results may occur with playlists that contain episodes
Required scope: none
Arguments
playlist_id
- The Spotify ID of the playlist.market
- An ISO 3166-1 alpha-2 country code.limit
- The maximum number of items to return. Default: 100. Minimum: 0. Maximum: 100.offset
- The index of the first item to return. Default: 0 (the first object). Use with limit to get the next set of items.
sourcepub fn add_tracks_to_playlist(
&self,
playlist_id: &str,
track_ids: Vec<&str>,
position: Option<i32>
) -> Result<(), SpotifyError>
pub fn add_tracks_to_playlist( &self, playlist_id: &str, track_ids: Vec<&str>, position: Option<i32> ) -> Result<(), SpotifyError>
Add one or more tracks to a user’s playlist: https://developer.spotify.com/documentation/web-api/reference/#/operations/add-tracks-to-playlist Note: currently only supports tracks, not episodes.
Required scope: playlist-modify-public playlist-modify-private
Arguments
playlist_id
- The Spotify ID of the playlist.track_ids
- A list of Spotify track URIs to add, can be a maximum of 100.position
- The position to insert the tracks, a zero-based index. For example, to insert the tracks in the first position: position=0; to insert the tracks in the third position: position=2. If omitted, the tracks will be appended to the playlist.
sourcepub fn replace_playlist_tracks(
&self,
playlist_id: &str,
track_ids: Vec<&str>
) -> Result<String, SpotifyError>
pub fn replace_playlist_tracks( &self, playlist_id: &str, track_ids: Vec<&str> ) -> Result<String, SpotifyError>
Replace tracks in user’s playlist. A derivative of: https://developer.spotify.com/documentation/web-api/reference/#/operations/reorder-or-replace-playlists-tracks Returns the new snapshot ID of the playlist. Note: Currently there is only support for spotifiy tracks, not episodes.
Required scope: playlist-modify-public playlist-modify-private
Arguments
playlist_id
- The Spotify ID of the playlist.track_ids
- A list of Spotify track URIs to add, can be a maximum of 100.
sourcepub fn reorder_playlist_tracks(
&self,
playlist_id: &str,
range_start: i32,
insert_before: i32,
range_length: Option<i32>,
snapshot_id: Option<&str>
) -> Result<String, SpotifyError>
pub fn reorder_playlist_tracks( &self, playlist_id: &str, range_start: i32, insert_before: i32, range_length: Option<i32>, snapshot_id: Option<&str> ) -> Result<String, SpotifyError>
Reorder tracks in user’s playlist. A derivative of: https://developer.spotify.com/documentation/web-api/reference/#/operations/reorder-or-replace-playlists-tracks Returns the new snapshot ID of the playlist.
Required scope: playlist-modify-public playlist-modify-private
Arguments
playlist_id
- The Spotify ID of the playlist.range_start
- The position of the first track to be reordered.insert_before
- The position where the tracks should be inserted.range_length
- The amount of tracks to be reordered. Defaults to 1 if not set.snapshot_id
- The playlist’s snapshot ID against which you want to make the changes.
sourcepub fn remove_playlist_tracks(
&self,
playlist_id: &str,
track_ids: Vec<&str>,
snapshot_id: Option<&str>
) -> Result<String, SpotifyError>
pub fn remove_playlist_tracks( &self, playlist_id: &str, track_ids: Vec<&str>, snapshot_id: Option<&str> ) -> Result<String, SpotifyError>
Remove tracks from user’s playlist: https://developer.spotify.com/documentation/web-api/reference/#/operations/remove-tracks-playlist Returns the new snapshot ID of the playlist. Note: currently only support for spotify tracks, not episodes.
Required scope: playlist-modify-public playlist-modify-private
Arguments
playlist_id
- The Spotify ID of the playlist.track_ids
- A list of Spotify track URIs to remove, can be a maximum of 100.snapshot_id
- The playlist’s snapshot ID against which you want to make the changes.
sourcepub fn get_current_users_playlists(
&self,
limit: Option<i32>,
offset: Option<i32>
) -> Result<SpotifyCollection<Playlist>, SpotifyError>
pub fn get_current_users_playlists( &self, limit: Option<i32>, offset: Option<i32> ) -> Result<SpotifyCollection<Playlist>, SpotifyError>
Get current user’s playlists: https://developer.spotify.com/documentation/web-api/reference/#/operations/get-a-list-of-current-users-playlists
Required scope: playlist-read-private playlist-read-collaborative
Arguments
limit
- The maximum number of playlists to return. Default: 20. Minimum: 1. Maximum: 50.offset
- The index of the first playlist to return. Default: 0 (the first object). Use with limit to get the next set of playlists.
sourcepub fn get_users_playlists(
&self,
user_id: &str,
limit: Option<i32>,
offset: Option<i32>
) -> Result<SpotifyCollection<Playlist>, SpotifyError>
pub fn get_users_playlists( &self, user_id: &str, limit: Option<i32>, offset: Option<i32> ) -> Result<SpotifyCollection<Playlist>, SpotifyError>
Get a specified user’s playlists: https://developer.spotify.com/documentation/web-api/reference/#/operations/get-list-users-playlists
Required scope: playlist-read-private playlist-read-collaborative
Arguments
user_id
- The user’s Spotify user ID.limit
- The maximum number of playlists to return. Default: 20. Minimum: 1. Maximum: 50.offset
- The index of the first playlist to return. Default: 0 (the first object). Use with limit to get the next set of playlists.
sourcepub fn create_playlist(
&self,
user_id: &str,
name: &str,
public: Option<bool>,
collaborative: Option<bool>,
description: Option<&str>
) -> Result<Playlist, SpotifyError>
pub fn create_playlist( &self, user_id: &str, name: &str, public: Option<bool>, collaborative: Option<bool>, description: Option<&str> ) -> Result<Playlist, SpotifyError>
Create a playlist for the current user: https://developer.spotify.com/documentation/web-api/reference/#/operations/create-playlist
Required scope: playlist-modify-public playlist-modify-private
Arguments
user_id
- The user’s Spotify user ID.name
- The name for the new playlistpublic
- Defaults to true. If true the playlist will be public, if false it will be private.collaborative
- Defaults to false. If true the playlist will be collaborative. Note that to create a collaborative playlist you must also set public to false.description
- Value for playlist description as displayed in Spotify Clients and in the Web API.
sourcepub fn get_featured_playlists(
&self,
country: Option<&str>,
locale: Option<&str>,
limit: Option<i32>,
offset: Option<i32>,
timestamp: Option<NaiveDateTime>
) -> Result<SpotifyCollection<Playlist>, SpotifyError>
pub fn get_featured_playlists( &self, country: Option<&str>, locale: Option<&str>, limit: Option<i32>, offset: Option<i32>, timestamp: Option<NaiveDateTime> ) -> Result<SpotifyCollection<Playlist>, SpotifyError>
Gets playlists featured in Browse tab: https://developer.spotify.com/documentation/web-api/reference/#/operations/get-featured-playlists
Required scope: none
Arguments
country
- An ISO 3166-1 alpha-2 country code. Will return the featured playlists for that country.locale
- The desired language, consisting of an ISO 639 language code and an ISO 3166-1 alpha-2 country code, joined by an underscore. For example: es_MX, meaning “Spanish (Mexico)”. Provide this parameter if you want the results returned in a particular language. Note that, if locale is not supplied, or if the specified language is not available, all strings will be returned in the Spotify default language (American English). The locale parameter, combined with the country parameter, may give odd results if not carefully matched. For example, country=SE&locale=de_DE will return a list of categories relevant to Sweden but as German language strings.limit
- The maximum number of items to return. Default: 20. Minimum: 1. Maximum: 50.offset
- The index of the first item to return. Default: 0 (the first object). Use with limit to get the next set of items.timestamp
- A timestamp for which the playlists would be relevant. Defaults to current time if not provided
sourcepub fn get_categorys_playlists(
&self,
category_id: &str,
country: Option<&str>,
limit: Option<i32>,
offset: Option<i32>
) -> Result<SpotifyCollection<Playlist>, SpotifyError>
pub fn get_categorys_playlists( &self, category_id: &str, country: Option<&str>, limit: Option<i32>, offset: Option<i32> ) -> Result<SpotifyCollection<Playlist>, SpotifyError>
Get a set of Spotify playlsits tagged with a particular category: https://developer.spotify.com/documentation/web-api/reference/#/operations/get-a-categories-playlists
Required scope: none
Arguments
category_id
- The Spotify category ID for the category.country
- An ISO 3166-1 alpha-2 country code.limit
- The maximum number of items to return. Default: 20. Minimum: 1. Maximum: 50.offset
- The index of the first item to return. Default: 0 (the first object). Use with limit to get the next set of items.
sourcepub fn get_playlist_cover_image(
&self,
playlist_id: &str
) -> Result<Vec<SpotifyImage>, SpotifyError>
pub fn get_playlist_cover_image( &self, playlist_id: &str ) -> Result<Vec<SpotifyImage>, SpotifyError>
Gets the current image associated with a playlist: https://developer.spotify.com/documentation/web-api/reference/#/operations/get-playlist-cover
Required scope: none
Arguments
playlist_id
- The Spotify ID for the playlist.
source§impl Spotify
impl Spotify
sourcepub fn new_from_auth_code(
authorization_code: &str,
client_id: &str,
scope: String,
code_verifier: &str,
redirect_uri: &str
) -> Spotify
pub fn new_from_auth_code( authorization_code: &str, client_id: &str, scope: String, code_verifier: &str, redirect_uri: &str ) -> Spotify
Creates spotify object from usual information and auth code. Essentially from less information
sourcepub fn authenticate(
&self,
localhost_port: String,
scope: String
) -> Result<(), SpotifyError>
pub fn authenticate( &self, localhost_port: String, scope: String ) -> Result<(), SpotifyError>
Creates a new Spotify object by authenticating with the Spotify API using the PKCE codeflow.
Grabs client_id
from .env
file.
Arguments
localhost_port
- The localhost port fort the redirect uri. Note: currently there is only support for localhost redirect uris.scope
- The scope of the Spotify API. See https://developer.spotify.com/documentation/general/guides/authorization/scopes/ for more information.
sourcepub fn check_scope(&self, scope: &str) -> Result<(), SpotifyError>
pub fn check_scope(&self, scope: &str) -> Result<(), SpotifyError>
Checks to see if required scope is present in current scope
Arguments
scope
- A string slice that holds required scope
sourcepub fn access_token(&self) -> Result<String, SpotifyError>
pub fn access_token(&self) -> Result<String, SpotifyError>
Returns the access token. If the token is expired, it will be refreshed.
sourcepub fn save_to_file(&self, file_name: &str) -> Result<(), SpotifyError>
pub fn save_to_file(&self, file_name: &str) -> Result<(), SpotifyError>
Saves necessary authorization information to file for later use
Arguments
file_name
- The name of the file to save the authorization information to
sourcepub fn new_from_file(file_name: &str) -> Result<Spotify, SpotifyError>
pub fn new_from_file(file_name: &str) -> Result<Spotify, SpotifyError>
sourcepub fn authenticate_from_file(
&self,
file_name: &str
) -> Result<(), SpotifyError>
pub fn authenticate_from_file( &self, file_name: &str ) -> Result<(), SpotifyError>
sourcepub fn is_authenticated(&self) -> bool
pub fn is_authenticated(&self) -> bool
Returns true if the API is authenticated
source§impl Spotify
impl Spotify
sourcepub fn spotify_request(
&self,
url_extension: &str,
request_method: RequestMethod
) -> Result<JsonValue, SpotifyError>
pub fn spotify_request( &self, url_extension: &str, request_method: RequestMethod ) -> Result<JsonValue, SpotifyError>
source§impl Spotify
impl Spotify
sourcepub fn get_track(&self, track_id: &str) -> Result<Track, SpotifyError>
pub fn get_track(&self, track_id: &str) -> Result<Track, SpotifyError>
Get information on a single track: https://developer.spotify.com/documentation/web-api/reference/#/operations/get-track
Required scope: none
Arguments
track_id
- The Spotify ID of the track.
sourcepub fn get_several_tracks(
&self,
track_ids: Vec<&str>,
market: Option<&str>
) -> Result<Vec<Track>, SpotifyError>
pub fn get_several_tracks( &self, track_ids: Vec<&str>, market: Option<&str> ) -> Result<Vec<Track>, SpotifyError>
Get information on many tracks: https://developer.spotify.com/documentation/web-api/reference/#/operations/get-several-tracks
Required scope: none
Arguments
track_ids
- A vector of Spotify track ids.market
- An ISO 3166-1 alpha-2 country code.
sourcepub fn get_user_saved_tracks(
&self,
limit: Option<u32>,
market: Option<&str>,
offset: Option<u32>
) -> Result<SpotifyCollection<DatedTrack>, SpotifyError>
pub fn get_user_saved_tracks( &self, limit: Option<u32>, market: Option<&str>, offset: Option<u32> ) -> Result<SpotifyCollection<DatedTrack>, SpotifyError>
Get user’s saved tracks: https://developer.spotify.com/documentation/web-api/reference/#/operations/get-users-saved-tracks
Required scope: user-library-read
Arguments
limit
- The number of tracks to return. Default: 20. Minimum: 1. Maximum: 50.market
- An ISO 3166-1 alpha-2 country code.offset
- The index of the first track to return. Default: 0 (i.e., the first track). Use with limit to get the next set of tracks.
sourcepub fn save_tracks(&self, track_ids: Vec<&str>) -> Result<(), SpotifyError>
pub fn save_tracks(&self, track_ids: Vec<&str>) -> Result<(), SpotifyError>
Save tracks into current user’s library: https://developer.spotify.com/documentation/web-api/reference/#/operations/save-tracks-user
Required scope: user-library-modify
Arguments
track_ids
- A vector of Spotify track ids
sourcepub fn remove_tracks(&self, track_ids: Vec<&str>) -> Result<(), SpotifyError>
pub fn remove_tracks(&self, track_ids: Vec<&str>) -> Result<(), SpotifyError>
Remove tracks from current user’s library: https://developer.spotify.com/documentation/web-api/reference/#/operations/remove-tracks-user
Required scope: user-library-modify
Arguments
track_ids
- A vector of Spotify track IDs
sourcepub fn check_saved_tracks(
&self,
track_ids: Vec<&str>
) -> Result<Vec<bool>, SpotifyError>
pub fn check_saved_tracks( &self, track_ids: Vec<&str> ) -> Result<Vec<bool>, SpotifyError>
Checks to see if specified tracks are saved in user’s library: https://developer.spotify.com/documentation/web-api/reference/#/operations/check-users-saved-tracks
Required scope: user-library-read
Arguments
track_ids
- A vector of track ids to check
sourcepub fn get_tracks_audio_features(
&self,
track_ids: Vec<&str>
) -> Result<Vec<FeatureTrack>, SpotifyError>
pub fn get_tracks_audio_features( &self, track_ids: Vec<&str> ) -> Result<Vec<FeatureTrack>, SpotifyError>
Gets audio features for specified track(s): https://developer.spotify.com/documentation/web-api/reference/#/operations/get-several-audio-features
Required scope: none
Arguments
track_ids
- A vector of track ids
sourcepub fn get_track_audio_features(
&self,
track_id: &str
) -> Result<FeatureTrack, SpotifyError>
pub fn get_track_audio_features( &self, track_id: &str ) -> Result<FeatureTrack, SpotifyError>
Gets audio features for specified track: https://developer.spotify.com/documentation/web-api/reference/#/operations/get-audio-features
Required scope: none
Arguments
track_id
- Spotify ID of track
sourcepub fn get_track_audio_analysis(
&self,
track_id: &str
) -> Result<AnalysisTrack, SpotifyError>
pub fn get_track_audio_analysis( &self, track_id: &str ) -> Result<AnalysisTrack, SpotifyError>
Gets audio analysis for specified track: https://developer.spotify.com/documentation/web-api/reference/#/operations/get-audio-analysis
Required scope: none
Arguments
track_id
- Spotify ID of track
sourcepub fn get_recommendations(
&self,
seed_artists: Option<Vec<&str>>,
seed_genres: Option<Vec<&str>>,
seed_tracks: Option<Vec<&str>>,
optional_parameters: Option<Vec<(&str, &str)>>
) -> Result<Vec<Track>, SpotifyError>
pub fn get_recommendations( &self, seed_artists: Option<Vec<&str>>, seed_genres: Option<Vec<&str>>, seed_tracks: Option<Vec<&str>>, optional_parameters: Option<Vec<(&str, &str)>> ) -> Result<Vec<Track>, SpotifyError>
Gets track recommendations based on seed artists, tracks, or genres: https://developer.spotify.com/documentation/web-api/reference/#/operations/get-recommendations
Required scope: none
Arguments
seed_artists
- A list of seed artists. Up to 5 seed values can be supplied betweenseed_artists
,seed_tracks
, andseed_genres
. Must supply 1.seed_tracks
- A list of seed tracks. Up to 5 seed values can be supplied betweenseed_artists
,seed_tracks
, andseed_genres
. Must supply 1.seed_genres
- A list of seed genres. Up to 5 seed values can be supplied betweenseed_artists
,seed_tracks
, andseed_genres
. Must supply 1.optional_parameters
- A vector mapping parameters to values. Can have any of the following as keys:limit
- The target size of the list of recommended tracks. Default: 20. Minimum: 1. Maximum: 100.market
- An ISO 3166-1 alpha-2 country codemin_acousticness
- minimum acousticness value for tracks, between 0 and 1max_acousticness
- maximum acousticness value for track, between 0 and 1target_acousticness
- target acousticness value for track, between 0 and 1min_danceability
- minimum danceability value for tracks, between 0 and 1max_danceability
- maximum danceability value for track, between 0 and 1target_danceability
- target danceability value for track, between 0 and 1min_duration
- minimum duration of tracks in msmax_duration
- maximum duration of track in mstarget_duration
- target duration of track in msmin_energy
- minimum energy value for tracks, between 0 and 1max_energy
- maximum energy value for track, between 0 and 1target_energy
- target energy value for track, between 0 and 1min_instrumentalness
- minimum instrumentalness value for tracks, between 0 and 1max_instrumentalness
- maximum instrumentalness value for track, between 0 and 1target_instrumentalness
- target instrumentalness value for track, between 0 and 1min_key
- minimum key value for tracks, between 0 and 11max_key
- maximum key value for track, between 0 and 11target_key
- target key value for track, between 0 and 11min_liveness
- minimum liveness value for tracks, between 0 and 1max_liveness
- maximum liveness value for track, between 0 and 1target_liveness
- target liveness value for track, between 0 and 1min_loudness
- minimum loudness value for tracks in dBmax_loudness
- maximum loudness value for track in dBtarget_loudness
- target loudness value for track in dBmin_mode
- minimum mode value for tracks, between 0 and 1max_mode
- maximum mode value for track, between 0 and 1target_mode
- target mode value for track, between 0 and 1min_popularity
- minimum popularity value for tracks, between 0 and 100max_popularity
- maximum popularity value for track, between 0 and 100target_popularity
- target popularity value for track, between 0 and 100min_speechiness
- minimum speechiness value for tracks, between 0 and 1max_speechiness
- maximum speechiness value for track, between 0 and 1target_speechiness
- target speechiness value for track, between 0 and 1min_tempo
- minimum tempo value for tracks in BPMmax_tempo
- maximum tempo value for track in BPMtarget_tempo
- target tempo value for track in BPMmin_time_signature
- minimum time signature value for tracksmax_time_signature
- maximum time signature value for tracktarget_time_signature
- target time signature value for trackmin_valence
- minimum valence value for tracks, between 0 and 1max_valence
- maximum valence value for track, between 0 and 1target_valence
- target valence value for track, between 0 and 1
source§impl Spotify
impl Spotify
sourcepub fn get_current_users_profile(&self) -> Result<User, SpotifyError>
pub fn get_current_users_profile(&self) -> Result<User, SpotifyError>
Get information on current user: https://developer.spotify.com/documentation/web-api/reference/#/operations/get-current-users-profile
Requires scope: user-read-private user-read-email
sourcepub fn get_users_top_artists(
&self,
time_range: Option<TimeRange>,
limit: Option<i32>,
offset: Option<i32>
) -> Result<SpotifyCollection<Artist>, SpotifyError>
pub fn get_users_top_artists( &self, time_range: Option<TimeRange>, limit: Option<i32>, offset: Option<i32> ) -> Result<SpotifyCollection<Artist>, SpotifyError>
Gets the user’s top artists. A derivative of: https://developer.spotify.com/documentation/web-api/reference/#/operations/get-users-top-artists-and-tracks
Requires scope: user-top-read
Arguments
time_range
- The time range over which to retrieve top artists: short, medium, long. Default: medium.limit
- The number of artists to return. Default: 20. Minimum: 1. Maximum: 50.offset
- The index of the first artist to return. Default: 0 (i.e., the first artist). Use with limit to get the next set of artists.
sourcepub fn get_users_top_tracks(
&self,
time_range: Option<TimeRange>,
limit: Option<i32>,
offset: Option<i32>
) -> Result<SpotifyCollection<Track>, SpotifyError>
pub fn get_users_top_tracks( &self, time_range: Option<TimeRange>, limit: Option<i32>, offset: Option<i32> ) -> Result<SpotifyCollection<Track>, SpotifyError>
Gets the user’s top tracks. A derivative of: https://developer.spotify.com/documentation/web-api/reference/#/operations/get-users-top-artists-and-tracks
Requires scope: user-top-read
Arguments
time_range
- The time range over which to retrieve top tracks: short, medium, long. Default: medium.limit
- The number of tracks to return. Default: 20. Minimum: 1. Maximum: 50.offset
- The index of the first track to return. Default: 0 (i.e., the first track). Use with limit to get the next set of tracks.
sourcepub fn get_users_profile(&self, user_id: &str) -> Result<User, SpotifyError>
pub fn get_users_profile(&self, user_id: &str) -> Result<User, SpotifyError>
Gets the public profile for a user: https://developer.spotify.com/documentation/web-api/reference/#/operations/get-users-profile
Requires scope: none
Arguments
user_id
- The user’s Spotify user ID.
sourcepub fn follow_playlist(
&self,
playlist_id: &str,
public: Option<bool>
) -> Result<(), SpotifyError>
pub fn follow_playlist( &self, playlist_id: &str, public: Option<bool> ) -> Result<(), SpotifyError>
Add current user as a follower to a playlist: https://developer.spotify.com/documentation/web-api/reference/#/operations/follow-playlist
Requires scope: playlist-modify-public playlist-modify-private
Arguments
playlist_id
- The Spotify ID of the playlist.public
- If true the playlist will be included in user’s public playlists, if false it will remain private. Default: true.
sourcepub fn unfollow_playlist(&self, playlist_id: &str) -> Result<(), SpotifyError>
pub fn unfollow_playlist(&self, playlist_id: &str) -> Result<(), SpotifyError>
Remove current user as a follower to a playlist: https://developer.spotify.com/documentation/web-api/reference/#/operations/unfollow-playlist
Requires scope: playlist-modify-private playlist-modify-public
Arguments
playlist_id
- The Spotify ID of the playlist.
sourcepub fn get_followed_artists(
&self,
limit: Option<i32>
) -> Result<SpotifyCollection<Artist>, SpotifyError>
pub fn get_followed_artists( &self, limit: Option<i32> ) -> Result<SpotifyCollection<Artist>, SpotifyError>
Gets the current user’s followed artists: https://developer.spotify.com/documentation/web-api/reference/#/operations/get-followed
Requires scope: user-follow-read
Arguments
limit
- The maximum number of items to return. Default: 20. Minimum: 1. Maximum: 50.
sourcepub fn follow_artists(&self, artist_ids: Vec<&str>) -> Result<(), SpotifyError>
pub fn follow_artists(&self, artist_ids: Vec<&str>) -> Result<(), SpotifyError>
Follows specified artists. A derivative of: https://developer.spotify.com/documentation/web-api/reference/#/operations/follow-artists-users
Requires scope: user-follow-modify
Arguments
artist_ids
- A vector of the artist Spotify IDs to follow.
sourcepub fn follow_users(&self, user_ids: Vec<&str>) -> Result<(), SpotifyError>
pub fn follow_users(&self, user_ids: Vec<&str>) -> Result<(), SpotifyError>
Follows specified users. A derivative of: https://developer.spotify.com/documentation/web-api/reference/#/operations/follow-artists-users
Requires scope: user-follow-modify
Arguments
user_ids
- A vector of the user Spotify IDs to follow.
sourcepub fn unfollow_artists(
&self,
artist_ids: Vec<&str>
) -> Result<(), SpotifyError>
pub fn unfollow_artists( &self, artist_ids: Vec<&str> ) -> Result<(), SpotifyError>
Unfollows specified artists. A derivative of: https://developer.spotify.com/documentation/web-api/reference/#/operations/unfollow-artists-users
Requires scope: user-follow-modify
Arguments
artist_ids
- A vector of the artist Spotify IDs to unfollow.
sourcepub fn unfollow_users(&self, user_ids: Vec<&str>) -> Result<(), SpotifyError>
pub fn unfollow_users(&self, user_ids: Vec<&str>) -> Result<(), SpotifyError>
Unfollows specified users. A derivative of: https://developer.spotify.com/documentation/web-api/reference/#/operations/unfollow-artists-users
Requires scope: user-follow-modify
Arguments
user_ids
- A vector of the user Spotify IDs to unfollow.
sourcepub fn check_user_follows_artists(
&self,
artist_ids: Vec<&str>
) -> Result<Vec<bool>, SpotifyError>
pub fn check_user_follows_artists( &self, artist_ids: Vec<&str> ) -> Result<Vec<bool>, SpotifyError>
Check if user follows specific artists. Returns a vector of bools. A derivative of: https://developer.spotify.com/documentation/web-api/reference/#/operations/check-current-user-follows
Requires scope: user-follow-read
Arguments
artist_ids
- A vector of the artist Spotify IDs to check.
Panics
Panics if API returned value is not formatted as expected. Shouldn’t happen.
sourcepub fn check_user_follows_users(
&self,
user_ids: Vec<&str>
) -> Result<Vec<bool>, SpotifyError>
pub fn check_user_follows_users( &self, user_ids: Vec<&str> ) -> Result<Vec<bool>, SpotifyError>
Check if user follows specific users. Returns a vector of bools. A derivative of: https://developer.spotify.com/documentation/web-api/reference/#/operations/check-current-user-follows
Requires scope: user-follow-read
Arguments
user_ids
- A vector of the user Spotify IDs to check.
Panics
Panics if API returned value is not formatted as expected. Shouldn’t happen.
sourcepub fn check_users_follow_playlist(
&self,
playlist_id: &str,
user_ids: Vec<&str>
) -> Result<Vec<bool>, SpotifyError>
pub fn check_users_follow_playlist( &self, playlist_id: &str, user_ids: Vec<&str> ) -> Result<Vec<bool>, SpotifyError>
Check if specified users follow a playlist. Returns a vector of bools: https://developer.spotify.com/documentation/web-api/reference/#/operations/check-if-user-follows-playlist
Requires scope: none
Arguments
playlist_id
- The Spotify ID of the playlist.user_ids
- A vector of the user Spotify IDs to check. Maximum 5 ids.