feat: add VideoId model
This commit is contained in:
parent
2a4233e5d5
commit
900eb487ce
2 changed files with 63 additions and 2 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
use super::{
|
use super::{
|
||||||
AlbumItem, ArtistItem, Channel, ChannelId, ChannelItem, ChannelTag, MusicItem,
|
AlbumItem, ArtistId, ArtistItem, Channel, ChannelId, ChannelItem, ChannelTag, MusicArtist,
|
||||||
MusicPlaylistItem, PlaylistItem, TrackItem, VideoItem, YouTubeItem,
|
MusicItem, MusicPlaylistItem, PlaylistItem, PlaylistVideo, TrackItem, VideoId, VideoItem,
|
||||||
|
YouTubeItem,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Trait for casting generic YouTube/YouTube music items to a specific kind.
|
/// Trait for casting generic YouTube/YouTube music items to a specific kind.
|
||||||
|
|
@ -125,3 +126,53 @@ impl<T> From<Channel<T>> for ChannelId {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<MusicArtist> for ChannelId {
|
||||||
|
fn from(artist: MusicArtist) -> Self {
|
||||||
|
Self {
|
||||||
|
id: artist.id,
|
||||||
|
name: artist.name,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TryFrom<ArtistId> for ChannelId {
|
||||||
|
type Error = ();
|
||||||
|
|
||||||
|
fn try_from(artist: ArtistId) -> Result<Self, Self::Error> {
|
||||||
|
match artist.id {
|
||||||
|
Some(id) => Ok(Self {
|
||||||
|
id,
|
||||||
|
name: artist.name,
|
||||||
|
}),
|
||||||
|
None => Err(()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<VideoItem> for VideoId {
|
||||||
|
fn from(video: VideoItem) -> Self {
|
||||||
|
Self {
|
||||||
|
id: video.id,
|
||||||
|
name: video.name,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<PlaylistVideo> for VideoId {
|
||||||
|
fn from(video: PlaylistVideo) -> Self {
|
||||||
|
Self {
|
||||||
|
id: video.id,
|
||||||
|
name: video.name,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<TrackItem> for VideoId {
|
||||||
|
fn from(track: TrackItem) -> Self {
|
||||||
|
Self {
|
||||||
|
id: track.id,
|
||||||
|
name: track.name,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -893,6 +893,16 @@ pub struct PlaylistItem {
|
||||||
pub video_count: Option<u64>,
|
pub video_count: Option<u64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// YouTube video identifier
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
|
||||||
|
#[non_exhaustive]
|
||||||
|
pub struct VideoId {
|
||||||
|
/// Video ID
|
||||||
|
pub id: String,
|
||||||
|
/// Video title
|
||||||
|
pub name: String,
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#MUSIC
|
#MUSIC
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
Reference in a new issue