feat!: replace TrackItem::is_video attr with TrackType enum; serde lowercase AlbumType enum for consistency

This commit is contained in:
ThetaDev 2024-11-09 02:55:59 +01:00
parent 50010b7b08
commit 044094a4b7
No known key found for this signature in database
GPG key ID: E319D3C5148D65B6
83 changed files with 3455 additions and 2945 deletions

View file

@ -759,7 +759,7 @@ impl MusicListMapper {
artist_id,
album,
view_count,
is_video: vtype.is_video(),
track_type: vtype.into(),
track_nr,
by_va,
}));
@ -829,7 +829,7 @@ impl MusicListMapper {
}));
Ok(Some(MusicItemType::Album))
}
MusicPageType::Playlist => {
MusicPageType::Playlist { is_podcast } => {
// Part 1 may be the "Playlist" label
let (channel_p, tcount_p) = match subtitle_p3 {
Some(_) => (subtitle_p2, subtitle_p3),
@ -855,6 +855,7 @@ impl MusicListMapper {
channel,
track_count,
from_ytm,
is_podcast,
}));
Ok(Some(MusicItemType::Playlist))
}
@ -930,7 +931,7 @@ impl MusicListMapper {
artists,
album: None,
view_count,
is_video: vtype.is_video(),
track_type: vtype.into(),
track_nr: None,
by_va,
}));
@ -1002,7 +1003,7 @@ impl MusicListMapper {
}));
Ok(Some(MusicItemType::Album))
}
MusicPageType::Playlist => {
MusicPageType::Playlist { is_podcast } => {
// When the playlist subtitle has only 1 part, it is a playlist from YT Music
// (featured on the startpage or in genres)
let from_ytm = subtitle_p2
@ -1019,6 +1020,7 @@ impl MusicListMapper {
channel,
track_count: None,
from_ytm,
is_podcast,
}));
Ok(Some(MusicItemType::Playlist))
}
@ -1093,7 +1095,7 @@ impl MusicListMapper {
artists,
album: None,
view_count: None,
is_video: vtype.is_video(),
track_type: vtype.into(),
track_nr: None,
by_va,
}));
@ -1130,14 +1132,14 @@ impl MusicListMapper {
artists,
album,
view_count,
is_video: vtype.is_video(),
track_type: vtype.into(),
track_nr: None,
by_va,
}));
}
Some(MusicItemType::Track)
}
MusicPageType::Playlist => {
MusicPageType::Playlist { is_podcast } => {
let from_ytm = subtitle_p2
.as_ref()
.and_then(|p| p.0.first())
@ -1154,6 +1156,7 @@ impl MusicListMapper {
channel,
track_count,
from_ytm,
is_podcast,
}));
Some(MusicItemType::Playlist)
}
@ -1359,7 +1362,7 @@ pub(crate) fn map_queue_item(item: QueueMusicItem, lang: Language) -> MapResult<
artist_id,
album,
view_count,
is_video,
track_type: MusicVideoType::from_is_video(is_video).into(),
track_nr: None,
by_va,
},

View file

@ -1,7 +1,10 @@
use serde::Deserialize;
use serde_with::{serde_as, DefaultOnError};
use crate::{model::UrlTarget, util};
use crate::{
model::{TrackType, UrlTarget},
util,
};
/// navigation/resolve_url response model
#[derive(Debug, Deserialize)]
@ -179,6 +182,16 @@ impl MusicVideoType {
}
}
impl From<MusicVideoType> for TrackType {
fn from(value: MusicVideoType) -> Self {
match value {
MusicVideoType::Video => Self::Video,
MusicVideoType::Track => Self::Track,
MusicVideoType::Episode => Self::Episode,
}
}
}
#[derive(Default, Debug, Clone, Copy, Deserialize, PartialEq, Eq)]
pub(crate) enum PageType {
#[serde(
@ -225,7 +238,7 @@ impl PageType {
pub(crate) enum MusicPageType {
Artist,
Album,
Playlist,
Playlist { is_podcast: bool },
Track { vtype: MusicVideoType },
User,
None,
@ -236,7 +249,8 @@ impl From<PageType> for MusicPageType {
match t {
PageType::Artist => MusicPageType::Artist,
PageType::Album => MusicPageType::Album,
PageType::Playlist | PageType::Podcast => MusicPageType::Playlist,
PageType::Playlist => MusicPageType::Playlist { is_podcast: false },
PageType::Podcast => MusicPageType::Playlist { is_podcast: true },
PageType::Channel => MusicPageType::User,
PageType::Episode => MusicPageType::Track {
vtype: MusicVideoType::Episode,
@ -310,7 +324,7 @@ impl NavigationEndpoint {
watch_playlist_endpoint,
} => Some(MusicPage {
id: watch_playlist_endpoint.playlist_id,
typ: MusicPageType::Playlist,
typ: MusicPageType::Playlist { is_podcast: false },
}),
}
}