1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
use std::collections::HashMap;
use std::time::Duration;
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use crate::model::{AlbumSimplified, ArtistSimplified, Context, Restrictions, TypeTrack};
macro_rules! inherit_track_simplified {
($(#[$attr:meta])* $name:ident { $($(#[$f_attr:meta])* $f_name:ident : $f_ty:ty,)* }) => {
to_struct!($(#[$attr])* $name {
$(
$(#[$f_attr])*
$f_name: $f_ty,
)*
/// The artists who performed the track.
artists: Vec<ArtistSimplified>,
/// The markets in which this track is available. Only [`Some`] if the market parameter
/// is not supplied in the request. This is an ISO-3166 2-letter country code.
available_markets: Option<Vec<String>>,
/// The disc number (1 unless the album contains more than one disc).
disc_number: usize,
/// The track length.
#[serde(rename = "duration_ms", with = "serde_millis")]
duration: Duration,
/// Whether the track has explicit lyrics, false if unknown.
explicit: bool,
/// Known external URLs for this track.
external_urls: HashMap<String, String>,
/// The [Spotify ID](https://developer.spotify.com/documentation/web-api/#spotify-uris-and-ids)
/// for this track. Only not present for a local track, which can only ever be obtained
/// from a playlist.
id: Option<String>,
/// When [track
/// relinking](https://developer.spotify.com/documentation/general/guides/track-relinking-guide/)
/// is applied, if the track is playable in the given market.
is_playable: Option<bool>,
/// When [track
/// relinking](https://developer.spotify.com/documentation/general/guides/track-relinking-guide/)
/// is applied and the requested track has been replaced by a different one.
linked_from: Option<TrackLink>,
/// When [track
/// relinking](https://developer.spotify.com/documentation/general/guides/track-relinking-guide/)
/// is applied, the original track isn't available in the given market and Spotify didn't have
/// any tracks to relink it with, then this is Some.
restrictions: Option<Restrictions>,
/// The name of the track.
name: String,
/// Link to a 30 second MP3 preview of the track, doesn't have to be there.
preview_url: Option<String>,
/// The 1-indexed number of the track in its album; if the track has several discs,
/// then it the number on the specified disc.
track_number: usize,
/// The item type; `track`.
#[serde(rename = "type")]
item_type: TypeTrack,
/// Whether the track is a local track.
is_local: bool,
});
}
}
inherit_track_simplified!(
/// A simplified track object.
TrackSimplified {}
);
inherit_track_simplified!(
/// A track object.
Track {
/// The album on which this track appears.
album: AlbumSimplified,
/// Known external IDs for this track.
external_ids: HashMap<String, String>,
/// The popularity of the track. The value will be between 0 and 100, with 100 being the most
/// popular. The popularity is calculated from the total number of plays and how recent they
/// are.
popularity: u32,
}
);
impl Track {
/// Convert to a `TrackSimplified`.
#[must_use]
pub fn simplify(self) -> TrackSimplified {
TrackSimplified {
artists: self.artists,
available_markets: self.available_markets,
disc_number: self.disc_number,
duration: self.duration,
explicit: self.explicit,
external_urls: self.external_urls,
id: self.id,
is_playable: self.is_playable,
linked_from: self.linked_from,
restrictions: self.restrictions,
name: self.name,
preview_url: self.preview_url,
track_number: self.track_number,
item_type: TypeTrack,
is_local: self.is_local,
}
}
}
impl From<Track> for TrackSimplified {
fn from(track: Track) -> Self {
track.simplify()
}
}
/// A link to a track.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct TrackLink {
/// Known external URLs for this track.
pub external_urls: HashMap<String, String>,
/// The [Spotify ID](https://developer.spotify.com/documentation/web-api/#spotify-uris-and-ids)
/// for this track.
pub id: String,
/// The item type; `track`.
#[serde(rename = "type")]
pub item_type: TypeTrack,
}
/// When and how a track was played.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct PlayHistory {
/// The track the user listened to.
pub track: TrackSimplified,
/// When the track was played.
pub played_at: DateTime<Utc>,
/// The context from which the track was played.
pub context: Option<Context>,
}
/// Information about a track that has been saved.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct SavedTrack {
/// When the track was saved.
pub added_at: DateTime<Utc>,
/// Information about the track.
pub track: Track,
}
/// The number of tracks an object contains.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Tracks {
/// The number of tracks.
pub total: usize,
}