spotify_rs/model/track.rs
1use chrono::{DateTime, Utc};
2use serde::Deserialize;
3use spotify_rs_macros::docs;
4
5use super::{album::SimplifiedAlbum, artist::SimplifiedArtist, *};
6
7/// A track.
8#[derive(Clone, Debug, Deserialize, PartialEq)]
9#[docs]
10pub struct Track {
11 /// The album the track belongs to.
12 pub album: SimplifiedAlbum,
13 /// The artists who performed on the track.
14 pub artists: Vec<SimplifiedArtist>,
15 pub available_markets: Option<Vec<String>>,
16 /// The disc number, which us usually `1`, unless the album consists of more
17 /// than one disk.
18 pub disc_number: u32,
19 pub duration_ms: u32,
20 pub explicit: bool,
21 pub external_ids: ExternalIds,
22 pub external_urls: ExternalUrls,
23 pub href: String,
24 pub id: String,
25 /// It's part of the response when
26 /// [Track Relinking](https://developer.spotify.com/documentation/web-api/concepts/track-relinking)
27 /// is applied.
28 pub is_playable: Option<bool>,
29 /// It's part of the response when
30 /// [Track Relinking](https://developer.spotify.com/documentation/web-api/concepts/track-relinking)
31 /// has been applied and the requested track has been replaced with a
32 /// different one. This field contains information about the originally
33 /// requested track.
34 pub linked_from: Option<LinkedFrom>,
35 pub restrictions: Option<Restriction>,
36 pub name: String,
37 /// A value ranging between `0` - `100` that represents the popularity
38 /// of a track. The popularity is based mostly on the number of times
39 /// the track has been played and how recently it's been played.
40 ///
41 /// Duplicate tracks - the same track from a single and an album are rated
42 /// independently.
43 ///
44 /// Note: the value may lag behind by a few days, as it's not updated in
45 /// real time.
46 pub popularity: u32,
47 /// The URL for a 30 second MP3 preview of the track.
48 ///
49 /// **Note:** This attribute has been deprecated by Spotify. It continues to work for
50 /// applications already using the extended mode in the API.
51 ///
52 /// You can read more about this [here](https://developer.spotify.com/blog/2024-11-27-changes-to-the-web-api).
53 pub preview_url: Option<String>,
54 /// The number of the track.
55 pub track_number: u32,
56 pub r#type: String,
57 pub uri: String,
58 /// Whether or not the track is from a local file.
59 pub is_local: bool,
60}
61
62// Used only to deserialize JSON responses with arrays that are named objects.
63#[derive(Clone, Debug, Deserialize, PartialEq)]
64pub(crate) struct Tracks {
65 pub(crate) tracks: Vec<Track>,
66}
67
68/// A simplified track, missing some details, that is usually obtained
69/// through endpoints not specific to tracks. The `href` field may be
70/// used to get a full track.
71#[derive(Clone, Debug, Deserialize, PartialEq)]
72#[docs(name = "track")]
73pub struct SimplifiedTrack {
74 /// The artists who performed on the track.
75 pub artists: Vec<SimplifiedArtist>,
76 pub available_markets: Option<Vec<String>>,
77 /// The disc number, which us usually `1`, unless the album consists of more
78 /// than one disk.
79 pub disc_number: u32,
80 pub duration_ms: u32,
81 pub explicit: bool,
82 pub external_urls: ExternalUrls,
83 pub href: String,
84 pub id: String,
85 pub is_playable: Option<bool>,
86 /// It's part of the response when
87 /// [Track Relinking](https://developer.spotify.com/documentation/web-api/concepts/track-relinking)
88 /// has been applied and the requested track has been replaced with a
89 /// different one. This field contains information about the originally
90 /// requested track.
91 pub linked_from: Option<LinkedFrom>,
92 pub restrictions: Option<Restriction>,
93 pub name: String,
94 /// The URL for a 30 second MP3 preview of the track.
95 ///
96 /// **Note:** This attribute has been deprecated by Spotify. It continues to work for
97 /// applications already using the extended mode in the API.
98 ///
99 /// You can read more about this [here](https://developer.spotify.com/blog/2024-11-27-changes-to-the-web-api).
100 pub preview_url: Option<String>,
101 /// The number of the track.
102 pub track_number: u32,
103 pub r#type: String,
104 pub uri: String,
105 /// Whether or not the track is from a local file.
106 pub is_local: bool,
107}
108
109/// A track saved by a user.
110#[derive(Clone, Debug, Deserialize, PartialEq)]
111pub struct SavedTrack {
112 /// The date and time the track was saved.
113 pub added_at: DateTime<Utc>,
114 /// The track itself.
115 pub track: Track,
116}
117
118/// Information about a track that's been
119/// [relinked](https://developer.spotify.com/documentation/web-api/concepts/track-relinking).
120#[derive(Clone, Debug, Deserialize, PartialEq)]
121#[docs(name = "track")]
122pub struct LinkedFrom {
123 pub external_urls: ExternalUrls,
124 pub href: String,
125 pub id: Option<String>,
126 pub r#type: String,
127 pub uri: String,
128}