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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
use super::{Copyright, ExternalUrls, Image, ItemType, Market, Page, SimplifiedChapter};
use serde::{Deserialize, Serialize};
/// An audiobook author.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct Author {
/// The name of the author.
pub name: String,
}
/// An audiobook narrator.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct Narrator {
/// The name of the Narrator.
pub name: String,
}
/// Full audiobook information from the Spotify catalog.
///
/// Contains complete details about an audiobook including its chapters
/// (when the `page_items` feature is enabled), authors, narrators,
/// copyright information, and available markets.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct Audiobook {
/// The author(s) for the audiobook.
pub authors: Vec<Author>,
/// A list of the countries in which the audiobook can be played, identified by their [ISO 3166-1 alpha-2](http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) code.
#[cfg(feature = "markets")]
#[serde(skip_serializing_if = "Vec::is_empty", default)]
pub available_markets: Vec<Market>,
/// The copyright statements of the audiobook.
pub copyrights: Vec<Copyright>,
/// A description of the audiobook. HTML tags are stripped away from this field,
/// use `html_description` field in case HTML tags are needed.
pub description: String,
/// A description of the audiobook. This field may contain HTML tags.
pub html_description: String,
/// The edition of the audiobook.
pub edition: String,
/// Whether or not the audiobook has explicit content
/// (true = yes it does; false = no it does not OR unknown).
pub explicit: bool,
/// External URLs for this audiobook.
pub external_urls: ExternalUrls,
/// A link to the Web API endpoint providing full details of the audiobook.
pub href: String,
/// The [Spotify ID](https://developer.spotify.com/documentation/web-api/concepts/spotify-uris-ids) for the audiobook.
pub id: String,
/// The cover art for the audiobook in various sizes, widest first.
pub images: Vec<Image>,
/// A list of the languages used in the audiobook, identified by their [ISO 639](https://en.wikipedia.org/wiki/ISO_639) code.
pub languages: Vec<String>,
/// The media type of the audiobook.
pub media_type: String,
/// The name of the audiobook.
pub name: String,
/// The narrator(s) for the audiobook.
pub narrators: Vec<Narrator>,
/// The publisher of the audiobook.
pub publisher: String,
/// The object type.
///
/// Allowed values: "audiobook"
#[serde(rename = "type")]
pub type_: ItemType,
/// The [Spotify URI](https://developer.spotify.com/documentation/web-api/concepts/spotify-uris-ids) for the audiobook.
pub uri: String,
/// The number of chapters in this audiobook.
pub total_chapters: usize,
/// A list of simplified chapters in this audiobook.
#[cfg(feature = "page_items")]
pub chapters: Page<SimplifiedChapter>,
}
/// Simplified audiobook information with basic details only.
///
/// A lighter version of [`Audiobook`] that omits the chapters page.
/// Commonly returned when audiobooks are nested within other objects.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct SimplifiedAudiobook {
/// The author(s) for the audiobook.
pub authors: Vec<Author>,
/// A list of the countries in which the audiobook can be played, identified by their [ISO 3166-1 alpha-2](http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) code.
#[cfg(feature = "markets")]
#[serde(skip_serializing_if = "Vec::is_empty", default)]
pub available_markets: Vec<Market>,
/// The copyright statements of the audiobook.
pub copyrights: Vec<Copyright>,
/// A description of the audiobook. HTML tags are stripped away from this field,
/// use `html_description` field in case HTML tags are needed.
pub description: String,
/// A description of the audiobook. This field may contain HTML tags.
pub html_description: String,
/// The edition of the audiobook.
#[serde(skip_serializing_if = "Option::is_none")]
pub edition: Option<String>,
/// Whether or not the audiobook has explicit content
/// (true = yes it does; false = no it does not OR unknown).
pub explicit: bool,
/// External URLs for this audiobook.
pub external_urls: ExternalUrls,
/// A link to the Web API endpoint providing full details of the audiobook.
pub href: String,
/// The [Spotify ID](https://developer.spotify.com/documentation/web-api/concepts/spotify-uris-ids) for the audiobook.
pub id: String,
/// The cover art for the audiobook in various sizes, widest first.
pub images: Vec<Image>,
/// A list of the languages used in the audiobook, identified by their [ISO 639](https://en.wikipedia.org/wiki/ISO_639) code.
pub languages: Vec<String>,
/// The media type of the audiobook.
pub media_type: String,
/// The name of the audiobook.
pub name: String,
/// The narrator(s) for the audiobook.
pub narrators: Vec<Narrator>,
/// The publisher of the audiobook.
pub publisher: String,
/// The object type.
///
/// Allowed values: "audiobook"
#[serde(rename = "type")]
pub type_: ItemType,
/// The [Spotify URI](https://developer.spotify.com/documentation/web-api/concepts/spotify-uris-ids) for the audiobook.
pub uri: String,
/// The number of chapters in this audiobook.
pub total_chapters: usize,
}
impl From<Audiobook> for SimplifiedAudiobook {
fn from(audiobook: Audiobook) -> Self {
Self {
authors: audiobook.authors,
#[cfg(feature = "markets")]
available_markets: audiobook.available_markets,
copyrights: audiobook.copyrights,
description: audiobook.description,
html_description: audiobook.html_description,
edition: Some(audiobook.edition),
explicit: audiobook.explicit,
external_urls: audiobook.external_urls,
href: audiobook.href,
id: audiobook.id,
images: audiobook.images,
languages: audiobook.languages,
media_type: audiobook.media_type,
name: audiobook.name,
narrators: audiobook.narrators,
publisher: audiobook.publisher,
type_: audiobook.type_,
uri: audiobook.uri,
total_chapters: audiobook.total_chapters,
}
}
}
/// Spotify catalog information for several audiobooks
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct Audiobooks {
pub audiobooks: Vec<Option<Audiobook>>,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn audiobook() {
let json = r#"
{
"authors": [
{
"name": "string"
}
],
"available_markets": ["US"],
"copyrights": [
{
"text": "string",
"type": "C"
}
],
"description": "string",
"html_description": "string",
"edition": "Unabridged",
"explicit": false,
"external_urls": {
"spotify": "string"
},
"href": "string",
"id": "string",
"images": [
{
"url": "https://i.scdn.co/image/ab67616d00001e02ff9ca10b55ce82ae553c8228",
"height": 300,
"width": 300
}
],
"languages": ["string"],
"media_type": "string",
"name": "string",
"narrators": [
{
"name": "string"
}
],
"publisher": "string",
"type": "audiobook",
"uri": "string",
"total_chapters": 0,
"chapters": {
"href": "https://api.spotify.com/v1/me/shows?offset=0&limit=20",
"limit": 20,
"next": "https://api.spotify.com/v1/me/shows?offset=1&limit=1",
"offset": 0,
"previous": "https://api.spotify.com/v1/me/shows?offset=1&limit=1",
"total": 4,
"items": [
{
"audio_preview_url": "https://p.scdn.co/mp3-preview/2f37da1d4221f40b9d1a98cd191f4d6f1646ad17",
"available_markets": ["US"],
"chapter_number": 1,
"description": "We kept on ascending, with occasional periods of quick descent, but in the main always ascending. Suddenly, I became conscious of the fact that the driver was in the act of pulling up the horses in the courtyard of a vast ruined castle, from whose tall black windows came no ray of light, and whose broken battlements showed a jagged line against the moonlit sky.",
"html_description": "<p>We kept on ascending, with occasional periods of quick descent, but in the main always ascending. Suddenly, I became conscious of the fact that the driver was in the act of pulling up the horses in the courtyard of a vast ruined castle, from whose tall black windows came no ray of light, and whose broken battlements showed a jagged line against the moonlit sky.</p>",
"duration_ms": 1686230,
"explicit": false,
"external_urls": {
"spotify": "string"
},
"href": "https://api.spotify.com/v1/episodes/5Xt5DXGzch68nYYamXrNxZ",
"id": "5Xt5DXGzch68nYYamXrNxZ",
"images": [
{
"url": "https://i.scdn.co/image/ab67616d00001e02ff9ca10b55ce82ae553c8228",
"height": 300,
"width": 300
}
],
"is_playable": false,
"languages": ["fr", "en"],
"name": "Starting Your Own Podcast: Tips, Tricks, and Advice From Anchor Creators",
"release_date": "1981-12-15",
"release_date_precision": "day",
"resume_point": {
"fully_played": false,
"resume_position_ms": 0
},
"type": "episode",
"uri": "spotify:episode:0zLhl3WsOCQHbe1BPTiHgr",
"restrictions": {
"reason": "string"
}
}
]
}
}
"#;
crate::test::assert_deserialized!(Audiobook, json);
}
#[test]
fn simplified_audiobook() {
let json = r#"
{
"authors": [
{
"name": "string"
}
],
"available_markets": ["US"],
"copyrights": [
{
"text": "string",
"type": "C"
}
],
"description": "string",
"html_description": "string",
"edition": "Unabridged",
"explicit": false,
"external_urls": {
"spotify": "string"
},
"href": "string",
"id": "string",
"images": [
{
"url": "https://i.scdn.co/image/ab67616d00001e02ff9ca10b55ce82ae553c8228",
"height": 300,
"width": 300
}
],
"languages": ["string"],
"media_type": "string",
"name": "string",
"narrators": [
{
"name": "string"
}
],
"publisher": "string",
"type": "audiobook",
"uri": "string",
"total_chapters": 0
}
"#;
crate::test::assert_deserialized!(SimplifiedAudiobook, json);
}
}