diff --git a/src/model/convert.rs b/src/model/convert.rs index e573911..ddfe25d 100644 --- a/src/model/convert.rs +++ b/src/model/convert.rs @@ -1,6 +1,7 @@ use super::{ - AlbumItem, ArtistItem, Channel, ChannelId, ChannelItem, ChannelTag, MusicItem, - MusicPlaylistItem, PlaylistItem, TrackItem, VideoItem, YouTubeItem, + AlbumItem, ArtistId, ArtistItem, Channel, ChannelId, ChannelItem, ChannelTag, MusicArtist, + MusicItem, MusicPlaylistItem, PlaylistItem, PlaylistVideo, TrackItem, VideoId, VideoItem, + YouTubeItem, }; /// Trait for casting generic YouTube/YouTube music items to a specific kind. @@ -125,3 +126,53 @@ impl From> for ChannelId { } } } + +impl From for ChannelId { + fn from(artist: MusicArtist) -> Self { + Self { + id: artist.id, + name: artist.name, + } + } +} + +impl TryFrom for ChannelId { + type Error = (); + + fn try_from(artist: ArtistId) -> Result { + match artist.id { + Some(id) => Ok(Self { + id, + name: artist.name, + }), + None => Err(()), + } + } +} + +impl From for VideoId { + fn from(video: VideoItem) -> Self { + Self { + id: video.id, + name: video.name, + } + } +} + +impl From for VideoId { + fn from(video: PlaylistVideo) -> Self { + Self { + id: video.id, + name: video.name, + } + } +} + +impl From for VideoId { + fn from(track: TrackItem) -> Self { + Self { + id: track.id, + name: track.name, + } + } +} diff --git a/src/model/mod.rs b/src/model/mod.rs index 7470bed..89ad012 100644 --- a/src/model/mod.rs +++ b/src/model/mod.rs @@ -893,6 +893,16 @@ pub struct PlaylistItem { pub video_count: Option, } +/// 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 */