Struct spotifyrs::Spotify

source ·
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

source

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.
source

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.
source

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.
source

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.
source

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.
source

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.
source

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.
source

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

source

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.
source

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.
source

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.
source

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

source

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.
source

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

source§

impl Spotify

source

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

source

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.
source

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 to
  • play - Whether or not to start playback on the new device
source

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

source

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
source

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 on
  • context - The context to start playback on. Valid contexts: Album, Artist, Playlist
  • track_ids - The track ids to start playback on
  • offset_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
source

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
source

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
source

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
source

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 to
  • device_id - The id of the device to seek on
source

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, off
  • device_id - The id of the device to set repeat mode on
source

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 inclusive
  • device_id - The id of the device to set volume on
source

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, false
  • device_id - The id of the device to set shuffle on
source

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 specified
  • limit - The maximum number of items to return. Default: 20. Minimum: 1. Maximum: 50
source

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

source

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 queue
  • device_id - The id of the device to add the track to
source§

impl Spotify

source

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.
source

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.
source

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.
source

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.
source

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.
source

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.
source

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.
source

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.
source

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.
source

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 playlist
  • public - 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.

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
source

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.
source

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

source

pub fn new() -> Spotify

Creates a blank Spotify object

source

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

source

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
source

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
source

pub fn access_token(&self) -> Result<String, SpotifyError>

Returns the access token. If the token is expired, it will be refreshed.

source

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
source

pub fn new_from_file(file_name: &str) -> Result<Spotify, SpotifyError>

Creates a new autheticated object from file

Arguments
  • file_name - The name of the file to load the authorization information from
Panics

Panics if the file doesn’t contain the necessary information

source

pub fn authenticate_from_file( &self, file_name: &str ) -> Result<(), SpotifyError>

Authorizes a blank Spotify object from a file

Arguments
  • file_name - The name of the file to load the authorization information from
Panics

Panics if the file doesn’t contain the necessary information

source

pub fn is_authenticated(&self) -> bool

Returns true if the API is authenticated

source§

impl Spotify

source

pub fn spotify_request( &self, url_extension: &str, request_method: RequestMethod ) -> Result<JsonValue, SpotifyError>

General request to the spotify API. Returns JSON response

Arguments
  • url_extension - part of url past: https://api.spotify.com/v1/. Specific to each type of request
  • request_method - type of request (GET, POST, PUT, DELETE)
Panics

On various parsing errors. Shouldn’t happen? Probably.

source§

impl Spotify

source

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.
source

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.
source

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.
source

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
source

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
source

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
source

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
source

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
source

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
source

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 between seed_artists, seed_tracks, and seed_genres. Must supply 1.
  • seed_tracks - A list of seed tracks. Up to 5 seed values can be supplied between seed_artists, seed_tracks, and seed_genres. Must supply 1.
  • seed_genres - A list of seed genres. Up to 5 seed values can be supplied between seed_artists, seed_tracks, and seed_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 code
    • min_acousticness - minimum acousticness value for tracks, between 0 and 1
    • max_acousticness - maximum acousticness value for track, between 0 and 1
    • target_acousticness - target acousticness value for track, between 0 and 1
    • min_danceability - minimum danceability value for tracks, between 0 and 1
    • max_danceability - maximum danceability value for track, between 0 and 1
    • target_danceability - target danceability value for track, between 0 and 1
    • min_duration - minimum duration of tracks in ms
    • max_duration - maximum duration of track in ms
    • target_duration - target duration of track in ms
    • min_energy - minimum energy value for tracks, between 0 and 1
    • max_energy - maximum energy value for track, between 0 and 1
    • target_energy - target energy value for track, between 0 and 1
    • min_instrumentalness - minimum instrumentalness value for tracks, between 0 and 1
    • max_instrumentalness - maximum instrumentalness value for track, between 0 and 1
    • target_instrumentalness - target instrumentalness value for track, between 0 and 1
    • min_key - minimum key value for tracks, between 0 and 11
    • max_key - maximum key value for track, between 0 and 11
    • target_key - target key value for track, between 0 and 11
    • min_liveness - minimum liveness value for tracks, between 0 and 1
    • max_liveness - maximum liveness value for track, between 0 and 1
    • target_liveness - target liveness value for track, between 0 and 1
    • min_loudness - minimum loudness value for tracks in dB
    • max_loudness - maximum loudness value for track in dB
    • target_loudness - target loudness value for track in dB
    • min_mode - minimum mode value for tracks, between 0 and 1
    • max_mode - maximum mode value for track, between 0 and 1
    • target_mode - target mode value for track, between 0 and 1
    • min_popularity - minimum popularity value for tracks, between 0 and 100
    • max_popularity - maximum popularity value for track, between 0 and 100
    • target_popularity - target popularity value for track, between 0 and 100
    • min_speechiness - minimum speechiness value for tracks, between 0 and 1
    • max_speechiness - maximum speechiness value for track, between 0 and 1
    • target_speechiness - target speechiness value for track, between 0 and 1
    • min_tempo - minimum tempo value for tracks in BPM
    • max_tempo - maximum tempo value for track in BPM
    • target_tempo - target tempo value for track in BPM
    • min_time_signature - minimum time signature value for tracks
    • max_time_signature - maximum time signature value for track
    • target_time_signature - target time signature value for track
    • min_valence - minimum valence value for tracks, between 0 and 1
    • max_valence - maximum valence value for track, between 0 and 1
    • target_valence - target valence value for track, between 0 and 1
source§

impl Spotify

source

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

source

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.
source

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.
source

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.
source

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.
source

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.
source

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.
source

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.
source

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.
source

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.
source

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.
source

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.

source

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.

source

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.

Trait Implementations§

source§

impl Default for Spotify

source§

fn default() -> Self

default

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more