2021-12-26 20:18:42 +00:00
|
|
|
use std::{
|
|
|
|
fmt::Debug,
|
2022-08-02 10:45:37 +00:00
|
|
|
ops::{Deref, DerefMut},
|
2021-12-07 22:22:24 +00:00
|
|
|
};
|
|
|
|
|
2022-08-02 12:21:07 +00:00
|
|
|
use crate::util::{impl_deref_wrapped, impl_from_repeated, impl_try_from_repeated};
|
2021-12-07 22:22:24 +00:00
|
|
|
|
2021-12-26 20:18:42 +00:00
|
|
|
use librespot_core::{FileId, SpotifyId};
|
|
|
|
|
|
|
|
use librespot_protocol as protocol;
|
2023-01-17 20:46:14 +00:00
|
|
|
pub use protocol::metadata::image::Size as ImageSize;
|
2021-12-07 22:22:24 +00:00
|
|
|
use protocol::metadata::Image as ImageMessage;
|
2022-08-23 20:23:37 +00:00
|
|
|
use protocol::metadata::ImageGroup;
|
2021-12-07 22:22:24 +00:00
|
|
|
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,
|
|
|
|
}
|
|
|
|
|
2022-07-31 22:44:43 +00:00
|
|
|
#[derive(Debug, Clone, Default)]
|
2021-12-07 22:22:24 +00:00
|
|
|
pub struct Images(pub Vec<Image>);
|
|
|
|
|
2022-08-23 20:23:37 +00:00
|
|
|
impl From<&ImageGroup> for Images {
|
|
|
|
fn from(image_group: &ImageGroup) -> Self {
|
|
|
|
Self(image_group.image.iter().map(|i| i.into()).collect())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-02 10:45:37 +00:00
|
|
|
impl_deref_wrapped!(Images, Vec<Image>);
|
2021-12-07 22:22:24 +00:00
|
|
|
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
pub struct PictureSize {
|
|
|
|
pub target_name: String,
|
|
|
|
pub url: String,
|
|
|
|
}
|
|
|
|
|
2022-07-31 22:44:43 +00:00
|
|
|
#[derive(Debug, Clone, Default)]
|
2021-12-07 22:22:24 +00:00
|
|
|
pub struct PictureSizes(pub Vec<PictureSize>);
|
|
|
|
|
2022-08-02 10:45:37 +00:00
|
|
|
impl_deref_wrapped!(PictureSizes, Vec<PictureSize>);
|
2021-12-07 22:22:24 +00:00
|
|
|
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
pub struct TranscodedPicture {
|
|
|
|
pub target_name: String,
|
|
|
|
pub uri: SpotifyId,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
pub struct TranscodedPictures(pub Vec<TranscodedPicture>);
|
|
|
|
|
2022-08-02 10:45:37 +00:00
|
|
|
impl_deref_wrapped!(TranscodedPictures, Vec<TranscodedPicture>);
|
2021-12-07 22:22:24 +00:00
|
|
|
|
|
|
|
impl From<&ImageMessage> for Image {
|
|
|
|
fn from(image: &ImageMessage) -> Self {
|
|
|
|
Self {
|
|
|
|
id: image.into(),
|
2023-01-17 20:46:14 +00:00
|
|
|
size: image.size(),
|
|
|
|
width: image.width(),
|
|
|
|
height: image.height(),
|
2021-12-07 22:22:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-02 12:21:07 +00:00
|
|
|
impl_from_repeated!(ImageMessage, Images);
|
2021-12-07 22:22:24 +00:00
|
|
|
|
|
|
|
impl From<&PictureSizeMessage> for PictureSize {
|
|
|
|
fn from(size: &PictureSizeMessage) -> Self {
|
|
|
|
Self {
|
2023-01-17 20:46:14 +00:00
|
|
|
target_name: size.target_name().to_owned(),
|
|
|
|
url: size.url().to_owned(),
|
2021-12-07 22:22:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-02 12:21:07 +00:00
|
|
|
impl_from_repeated!(PictureSizeMessage, PictureSizes);
|
2021-12-07 22:22:24 +00:00
|
|
|
|
|
|
|
impl TryFrom<&TranscodedPictureMessage> for TranscodedPicture {
|
2021-12-26 20:18:42 +00:00
|
|
|
type Error = librespot_core::Error;
|
2021-12-07 22:22:24 +00:00
|
|
|
fn try_from(picture: &TranscodedPictureMessage) -> Result<Self, Self::Error> {
|
|
|
|
Ok(Self {
|
2023-01-17 20:46:14 +00:00
|
|
|
target_name: picture.target_name().to_owned(),
|
2021-12-07 22:22:24 +00:00
|
|
|
uri: picture.try_into()?,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-02 12:21:07 +00:00
|
|
|
impl_try_from_repeated!(TranscodedPictureMessage, TranscodedPictures);
|