forked from librespot-org/librespot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimage.rs
More file actions
92 lines (73 loc) · 2.32 KB
/
image.rs
File metadata and controls
92 lines (73 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
use std::{
fmt::Debug,
ops::{Deref, DerefMut},
};
use crate::util::{impl_deref_wrapped, impl_from_repeated, impl_try_from_repeated};
use librespot_core::{FileId, SpotifyUri};
use librespot_protocol as protocol;
use protocol::metadata::Image as ImageMessage;
use protocol::metadata::ImageGroup;
pub use protocol::metadata::image::Size as ImageSize;
use protocol::playlist_annotate3::TranscodedPicture as TranscodedPictureMessage;
use protocol::playlist4_external::PictureSize as PictureSizeMessage;
#[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<Image>);
impl From<&ImageGroup> for Images {
fn from(image_group: &ImageGroup) -> Self {
Self(image_group.image.iter().map(Into::into).collect())
}
}
impl_deref_wrapped!(Images, Vec<Image>);
#[derive(Debug, Clone)]
pub struct PictureSize {
pub target_name: String,
pub url: String,
}
#[derive(Debug, Clone, Default)]
pub struct PictureSizes(pub Vec<PictureSize>);
impl_deref_wrapped!(PictureSizes, Vec<PictureSize>);
#[derive(Debug, Clone)]
pub struct TranscodedPicture {
pub target_name: String,
pub uri: SpotifyUri,
}
#[derive(Debug, Clone)]
pub struct TranscodedPictures(pub Vec<TranscodedPicture>);
impl_deref_wrapped!(TranscodedPictures, Vec<TranscodedPicture>);
impl From<&ImageMessage> for Image {
fn from(image: &ImageMessage) -> Self {
Self {
id: image.into(),
size: image.size(),
width: image.width(),
height: image.height(),
}
}
}
impl_from_repeated!(ImageMessage, Images);
impl From<&PictureSizeMessage> for PictureSize {
fn from(size: &PictureSizeMessage) -> Self {
Self {
target_name: size.target_name().to_owned(),
url: size.url().to_owned(),
}
}
}
impl_from_repeated!(PictureSizeMessage, PictureSizes);
impl TryFrom<&TranscodedPictureMessage> for TranscodedPicture {
type Error = librespot_core::Error;
fn try_from(picture: &TranscodedPictureMessage) -> Result<Self, Self::Error> {
Ok(Self {
target_name: picture.target_name().to_owned(),
uri: picture.try_into()?,
})
}
}
impl_try_from_repeated!(TranscodedPictureMessage, TranscodedPictures);