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<'_>
impl Playlists<'_>
Sourcepub 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>
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.
Sourcepub async fn change_playlist(
self,
id: &str,
name: Option<&str>,
public: Option<bool>,
collaborative: Option<bool>,
description: Option<&str>,
) -> Result<(), Error>
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.
Sourcepub async fn create_playlist(
self,
name: &str,
public: bool,
collaborative: bool,
description: &str,
) -> Result<Response<Playlist>, Error>
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.
Sourcepub async fn current_users_playlists(
self,
limit: usize,
offset: usize,
) -> Result<Response<Page<PlaylistSimplified>>, Error>
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].
Sourcepub async fn get_users_playlists(
self,
id: &str,
limit: usize,
offset: usize,
) -> Result<Response<Page<PlaylistSimplified>>, Error>
pub async fn get_users_playlists( self, id: &str, limit: usize, offset: usize, ) -> Result<Response<Page<PlaylistSimplified>>, Error>
Sourcepub async fn get_playlist(
self,
id: &str,
market: Option<Market>,
) -> Result<Response<Playlist>, Error>
pub async fn get_playlist( self, id: &str, market: Option<Market>, ) -> Result<Response<Playlist>, Error>
Get information about a playlist.
Sourcepub async fn get_playlists_images(
self,
id: &str,
) -> Result<Response<Vec<Image>>, Error>
pub async fn get_playlists_images( self, id: &str, ) -> Result<Response<Vec<Image>>, Error>
Get a playlist’s cover images.
Sourcepub async fn get_playlists_items(
self,
id: &str,
limit: usize,
offset: usize,
market: Option<Market>,
) -> Result<Response<Page<PlaylistItem>>, Error>
pub async fn get_playlists_items( self, id: &str, limit: usize, offset: usize, market: Option<Market>, ) -> Result<Response<Page<PlaylistItem>>, Error>
Sourcepub 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>
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.
Sourcepub async fn reorder_playlist(
self,
id: &str,
range_start: usize,
range_length: usize,
insert_before: usize,
snapshot_id: &str,
) -> Result<String, Error>
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
).
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.
Sourcepub async fn replace_playlists_items<T: Display, E: Display>(
self,
id: &str,
items: impl IntoIterator<Item = PlaylistItemType<T, E>>,
) -> Result<String, Error>
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.
Sourcepub async fn upload_playlist_cover(
self,
id: &str,
image: String,
) -> Result<(), Error>
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
.
Sourcepub async fn upload_playlist_cover_jpeg<T: ?Sized + AsRef<[u8]>>(
self,
id: &str,
image: &T,
) -> Result<(), Error>
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.
Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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