spotify_rs/model/playlist.rs
1use chrono::{DateTime, Utc};
2use serde::Deserialize;
3use spotify_rs_macros::docs;
4
5use super::{user::ReferenceUser, *};
6
7/// A playlist.
8#[derive(Clone, Debug, Deserialize, PartialEq)]
9#[docs]
10pub struct Playlist {
11 /// Whether or not other users besides the owner are allowed to modify the playlist.
12 pub collaborative: bool,
13 /// The playlist's description.
14 ///
15 /// Note: it's only returned for modified, verified playlists.
16 pub description: Option<String>,
17 pub external_urls: ExternalUrls,
18 /// The followers of the playlist.
19 pub followers: Followers,
20 pub href: String,
21 pub id: String,
22 #[serde(deserialize_with = "null_to_default")]
23 pub images: Vec<Image>,
24 pub name: String,
25 /// The owner of the playlist.
26 pub owner: ReferenceUser,
27 /// Whether or not the playlist is public (if it's added to the user's profile).
28 pub public: Option<bool>,
29 /// The ID for the current version of the playlist. It can be used in
30 /// requests to target a specific playlist version.
31 pub snapshot_id: String,
32 /// The playlist's tracks.
33 pub tracks: Page<PlaylistItem>,
34 pub r#type: String,
35 pub uri: String,
36}
37
38/// A simplified playlist, missing some details, that is usually obtained
39/// through endpoints not specific to playlists. The `href` field may be
40/// used to get a full playlist.
41#[derive(Clone, Debug, Deserialize, PartialEq)]
42#[docs(name = "playlist")]
43pub struct SimplifiedPlaylist {
44 /// Whether or not other users besides the owner are allowed to modify the playlist.
45 pub collaborative: bool,
46 /// The playlist's description.
47 ///
48 /// Note: it's only returned for modified, verified playlists.
49 pub description: Option<String>,
50 pub external_urls: ExternalUrls,
51 pub href: String,
52 pub id: String,
53 #[serde(deserialize_with = "null_to_default")]
54 pub images: Vec<Image>,
55 pub name: String,
56 /// The owner of the playlist.
57 pub owner: ReferenceUser,
58 /// Whether or not the playlist is public (if it's added to the user's profile).
59 pub public: Option<bool>,
60 /// The ID for the current version of the playlist. It can be used in
61 /// requests to target a specific playlist version.
62 pub snapshot_id: String,
63 /// The playlist's tracks.
64 pub tracks: Option<TrackReference>,
65 pub r#type: String,
66 pub uri: String,
67}
68
69// Used only to deserialize JSON responses with arrays that are named objects.
70#[derive(Clone, Debug, Deserialize, PartialEq)]
71pub(crate) struct Playlists {
72 pub(crate) playlists: Page<SimplifiedPlaylist>,
73}
74
75/// A track or episode within a playlist.
76#[derive(Clone, Debug, Deserialize, PartialEq)]
77pub struct PlaylistItem {
78 /// The date and time the item was added.
79 ///
80 /// Note: some very old playlists may return `None` in this field.
81 pub added_at: Option<DateTime<Utc>>,
82 /// The user who added the track or episode.
83 ///
84 /// Note: some very old playlists may return `None` in this field.
85 pub added_by: Option<ReferenceUser>,
86 /// Whether or not this item is a local file.
87 pub is_local: bool,
88 /// The item itself.
89 pub track: PlayableItem,
90}
91
92/// A list of featured playlists.
93#[derive(Clone, Debug, Deserialize, PartialEq)]
94pub struct FeaturedPlaylists {
95 /// The message of the playlist.
96 pub message: String,
97 /// The playlists.
98 pub playlists: Page<SimplifiedPlaylist>,
99}
100
101/// Contains the link where the full details of a playlist's tracks can be found,
102/// as well as the number of the tracks in the playlist.
103#[derive(Clone, Debug, Deserialize, PartialEq)]
104pub struct TrackReference {
105 /// A link to the Spotify Web API endpoint providing full details of the
106 /// playlist's tracks.
107 pub href: String,
108 /// The number of tracks in the playlist.
109 pub total: u32,
110}
111
112// Used only to deserialize JSON responses that are named objects.
113#[derive(Clone, Debug, Deserialize, PartialEq)]
114pub(crate) struct SnapshotId {
115 pub(crate) snapshot_id: String,
116}