feat: add channel info to channel response items

This commit is contained in:
ThetaDev 2022-10-29 00:27:20 +02:00
parent 8026b08e2d
commit 6e77a2198d
13 changed files with 2188 additions and 412 deletions

64
src/model/convert.rs Normal file
View file

@ -0,0 +1,64 @@
use super::{Channel, ChannelId, ChannelItem, ChannelTag, PlaylistItem, VideoItem, YouTubeItem};
impl TryFrom<YouTubeItem> for VideoItem {
type Error = ();
fn try_from(value: YouTubeItem) -> Result<Self, Self::Error> {
match value {
YouTubeItem::Video(video) => Ok(video),
_ => Err(()),
}
}
}
impl TryFrom<YouTubeItem> for PlaylistItem {
type Error = ();
fn try_from(value: YouTubeItem) -> Result<Self, Self::Error> {
match value {
YouTubeItem::Playlist(playlist) => Ok(playlist),
_ => Err(()),
}
}
}
impl TryFrom<YouTubeItem> for ChannelItem {
type Error = ();
fn try_from(value: YouTubeItem) -> Result<Self, Self::Error> {
match value {
YouTubeItem::Channel(channel) => Ok(channel),
_ => Err(()),
}
}
}
impl<T> From<Channel<T>> for ChannelTag {
fn from(channel: Channel<T>) -> Self {
Self {
id: channel.id,
name: channel.name,
avatar: channel.avatar,
verification: channel.verification,
subscriber_count: channel.subscriber_count,
}
}
}
impl From<ChannelTag> for ChannelId {
fn from(channel: ChannelTag) -> Self {
Self {
id: channel.id,
name: channel.name,
}
}
}
impl<T> From<Channel<T>> for ChannelId {
fn from(channel: Channel<T>) -> Self {
Self {
id: channel.id,
name: channel.name,
}
}
}

View file

@ -1,5 +1,6 @@
//! YouTube API request and response models
mod convert;
mod ordering;
mod paginator;
pub mod richtext;
@ -850,36 +851,3 @@ pub struct PlaylistItem {
/// Number of playlist videos
pub video_count: Option<u64>,
}
impl TryFrom<YouTubeItem> for VideoItem {
type Error = ();
fn try_from(value: YouTubeItem) -> Result<Self, Self::Error> {
match value {
YouTubeItem::Video(video) => Ok(video),
_ => Err(()),
}
}
}
impl TryFrom<YouTubeItem> for PlaylistItem {
type Error = ();
fn try_from(value: YouTubeItem) -> Result<Self, Self::Error> {
match value {
YouTubeItem::Playlist(playlist) => Ok(playlist),
_ => Err(()),
}
}
}
impl TryFrom<YouTubeItem> for ChannelItem {
type Error = ();
fn try_from(value: YouTubeItem) -> Result<Self, Self::Error> {
match value {
YouTubeItem::Channel(channel) => Ok(channel),
_ => Err(()),
}
}
}