use std::{ convert::{TryFrom, TryInto}, fmt::Debug, ops::{Deref, DerefMut}, }; use crate::util::{from_repeated_message, impl_deref_wrapped, try_from_repeated_message}; use librespot_core::{FileId, SpotifyId}; use librespot_protocol as protocol; use protocol::metadata::Image as ImageMessage; pub use protocol::metadata::Image_Size as ImageSize; use protocol::playlist4_external::PictureSize as PictureSizeMessage; use protocol::playlist_annotate3::TranscodedPicture as TranscodedPictureMessage; #[derive(Debug, Clone)] pub struct Image { pub id: FileId, pub size: ImageSize, pub width: i32, pub height: i32, } #[derive(Debug, Clone, Default)] pub struct Images(pub Vec); impl_deref_wrapped!(Images, Vec); #[derive(Debug, Clone)] pub struct PictureSize { pub target_name: String, pub url: String, } #[derive(Debug, Clone, Default)] pub struct PictureSizes(pub Vec); impl_deref_wrapped!(PictureSizes, Vec); #[derive(Debug, Clone)] pub struct TranscodedPicture { pub target_name: String, pub uri: SpotifyId, } #[derive(Debug, Clone)] pub struct TranscodedPictures(pub Vec); impl_deref_wrapped!(TranscodedPictures, Vec); impl From<&ImageMessage> for Image { fn from(image: &ImageMessage) -> Self { Self { id: image.into(), size: image.get_size(), width: image.get_width(), height: image.get_height(), } } } from_repeated_message!(ImageMessage, Images); impl From<&PictureSizeMessage> for PictureSize { fn from(size: &PictureSizeMessage) -> Self { Self { target_name: size.get_target_name().to_owned(), url: size.get_url().to_owned(), } } } from_repeated_message!(PictureSizeMessage, PictureSizes); impl TryFrom<&TranscodedPictureMessage> for TranscodedPicture { type Error = librespot_core::Error; fn try_from(picture: &TranscodedPictureMessage) -> Result { Ok(Self { target_name: picture.get_target_name().to_owned(), uri: picture.try_into()?, }) } } try_from_repeated_message!(TranscodedPictureMessage, TranscodedPictures);