Struct Playlists

Source
pub struct Playlists<'a>(pub &'a Client);
Expand description

Endpoint functions relating to playlists.

The parameter snapshot_id is the snapshot of the playlist to perform the operation on to prevent concurrent accesses causing problems.

Take this example; person A gets playlist X. Person B removes track N from playlist X. Person A tries to do something to playlist X, assuming track N still exists, but it causes unexpected behaviour because track N doesn’t actually exist any more. However, with snapshot ids, person A will have used the snapshot ID they received from the initial request in their request. Spotify knows that person A is attempting to operate on an older playlist, and adjusts accordingly, causing no unexpected behaviour.

One feature of Spotify is that you cannot delete playlists; you can only unfollow them, hence there is no delete_playlist function.

Tuple Fields§

§0: &'a Client

Implementations§

Source§

impl Playlists<'_>

Source

pub async fn add_to_playlist<T: Display, E: Display>( self, id: &str, tracks: impl IntoIterator<Item = PlaylistItemType<T, E>>, position: Option<usize>, ) -> Result<String, Error>

Add tracks to a playlist.

Requires playist-modify-public if the playlist is public, and playlist-modify-private if it is private. position is the zero-indexed position to insert the tracks; if None it appends to the playlist. A maximum of 100 tracks can be specified.

This function returns the snapshot_id of the created playlist, which you should hold on to to stop concurrent accesses to the playlist interfering with each other.

Reference.

Source

pub async fn change_playlist( self, id: &str, name: Option<&str>, public: Option<bool>, collaborative: Option<bool>, description: Option<&str>, ) -> Result<(), Error>

Change a playlist’s details.

Requires playist-modify-public if the playlist is public, and playlist-modify-private if it is private. Each parameter, when Some, changes an attribute of the playlist. A playlist cannot be both public and collaborative.

Reference.

Source

pub async fn create_playlist( self, name: &str, public: bool, collaborative: bool, description: &str, ) -> Result<Response<Playlist>, Error>

Create a playlist.

Requires playlist-modify-public if creating a public playlist, requires playlist-modify-private if creating a private one.

Reference.

Source

pub async fn current_users_playlists( self, limit: usize, offset: usize, ) -> Result<Response<Page<PlaylistSimplified>>, Error>

Get current user’s playlists.

Gets a list of playlists owned or followed by the current Spotify user. Requires playlist-read-private in order to get private playlists, and playlist-read-collaborative to get collaborative playlists. Limit must be in the range [1..50], and offset must be in the range [0..100,000].

Reference.

Source

pub async fn get_users_playlists( self, id: &str, limit: usize, offset: usize, ) -> Result<Response<Page<PlaylistSimplified>>, Error>

Get a user’s playlists.

Gets a list of playlists owned or followed by a Spotify user.

Reference.

Source

pub async fn get_playlist( self, id: &str, market: Option<Market>, ) -> Result<Response<Playlist>, Error>

Get information about a playlist.

Reference.

Source

pub async fn get_playlists_images( self, id: &str, ) -> Result<Response<Vec<Image>>, Error>

Get a playlist’s cover images.

Reference.

Source

pub async fn get_playlists_items( self, id: &str, limit: usize, offset: usize, market: Option<Market>, ) -> Result<Response<Page<PlaylistItem>>, Error>

Get a playlist’s items.

Limit must be in the range [1..100].

Reference.

Source

pub async fn remove_from_playlist<T: Display, E: Display>( self, id: &str, items: impl IntoIterator<Item = (PlaylistItemType<T, E>, Option<&[usize]>)>, snapshot_id: &str, ) -> Result<String, Error>

Remove tracks from a playlist.

Requires playlist-modify-public if the playlist is public, requires playlist-modify-private if it is private.

Items is a list of items that will be removed, and optionally multiple positions where the items will be removed, otherwise it will remove them from the entire playlist. It is not possible to remove items only by position. There is a maximum of 100 items you can remove at once.

This function returns the snapshot_id of the created playlist, which you should hold on to to stop concurrent accesses to the playlist interfering with each other.

Reference.

Source

pub async fn reorder_playlist( self, id: &str, range_start: usize, range_length: usize, insert_before: usize, snapshot_id: &str, ) -> Result<String, Error>

Reorder items in a playlist.

Requires playlist-modify-public if the playlist is public, requires playlist-modify-private if it is private.

range_start and range_length specify a slice of the playlist to move around. This slice will always remain in the same order. It will be moved before the position in insert_before (e.g. it will be moved to start if insert_before == 0 and it will be moved to the end if insert_before == the playlist's length).

A helpful diagram from Spotify explaining this

This function does nothing if range_length == 0 or if range_start + range_length == insert_before.

This function returns the snapshot_id of the created playlist, which you should hold on to to stop concurrent accesses to the playlist interfering with each other.

Reference.

Source

pub async fn replace_playlists_items<T: Display, E: Display>( self, id: &str, items: impl IntoIterator<Item = PlaylistItemType<T, E>>, ) -> Result<String, Error>

Replace a playlist’s items.

Requires playlist-modify-public if the playlist is public, requires playlist-modify-private if it is private.

This function removes all the items from the given playlist, and replaces them with the given items. The maximum number of tracks is 100, if you need more you can use add_to_playlist.

This function returns the snapshot_id of the created playlist, which you should hold on to to stop concurrent accesses to the playlist interfering with each other.

Reference.

Source

pub async fn upload_playlist_cover( self, id: &str, image: String, ) -> Result<(), Error>

Upload a custom playlist cover image.

Requires playlist-modify-public if the playlist is public, requires playlist-modify-private if it is private, and also requires ugc-image-upload.

image must be a base64-encoded JPEG image under 256KB. If you want to pass in JPEG data, see upload_playlist_cover_jpeg; if you want to pass in a filename, see upload_playlist_cover_file.

Reference.

Source

pub async fn upload_playlist_cover_jpeg<T: ?Sized + AsRef<[u8]>>( self, id: &str, image: &T, ) -> Result<(), Error>

Upload a custom playlist cover image.

Requires playlist-modify-public if the playlist is public, requires playlist-modify-private if it is private, and also requires ugc-image-upload.

image must be JPEG data.

This function is only available when the base64 feature of this library is enabled.

Reference.

Trait Implementations§

Source§

impl<'a> Clone for Playlists<'a>

Source§

fn clone(&self) -> Playlists<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for Playlists<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> Copy for Playlists<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for Playlists<'a>

§

impl<'a> !RefUnwindSafe for Playlists<'a>

§

impl<'a> Send for Playlists<'a>

§

impl<'a> Sync for Playlists<'a>

§

impl<'a> Unpin for Playlists<'a>

§

impl<'a> !UnwindSafe for Playlists<'a>

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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 T
where 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

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 T
where U: TryFrom<T>,

Source§

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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
Source§

impl<T> ErasedDestructor for T
where T: 'static,