feat: add YtEntity trait to YouTubeItem and MusicItem

This commit is contained in:
ThetaDev 2024-08-08 03:22:04 +02:00
parent 97fb0578b5
commit 114a86a382
No known key found for this signature in database
GPG key ID: E319D3C5148D65B6

View file

@ -227,50 +227,16 @@ macro_rules! yt_entity_owner_music {
}
fn channel_name(&self) -> Option<&str> {
self.artists.first().map(|a| a.name.as_str())
if self.by_va {
Some(crate::util::VARIOUS_ARTISTS)
} else {
self.artists.first().map(|a| a.name.as_str())
}
}
}
};
}
/*
impl YtEntity for VideoPlayer {
fn id(&self) -> &str {
&self.details.id
}
fn name(&self) -> &str {
&self.details.name
}
fn channel_id(&self) -> Option<&str> {
Some(&self.details.channel_id)
}
fn channel_name(&self) -> Option<&str> {
self.details.channel_name.as_deref()
}
}
impl YtEntity for VideoPlayerDetails {
fn id(&self) -> &str {
&self.channel_id
}
fn name(&self) -> &str {
&self.name
}
fn channel_id(&self) -> Option<&str> {
Some(&self.channel_id)
}
fn channel_name(&self) -> Option<&str> {
self.channel_name.as_deref()
}
}
*/
impl<T> YtEntity for Channel<T> {
fn id(&self) -> &str {
&self.id
@ -289,6 +255,78 @@ impl<T> YtEntity for Channel<T> {
}
}
impl YtEntity for YouTubeItem {
fn id(&self) -> &str {
match self {
YouTubeItem::Video(v) => &v.id,
YouTubeItem::Playlist(p) => &p.id,
YouTubeItem::Channel(c) => &c.id,
}
}
fn name(&self) -> &str {
match self {
YouTubeItem::Video(v) => &v.name,
YouTubeItem::Playlist(p) => &p.name,
YouTubeItem::Channel(c) => &c.name,
}
}
fn channel_id(&self) -> Option<&str> {
match self {
YouTubeItem::Video(v) => v.channel_id(),
YouTubeItem::Playlist(p) => p.channel_id(),
YouTubeItem::Channel(_) => None,
}
}
fn channel_name(&self) -> Option<&str> {
match self {
YouTubeItem::Video(v) => v.channel_name(),
YouTubeItem::Playlist(p) => p.channel_name(),
YouTubeItem::Channel(_) => None,
}
}
}
impl YtEntity for MusicItem {
fn id(&self) -> &str {
match self {
MusicItem::Track(t) => &t.id,
MusicItem::Album(b) => &b.id,
MusicItem::Artist(a) => &a.id,
MusicItem::Playlist(p) => &p.id,
}
}
fn name(&self) -> &str {
match self {
MusicItem::Track(t) => &t.name,
MusicItem::Album(b) => &b.name,
MusicItem::Artist(a) => &a.name,
MusicItem::Playlist(p) => &p.name,
}
}
fn channel_id(&self) -> Option<&str> {
match self {
MusicItem::Track(t) => t.channel_id(),
MusicItem::Album(b) => b.channel_id(),
MusicItem::Artist(_) => None,
MusicItem::Playlist(p) => p.channel_id(),
}
}
fn channel_name(&self) -> Option<&str> {
match self {
MusicItem::Track(t) => t.channel_name(),
MusicItem::Album(b) => b.channel_name(),
MusicItem::Artist(_) => None,
MusicItem::Playlist(p) => p.channel_id(),
}
}
}
yt_entity_owner_opt! {Playlist}
yt_entity! {ChannelId}
yt_entity_owner! {VideoDetails}