feat: add artist_id field for albums
This commit is contained in:
parent
9e4787f501
commit
0453a928bc
16 changed files with 260 additions and 1038 deletions
|
|
@ -10,7 +10,7 @@ use crate::{
|
|||
use super::{
|
||||
response::{
|
||||
self,
|
||||
music_item::{map_album_type, map_artists, MusicListMapper},
|
||||
music_item::{map_album_type, map_artist_id, map_artists, MusicListMapper},
|
||||
},
|
||||
ClientType, MapResponse, QBrowse, RustyPipeQuery,
|
||||
};
|
||||
|
|
@ -274,17 +274,23 @@ impl MapResponse<MusicAlbum> for response::MusicPlaylist {
|
|||
"no sectionListRenderer content",
|
||||
)))?;
|
||||
|
||||
let playlist_id = header.menu.and_then(|mut menu| {
|
||||
menu.menu_renderer
|
||||
.top_level_buttons
|
||||
.try_swap_remove(0)
|
||||
.map(|btn| {
|
||||
btn.button_renderer
|
||||
.navigation_endpoint
|
||||
.watch_playlist_endpoint
|
||||
.playlist_id
|
||||
})
|
||||
});
|
||||
let (artist_id, playlist_id) = header
|
||||
.menu
|
||||
.map(|mut menu| {
|
||||
(
|
||||
map_artist_id(menu.menu_renderer.items),
|
||||
menu.menu_renderer
|
||||
.top_level_buttons
|
||||
.try_swap_remove(0)
|
||||
.map(|btn| {
|
||||
btn.button_renderer
|
||||
.navigation_endpoint
|
||||
.watch_playlist_endpoint
|
||||
.playlist_id
|
||||
}),
|
||||
)
|
||||
})
|
||||
.unwrap_or_default();
|
||||
|
||||
let mut subtitle_split = header.subtitle.split(util::DOT_SEPARATOR);
|
||||
let year_txt = subtitle_split.try_swap_remove(2).map(|cmp| cmp.to_string());
|
||||
|
|
@ -326,6 +332,7 @@ impl MapResponse<MusicAlbum> for response::MusicPlaylist {
|
|||
name: header.title,
|
||||
cover: header.thumbnail.into(),
|
||||
artists,
|
||||
artist_id,
|
||||
description: header.description,
|
||||
album_type,
|
||||
year,
|
||||
|
|
|
|||
|
|
@ -620,7 +620,7 @@ impl MusicListMapper {
|
|||
}
|
||||
|
||||
// Extract artist id from dropdown menu
|
||||
let artist_id = map_artist_id(item.menu, artists.first());
|
||||
let artist_id = map_artist_id_fallback(item.menu, artists.first());
|
||||
|
||||
let track_nr = item.index.and_then(|txt| util::parse_numeric(&txt).ok());
|
||||
|
||||
|
|
@ -946,29 +946,31 @@ pub(crate) fn map_artists(artists_p: Option<TextComponents>) -> (Vec<ArtistId>,
|
|||
(artists, by_va)
|
||||
}
|
||||
|
||||
pub(crate) fn map_artist_id(
|
||||
fn map_artist_id_fallback(
|
||||
menu: Option<MusicItemMenu>,
|
||||
fallback_artist: Option<&ArtistId>,
|
||||
) -> Option<String> {
|
||||
menu.and_then(|m| {
|
||||
m.menu_renderer.items.into_iter().find_map(|i| {
|
||||
let ep = i
|
||||
.menu_navigation_item_renderer
|
||||
.navigation_endpoint
|
||||
.browse_endpoint;
|
||||
ep.and_then(|ep| {
|
||||
ep.browse_endpoint_context_supported_configs
|
||||
.and_then(|cfg| {
|
||||
if cfg.browse_endpoint_context_music_config.page_type == PageType::Artist {
|
||||
Some(ep.browse_id)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
})
|
||||
menu.and_then(|m| map_artist_id(m.menu_renderer.items))
|
||||
.or_else(|| fallback_artist.and_then(|a| a.id.to_owned()))
|
||||
}
|
||||
|
||||
pub(crate) fn map_artist_id(entries: Vec<MusicItemMenuEntry>) -> Option<String> {
|
||||
entries.into_iter().find_map(|i| {
|
||||
let ep = i
|
||||
.menu_navigation_item_renderer
|
||||
.navigation_endpoint
|
||||
.browse_endpoint;
|
||||
ep.and_then(|ep| {
|
||||
ep.browse_endpoint_context_supported_configs
|
||||
.and_then(|cfg| {
|
||||
if cfg.browse_endpoint_context_music_config.page_type == PageType::Artist {
|
||||
Some(ep.browse_id)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
.or_else(|| fallback_artist.and_then(|a| a.id.to_owned()))
|
||||
}
|
||||
|
||||
pub(crate) fn map_album_type(txt: &str, lang: Language) -> AlbumType {
|
||||
|
|
@ -991,7 +993,7 @@ pub(crate) fn map_queue_item(item: QueueMusicItem, lang: Language) -> TrackItem
|
|||
|
||||
let artist_p = subtitle_parts.next();
|
||||
let (artists, _) = map_artists(artist_p);
|
||||
let artist_id = map_artist_id(item.menu, artists.first());
|
||||
let artist_id = map_artist_id_fallback(item.menu, artists.first());
|
||||
|
||||
let subtitle_p2 = subtitle_parts.next();
|
||||
let (album, view_count) = if is_video {
|
||||
|
|
|
|||
|
|
@ -5,7 +5,8 @@ use crate::serializer::text::{Text, TextComponents};
|
|||
|
||||
use super::{
|
||||
music_item::{
|
||||
ItemSection, MusicContentsRenderer, MusicThumbnailRenderer, SingleColumnBrowseResult,
|
||||
ItemSection, MusicContentsRenderer, MusicItemMenuEntry, MusicThumbnailRenderer,
|
||||
SingleColumnBrowseResult,
|
||||
},
|
||||
Tab,
|
||||
};
|
||||
|
|
@ -78,6 +79,8 @@ pub(crate) struct HeaderMenuRenderer {
|
|||
#[serde(default)]
|
||||
#[serde_as(as = "VecSkipError<_>")]
|
||||
pub top_level_buttons: Vec<TopLevelButton>,
|
||||
#[serde_as(as = "VecSkipError<_>")]
|
||||
pub items: Vec<MusicItemMenuEntry>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ MusicAlbum(
|
|||
name: "Adele",
|
||||
),
|
||||
],
|
||||
artist_id: Some("UCRw0x9_EfawqmgDI2IgQLLg"),
|
||||
description: Some("25 is the third studio album by English singer-songwriter Adele, released on 20 November 2015 by XL Recordings and Columbia Records. The album is titled as a reflection of her life and frame of mind at 25 years old and is termed a \"make-up record\". Its lyrical content features themes of Adele \"yearning for her old self, her nostalgia\", and \"melancholia about the passage of time\" according to an interview with the singer by Rolling Stone, as well as themes of motherhood and regret. In contrast to Adele\'s previous works, the production of 25 incorporated the use of electronic elements and creative rhythmic patterns, with elements of 1980s R&B and organs. Like when recording 21, Adele worked with producer and songwriter Paul Epworth and Ryan Tedder, along with new collaborations with Max Martin and Shellback, Bruno Mars, Greg Kurstin, Danger Mouse, the Smeezingtons, Samuel Dixon, and Tobias Jesso Jr.\n25 received generally positive reviews from music critics, who commended its production and Adele\'s vocal performance.\n\nFrom Wikipedia (https://en.wikipedia.org/wiki/25_(Adele_album)) under Creative Commons Attribution CC-BY-SA 3.0 (https://creativecommons.org/licenses/by-sa/3.0/legalcode)"),
|
||||
album_type: Album,
|
||||
year: Some(2015),
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ MusicAlbum(
|
|||
name: "Oonagh",
|
||||
),
|
||||
],
|
||||
artist_id: Some("UC_vmjW5e1xEHhYjY2a0kK1A"),
|
||||
description: None,
|
||||
album_type: Album,
|
||||
year: Some(2016),
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ MusicAlbum(
|
|||
name: "Vanessa Mai",
|
||||
),
|
||||
],
|
||||
artist_id: Some("UCXGYZ-OhdOpPBamHX3K9YRg"),
|
||||
description: None,
|
||||
album_type: Single,
|
||||
year: Some(2020),
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ MusicAlbum(
|
|||
),
|
||||
],
|
||||
artists: [],
|
||||
artist_id: None,
|
||||
description: None,
|
||||
album_type: Album,
|
||||
year: Some(2019),
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ MusicAlbum(
|
|||
),
|
||||
],
|
||||
artists: [],
|
||||
artist_id: None,
|
||||
description: None,
|
||||
album_type: Single,
|
||||
year: Some(2022),
|
||||
|
|
|
|||
|
|
@ -1132,6 +1132,8 @@ pub struct MusicAlbum {
|
|||
pub cover: Vec<Thumbnail>,
|
||||
/// Artists of the album
|
||||
pub artists: Vec<ArtistId>,
|
||||
/// Primary artist ID
|
||||
pub artist_id: Option<String>,
|
||||
/// Album description in plaintext format
|
||||
pub description: Option<String>,
|
||||
/// Album type (Album/Single/EP)
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -13,6 +13,7 @@ MusicAlbum(
|
|||
name: "Madeline Juno",
|
||||
),
|
||||
],
|
||||
artist_id: Some("UCpJyCbFbdTrx0M90HCNBHFQ"),
|
||||
description: None,
|
||||
album_type: Ep,
|
||||
year: Some(2016),
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ MusicAlbum(
|
|||
name: "Oonagh",
|
||||
),
|
||||
],
|
||||
artist_id: Some("UC_vmjW5e1xEHhYjY2a0kK1A"),
|
||||
description: None,
|
||||
album_type: Album,
|
||||
year: Some(2016),
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ MusicAlbum(
|
|||
name: "Kingdom Force",
|
||||
),
|
||||
],
|
||||
artist_id: Some("UCNoyEM0e2A7WlsBmP2w3avg"),
|
||||
description: None,
|
||||
album_type: Show,
|
||||
year: Some(2022),
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ MusicAlbum(
|
|||
name: "Vanessa Mai",
|
||||
),
|
||||
],
|
||||
artist_id: Some("UCXGYZ-OhdOpPBamHX3K9YRg"),
|
||||
description: None,
|
||||
album_type: Single,
|
||||
year: Some(2020),
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ MusicAlbum(
|
|||
name: "13 Reasons Why (Season 3)",
|
||||
cover: "[cover]",
|
||||
artists: [],
|
||||
artist_id: None,
|
||||
description: None,
|
||||
album_type: Album,
|
||||
year: Some(2019),
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ MusicAlbum(
|
|||
name: "<Queendom2> FINAL",
|
||||
cover: "[cover]",
|
||||
artists: [],
|
||||
artist_id: None,
|
||||
description: None,
|
||||
album_type: Single,
|
||||
year: Some(2022),
|
||||
|
|
|
|||
Reference in a new issue