fix: support podcast episodes in new videos

This commit is contained in:
ThetaDev 2023-11-13 13:53:29 +01:00
parent a5ec111af4
commit 53a8ec680a
5 changed files with 47180 additions and 20 deletions

View file

@ -112,13 +112,14 @@ mod tests {
#[rstest]
#[case::default("default")]
#[case::default("w_podcasts")]
fn map_music_new_videos(#[case] name: &str) {
let json_path = path!(*TESTFILES / "music_new" / format!("videos_{name}.json"));
let json_file = File::open(json_path).unwrap();
let new_albums: response::MusicNew =
let new_videos: response::MusicNew =
serde_json::from_reader(BufReader::new(json_file)).unwrap();
let map_res: MapResult<Vec<TrackItem>> = new_albums
let map_res: MapResult<Vec<TrackItem>> = new_videos
.map_response("", Language::En, None, None)
.unwrap();

View file

@ -11,7 +11,7 @@ use crate::{
text::{Text, TextComponent, TextComponents},
MapResult,
},
util::{self, dictionary},
util::{self, dictionary, timeago},
};
use super::{
@ -780,10 +780,17 @@ impl MusicListMapper {
.map(|st| map_album_type(st.first_str(), self.lang))
.unwrap_or_default();
let (artists, by_va) = map_artists(subtitle_p2);
let (mut artists, by_va) = map_artists(subtitle_p2);
let artist_id = map_artist_id_fallback(item.menu, artists.first());
// Album artist links may be invisible on the search page, so
// fall back to menu data
if let Some(a1) = artists.first_mut() {
if a1.id.is_none() {
a1.id = artist_id.clone();
}
}
let year =
subtitle_p3.and_then(|st| util::parse_numeric(st.first_str()).ok());
@ -855,23 +862,38 @@ impl MusicListMapper {
match item.navigation_endpoint.music_page() {
Some(music_page) => match music_page.typ {
MusicPageType::Track { vtype } => {
let (artists, by_va, view_count, duration) = if vtype == MusicVideoType::Episode
{
let (artists, by_va) = map_artists(subtitle_p2);
let duration = subtitle_p1.and_then(|s| {
timeago::parse_video_duration_or_warn(
self.lang,
s.first_str(),
&mut self.warnings,
)
});
(artists, by_va, None, duration)
} else {
let (artists, by_va) = map_artists(subtitle_p1);
self.items.push(MusicItem::Track(TrackItem {
id: music_page.id,
name: item.title,
duration: None,
cover: item.thumbnail_renderer.into(),
artist_id: artists.first().and_then(|a| a.id.clone()),
artists,
album: None,
view_count: subtitle_p2.and_then(|c| {
let view_count = subtitle_p2.and_then(|c| {
util::parse_large_numstr_or_warn(
c.first_str(),
self.lang,
&mut self.warnings,
)
}),
});
(artists, by_va, view_count, None)
};
self.items.push(MusicItem::Track(TrackItem {
id: music_page.id,
name: item.title,
duration,
cover: item.thumbnail_renderer.into(),
artist_id: artists.first().and_then(|a| a.id.clone()),
artists,
album: None,
view_count,
is_video: vtype.is_video(),
track_nr: None,
by_va,

File diff suppressed because it is too large Load diff

View file

@ -1389,9 +1389,10 @@ fn music_playlist_cont(#[case] id: &str, rp: RustyPipe) {
assert_gte(track_count, 100, "tracks");
assert_eq!(track_count, playlist.tracks.count.unwrap());
assert_eq!(
assert_gte(
usize::try_from(track_count).unwrap(),
playlist.tracks.items.len()
playlist.tracks.items.len(),
"tracks",
);
}
@ -2263,7 +2264,12 @@ fn music_new_videos(rp: RustyPipe) {
validate::video_id(&video.id).unwrap();
assert!(!video.name.is_empty());
assert!(!video.cover.is_empty(), "got no cover");
assert_gte(video.view_count.unwrap(), 1000, "views");
if let Some(view_count) = video.view_count {
assert_gte(view_count, 1000, "views");
} else {
// Podcast episode: shows duration instead of view count
assert!(video.duration.is_some(), "no view count or duration");
}
assert!(video.is_video);
}
}