librespot_metadata/
show.rs1use std::fmt::Debug;
2
3use crate::{
4 availability::Availabilities, copyright::Copyrights, episode::Episodes, image::Images,
5 restriction::Restrictions, Metadata, RequestResult,
6};
7
8use librespot_core::{Error, Session, SpotifyId};
9
10use librespot_protocol as protocol;
11pub use protocol::metadata::show::ConsumptionOrder as ShowConsumptionOrder;
12pub use protocol::metadata::show::MediaType as ShowMediaType;
13
14#[derive(Debug, Clone)]
15pub struct Show {
16 pub id: SpotifyId,
17 pub name: String,
18 pub description: String,
19 pub publisher: String,
20 pub language: String,
21 pub is_explicit: bool,
22 pub covers: Images,
23 pub episodes: Episodes,
24 pub copyrights: Copyrights,
25 pub restrictions: Restrictions,
26 pub keywords: Vec<String>,
27 pub media_type: ShowMediaType,
28 pub consumption_order: ShowConsumptionOrder,
29 pub availability: Availabilities,
30 pub trailer_uri: SpotifyId,
31 pub has_music_and_talk: bool,
32 pub is_audiobook: bool,
33}
34
35#[async_trait]
36impl Metadata for Show {
37 type Message = protocol::metadata::Show;
38
39 async fn request(session: &Session, show_id: &SpotifyId) -> RequestResult {
40 session.spclient().get_show_metadata(show_id).await
41 }
42
43 fn parse(msg: &Self::Message, _: &SpotifyId) -> Result<Self, Error> {
44 Self::try_from(msg)
45 }
46}
47
48impl TryFrom<&<Self as Metadata>::Message> for Show {
49 type Error = librespot_core::Error;
50 fn try_from(show: &<Self as Metadata>::Message) -> Result<Self, Self::Error> {
51 Ok(Self {
52 id: show.try_into()?,
53 name: show.name().to_owned(),
54 description: show.description().to_owned(),
55 publisher: show.publisher().to_owned(),
56 language: show.language().to_owned(),
57 is_explicit: show.explicit(),
58 covers: show.cover_image.image.as_slice().into(),
59 episodes: show.episode.as_slice().try_into()?,
60 copyrights: show.copyright.as_slice().into(),
61 restrictions: show.restriction.as_slice().into(),
62 keywords: show.keyword.to_vec(),
63 media_type: show.media_type(),
64 consumption_order: show.consumption_order(),
65 availability: show.availability.as_slice().try_into()?,
66 trailer_uri: SpotifyId::from_uri(show.trailer_uri())?,
67 has_music_and_talk: show.music_and_talk(),
68 is_audiobook: show.is_audiobook(),
69 })
70 }
71}