1use serde::Deserialize;
2use spotify_rs_macros::docs;
3
4use super::*;
5
6#[derive(Clone, Debug, Deserialize, PartialEq)]
8#[docs]
9pub struct Audiobook {
10 pub authors: Vec<Author>,
12 #[serde(default)]
13 pub available_markets: Vec<String>,
14 pub copyrights: Vec<Copyright>,
15 pub description: String,
17 pub html_description: String,
19 pub edition: String,
21 pub explicit: bool,
22 pub external_urls: ExternalUrls,
23 pub href: String,
24 pub id: String,
25 pub images: Vec<Image>,
26 pub languages: Vec<String>,
27 pub media_type: String,
28 pub name: String,
29 pub narrators: Vec<Narrator>,
31 pub publisher: String,
32 pub r#type: String,
33 pub uri: String,
34 pub total_chapters: u32,
36 pub chapters: Page<SimplifiedChapter>,
38}
39
40#[derive(Clone, Debug, Deserialize, PartialEq)]
44#[docs(name = "audiobook")]
45pub struct SimplifiedAudiobook {
46 pub authors: Vec<Author>,
48 #[serde(default)]
49 pub available_markets: Vec<String>,
50 pub copyrights: Vec<Copyright>,
51 pub description: String,
53 pub html_description: String,
55 pub edition: String,
57 pub explicit: bool,
60 pub external_urls: ExternalUrls,
61 pub href: String,
62 pub id: String,
63 pub images: Vec<Image>,
64 pub languages: Vec<String>,
67 pub media_type: String,
69 pub name: String,
70 pub narrators: Vec<Narrator>,
72 pub publisher: String,
74 pub r#type: String,
75 pub uri: String,
76 pub total_chapters: Option<u32>,
78}
79
80#[derive(Clone, Debug, Deserialize, PartialEq)]
82pub(crate) struct Audiobooks {
83 pub(crate) audiobooks: Vec<Option<Audiobook>>,
84}
85
86#[derive(Clone, Debug, Deserialize, PartialEq)]
88#[docs]
89pub struct Chapter {
90 pub audio_preview_url: Option<String>,
97 #[serde(default)]
98 pub available_markets: Vec<String>,
99 pub chapter_number: u32,
101 pub description: String,
103 pub html_description: String,
105 pub duration_ms: u32,
106 pub explicit: bool,
109 pub external_urls: ExternalUrls,
110 pub href: String,
111 pub id: String,
112 pub images: Vec<Image>,
113 pub is_playable: Option<bool>,
114 pub languages: Vec<String>,
117 pub name: String,
118 pub release_date: String,
119 pub release_date_precision: DatePrecision,
120 pub resume_point: Option<ResumePoint>,
121 pub r#type: String,
122 pub uri: String,
123 pub restrictions: Option<Restriction>,
125 pub audiobook: SimplifiedAudiobook,
127}
128
129#[derive(Clone, Debug, Deserialize, PartialEq)]
133#[docs(name = "chapter")]
134pub struct SimplifiedChapter {
135 pub audio_preview_url: Option<String>,
142 #[serde(default)]
143 pub available_markets: Vec<String>,
144 pub chapter_number: u32,
146 pub description: String,
147 pub html_description: String,
148 pub duration_ms: u32,
149 pub explicit: bool,
150 pub external_urls: ExternalUrls,
151 pub href: String,
152 pub id: String,
153 pub images: Vec<Image>,
154 pub is_playable: Option<bool>,
155 pub languages: Vec<String>,
156 pub name: String,
157 pub release_date: String,
158 pub release_date_precision: DatePrecision,
159 pub resume_point: Option<ResumePoint>,
160 pub r#type: String,
161 pub uri: String,
162 pub restrictions: Option<Restriction>,
164}
165
166#[derive(Clone, Debug, Deserialize, PartialEq)]
168pub(crate) struct Chapters {
169 pub(crate) chapters: Vec<Option<Chapter>>,
170}
171
172#[derive(Clone, Debug, Deserialize, PartialEq)]
176pub struct Author {
177 pub name: String,
179}
180
181#[derive(Clone, Debug, Deserialize, PartialEq)]
183pub struct Narrator {
184 pub name: String,
186}
187
188impl Audiobook {
189 pub fn author_names(&self) -> Vec<String> {
191 self.authors.iter().map(|a| a.name.clone()).collect()
192 }
193
194 pub fn narrator_names(&self) -> Vec<String> {
196 self.narrators.iter().map(|n| n.name.clone()).collect()
197 }
198}
199
200impl SimplifiedAudiobook {
201 pub fn author_names(&self) -> Vec<String> {
203 self.authors.iter().map(|a| a.name.clone()).collect()
204 }
205
206 pub fn narrator_names(&self) -> Vec<String> {
208 self.narrators.iter().map(|n| n.name.clone()).collect()
209 }
210}