1use super::{Copyright, ExternalUrls, Image, ItemType, Market, Page, SimplifiedEpisode};
2use serde::{Deserialize, Serialize};
3
4#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
10pub struct Show {
11 #[cfg(feature = "markets")]
13 #[serde(skip_serializing_if = "Vec::is_empty", default)]
14 pub available_markets: Vec<Market>,
15
16 pub copyrights: Vec<Copyright>,
18
19 pub description: String,
22
23 pub html_description: String,
25
26 pub explicit: bool,
28
29 pub external_urls: ExternalUrls,
31
32 pub href: String,
34
35 pub id: String,
37
38 pub images: Vec<Image>,
40
41 pub is_externally_hosted: bool,
43
44 pub languages: Vec<String>,
46
47 pub media_type: String,
49
50 pub name: String,
52
53 pub publisher: String,
55
56 #[serde(rename = "type")]
60 pub type_: ItemType,
61
62 pub uri: String,
64
65 pub total_episodes: usize,
67
68 #[cfg(feature = "page_items")]
70 pub episodes: Page<SimplifiedEpisode>,
71}
72
73#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
78pub struct SimplifiedShow {
79 #[cfg(feature = "markets")]
81 #[serde(skip_serializing_if = "Vec::is_empty", default)]
82 pub available_markets: Vec<Market>,
83
84 pub copyrights: Vec<Copyright>,
86
87 pub description: String,
90
91 pub html_description: String,
93
94 pub explicit: bool,
96
97 pub external_urls: ExternalUrls,
99
100 pub href: String,
102
103 pub id: String,
105
106 pub images: Vec<Image>,
108
109 pub is_externally_hosted: bool,
111
112 pub languages: Vec<String>,
114
115 pub media_type: String,
117
118 pub name: String,
120
121 pub publisher: String,
123
124 #[serde(rename = "type")]
128 pub type_: ItemType,
129
130 pub uri: String,
132
133 pub total_episodes: usize,
135}
136
137impl From<Show> for SimplifiedShow {
138 fn from(show: Show) -> Self {
139 Self {
140 #[cfg(feature = "markets")]
141 available_markets: show.available_markets,
142 copyrights: show.copyrights,
143 description: show.description,
144 html_description: show.html_description,
145 explicit: show.explicit,
146 external_urls: show.external_urls,
147 href: show.href,
148 id: show.id,
149 images: show.images,
150 is_externally_hosted: show.is_externally_hosted,
151 languages: show.languages,
152 media_type: show.media_type,
153 name: show.name,
154 publisher: show.publisher,
155 type_: show.type_,
156 uri: show.uri,
157 total_episodes: show.total_episodes,
158 }
159 }
160}
161
162#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
166pub struct SavedShow {
167 pub added_at: String,
171
172 pub show: SimplifiedShow,
174}
175
176#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
178pub struct Shows {
179 pub shows: Vec<SimplifiedShow>,
180}
181
182#[cfg(test)]
183mod tests {
184 use super::*;
185
186 #[test]
187 fn show() {
188 let json = r#"
189 {
190 "available_markets": ["US"],
191 "copyrights": [
192 {
193 "text": "string",
194 "type": "C"
195 }
196 ],
197 "description": "string",
198 "html_description": "string",
199 "explicit": false,
200 "external_urls": {
201 "spotify": "string"
202 },
203 "href": "string",
204 "id": "string",
205 "images": [
206 {
207 "url": "https://i.scdn.co/image/ab67616d00001e02ff9ca10b55ce82ae553c8228",
208 "height": 300,
209 "width": 300
210 }
211 ],
212 "is_externally_hosted": false,
213 "languages": ["string"],
214 "media_type": "string",
215 "name": "string",
216 "publisher": "string",
217 "type": "show",
218 "uri": "string",
219 "total_episodes": 0,
220 "episodes": {
221 "href": "https://api.spotify.com/v1/me/shows?offset=0&limit=20",
222 "limit": 20,
223 "next": "https://api.spotify.com/v1/me/shows?offset=1&limit=1",
224 "offset": 0,
225 "previous": "https://api.spotify.com/v1/me/shows?offset=1&limit=1",
226 "total": 4,
227 "items": [
228 {
229 "audio_preview_url": "https://p.scdn.co/mp3-preview/2f37da1d4221f40b9d1a98cd191f4d6f1646ad17",
230 "description": "A Spotify podcast sharing fresh insights on important topics of the moment—in a way only Spotify can. You’ll hear from experts in the music, podcast and tech industries as we discover and uncover stories about our work and the world around us.",
231 "html_description": "<p>A Spotify podcast sharing fresh insights on important topics of the moment—in a way only Spotify can. You’ll hear from experts in the music, podcast and tech industries as we discover and uncover stories about our work and the world around us.</p>",
232 "duration_ms": 1686230,
233 "explicit": false,
234 "external_urls": {
235 "spotify": "string"
236 },
237 "href": "https://api.spotify.com/v1/episodes/5Xt5DXGzch68nYYamXrNxZ",
238 "id": "5Xt5DXGzch68nYYamXrNxZ",
239 "images": [
240 {
241 "url": "https://i.scdn.co/image/ab67616d00001e02ff9ca10b55ce82ae553c8228",
242 "height": 300,
243 "width": 300
244 }
245 ],
246 "is_externally_hosted": false,
247 "is_playable": false,
248 "language": "en",
249 "languages": ["fr", "en"],
250 "name": "Starting Your Own Podcast: Tips, Tricks, and Advice From Anchor Creators",
251 "release_date": "1981-12-15",
252 "release_date_precision": "day",
253 "resume_point": {
254 "fully_played": false,
255 "resume_position_ms": 0
256 },
257 "type": "episode",
258 "uri": "spotify:episode:0zLhl3WsOCQHbe1BPTiHgr",
259 "restrictions": {
260 "reason": "string"
261 }
262 }
263 ]
264 }
265 }
266 "#;
267
268 crate::test::assert_deserialized!(Show, json);
269 }
270
271 #[test]
272 fn simplified_show() {
273 let json = r#"
274 {
275 "available_markets": ["US"],
276 "copyrights": [
277 {
278 "text": "string",
279 "type": "C"
280 }
281 ],
282 "description": "string",
283 "html_description": "string",
284 "explicit": false,
285 "external_urls": {
286 "spotify": "string"
287 },
288 "href": "string",
289 "id": "string",
290 "images": [
291 {
292 "url": "https://i.scdn.co/image/ab67616d00001e02ff9ca10b55ce82ae553c8228",
293 "height": 300,
294 "width": 300
295 }
296 ],
297 "is_externally_hosted": false,
298 "languages": ["string"],
299 "media_type": "string",
300 "name": "string",
301 "publisher": "string",
302 "type": "show",
303 "uri": "string",
304 "total_episodes": 0
305 }
306 "#;
307
308 crate::test::assert_deserialized!(SimplifiedShow, json);
309 }
310}