2021-12-26 20:18:42 +00:00
|
|
|
use std::{
|
|
|
|
convert::{TryFrom, TryInto},
|
|
|
|
fmt::Debug,
|
|
|
|
};
|
2021-12-07 22:22:24 +00:00
|
|
|
|
|
|
|
use crate::{
|
2021-12-26 20:18:42 +00:00
|
|
|
availability::Availabilities, copyright::Copyrights, episode::Episodes, image::Images,
|
|
|
|
restriction::Restrictions, Metadata, RequestResult,
|
2021-12-07 22:22:24 +00:00
|
|
|
};
|
|
|
|
|
2021-12-26 20:18:42 +00:00
|
|
|
use librespot_core::{Error, Session, SpotifyId};
|
2021-12-07 22:22:24 +00:00
|
|
|
|
2021-12-26 20:18:42 +00:00
|
|
|
use librespot_protocol as protocol;
|
2021-12-07 22:22:24 +00:00
|
|
|
pub use protocol::metadata::Show_ConsumptionOrder as ShowConsumptionOrder;
|
|
|
|
pub use protocol::metadata::Show_MediaType as ShowMediaType;
|
|
|
|
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
pub struct Show {
|
|
|
|
pub id: SpotifyId,
|
|
|
|
pub name: String,
|
|
|
|
pub description: String,
|
|
|
|
pub publisher: String,
|
|
|
|
pub language: String,
|
|
|
|
pub is_explicit: bool,
|
|
|
|
pub covers: Images,
|
|
|
|
pub episodes: Episodes,
|
|
|
|
pub copyrights: Copyrights,
|
|
|
|
pub restrictions: Restrictions,
|
|
|
|
pub keywords: Vec<String>,
|
|
|
|
pub media_type: ShowMediaType,
|
|
|
|
pub consumption_order: ShowConsumptionOrder,
|
|
|
|
pub availability: Availabilities,
|
|
|
|
pub trailer_uri: SpotifyId,
|
|
|
|
pub has_music_and_talk: bool,
|
2021-12-10 19:33:43 +00:00
|
|
|
pub is_audiobook: bool,
|
2021-12-07 22:22:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[async_trait]
|
|
|
|
impl Metadata for Show {
|
|
|
|
type Message = protocol::metadata::Show;
|
|
|
|
|
|
|
|
async fn request(session: &Session, show_id: SpotifyId) -> RequestResult {
|
2021-12-26 20:18:42 +00:00
|
|
|
session.spclient().get_show_metadata(show_id).await
|
2021-12-07 22:22:24 +00:00
|
|
|
}
|
|
|
|
|
2021-12-26 20:18:42 +00:00
|
|
|
fn parse(msg: &Self::Message, _: SpotifyId) -> Result<Self, Error> {
|
2021-12-07 22:22:24 +00:00
|
|
|
Self::try_from(msg)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl TryFrom<&<Self as Metadata>::Message> for Show {
|
2021-12-26 20:18:42 +00:00
|
|
|
type Error = librespot_core::Error;
|
2021-12-07 22:22:24 +00:00
|
|
|
fn try_from(show: &<Self as Metadata>::Message) -> Result<Self, Self::Error> {
|
|
|
|
Ok(Self {
|
|
|
|
id: show.try_into()?,
|
|
|
|
name: show.get_name().to_owned(),
|
|
|
|
description: show.get_description().to_owned(),
|
|
|
|
publisher: show.get_publisher().to_owned(),
|
|
|
|
language: show.get_language().to_owned(),
|
|
|
|
is_explicit: show.get_explicit(),
|
|
|
|
covers: show.get_cover_image().get_image().into(),
|
|
|
|
episodes: show.get_episode().try_into()?,
|
|
|
|
copyrights: show.get_copyright().into(),
|
|
|
|
restrictions: show.get_restriction().into(),
|
|
|
|
keywords: show.get_keyword().to_vec(),
|
|
|
|
media_type: show.get_media_type(),
|
|
|
|
consumption_order: show.get_consumption_order(),
|
2022-01-14 22:28:09 +00:00
|
|
|
availability: show.get_availability().try_into()?,
|
2021-12-07 22:22:24 +00:00
|
|
|
trailer_uri: SpotifyId::from_uri(show.get_trailer_uri())?,
|
|
|
|
has_music_and_talk: show.get_music_and_talk(),
|
2021-12-10 19:33:43 +00:00
|
|
|
is_audiobook: show.get_is_audiobook(),
|
2021-12-07 22:22:24 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|