ytmapi-rs: Wrong value in album, duration if song has multiple artists (with my crappy solution)
lebenoa opened this issue · 3 comments
Hello. I'm apologizing in advance for my bad English since I'm not a native speaker.
During the development I saw that SearchResultSong.duration
return an artist or album name instead of actual duration and this is only happening to song with multiple artists (Example: Sleeping In The Cold Below
by Keith Power & Alan Doyle
AND All Falls Down
by Alan Walker, Noah Cyrus & Digital Farm Animals
)
Solution
ytmapi-rs > src > parse > parse_song_search_result_from_music_shelf_contents
// TODO: Type safety
// TODO: Tests
fn parse_song_search_result_from_music_shelf_contents(
music_shelf_contents: JsonCrawlerBorrowed<'_>,
) -> Result<SearchResultSong> {
let mut mrlir = music_shelf_contents.navigate_pointer("/musicResponsiveListItemRenderer")?;
let title = parse_flex_column_item(&mut mrlir, 0, 0)?;
let mut artist: String = parse_flex_column_item(&mut mrlir, 1, 0)?;
let mut run_idx = 1;
loop {
let cont: String = parse_flex_column_item(&mut mrlir, 1, run_idx)?;
run_idx += 1;
// Since next section seperator is always " • "
// We can check if it's not equal to that instead of ", " and " & "
if cont != " • " {
artist.push_str(&cont);
artist.push_str(&parse_flex_column_item::<String>(&mut mrlir, 1, run_idx)?);
run_idx += 1;
} else {
break;
}
}
let album = parse_flex_column_item(&mut mrlir, 1, run_idx)?;
let duration = parse_flex_column_item(&mut mrlir, 1, run_idx + 2)?;
let plays = parse_flex_column_item(&mut mrlir, 2, 0)?;
let explicit = if mrlir.path_exists(BADGE_LABEL) {
Explicit::IsExplicit
} else {
Explicit::NotExplicit
};
let video_id = mrlir.take_value_pointer(PLAYLIST_ITEM_VIDEO_ID)?;
let thumbnails: Vec<Thumbnail> = mrlir.take_value_pointer(THUMBNAILS)?;
Ok(SearchResultSong {
artist,
thumbnails,
title,
explicit,
plays,
album,
video_id,
duration,
})
}
PSA: I'm happy to create a pull request if you are happy with my solution but since I'm a bad programmer I decided to create an issue instead
G'day there,
Thanks for the report - I'm glad to see somebody using this library!
I can replicate this locally, it's a faulty assumption from my behalf.
Let me see what I can do, there are a couple of things I'd like to investigate before committing to a solution, ie can this be done declaratively and have I made this same mistake elsewhere.
UPDATE: Seems to affect albums search as well. everything else seems OK.
Yes. Thank you for your hard work. Have a good day.