feat: add original album track count, fix fetching albums with more than 200 tracks
This commit is contained in:
parent
83f8652776
commit
544782f8de
18 changed files with 3870 additions and 5 deletions
src
client
music_playlist.rs
snapshots
rustypipe__client__music_playlist__tests__map_music_album_20240228_twoColumns.snaprustypipe__client__music_playlist__tests__map_music_album_description.snaprustypipe__client__music_playlist__tests__map_music_album_one_artist.snaprustypipe__client__music_playlist__tests__map_music_album_single.snaprustypipe__client__music_playlist__tests__map_music_album_unavailable.snaprustypipe__client__music_playlist__tests__map_music_album_various_artists.snap
model
util
tests/snapshots
youtube__music_album_audiobook.snapyoutube__music_album_ep.snapyoutube__music_album_no_artist.snapyoutube__music_album_no_year.snapyoutube__music_album_one_artist.snapyoutube__music_album_show.snapyoutube__music_album_single.snapyoutube__music_album_unavailable.snapyoutube__music_album_various_artists.snap
|
@ -95,11 +95,21 @@ impl RustyPipeQuery {
|
|||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
if !to_replace.is_empty() {
|
||||
let last_tn = album
|
||||
.tracks
|
||||
.last()
|
||||
.and_then(|t| t.track_nr)
|
||||
.unwrap_or_default();
|
||||
if !to_replace.is_empty() || last_tn < album.track_count {
|
||||
tracing::debug!(
|
||||
"fetching album playlist ({} tracks, {} to replace)",
|
||||
album.track_count,
|
||||
to_replace.len()
|
||||
);
|
||||
let mut playlist = self.music_playlist(playlist_id).await?;
|
||||
playlist
|
||||
.tracks
|
||||
.extend_limit(&self, album.tracks.len())
|
||||
.extend_limit(&self, album.track_count.into())
|
||||
.await?;
|
||||
|
||||
for (i, title) in to_replace {
|
||||
|
@ -118,6 +128,18 @@ impl RustyPipeQuery {
|
|||
album.tracks[i].track_type = TrackType::Track;
|
||||
}
|
||||
}
|
||||
|
||||
// Extend the list of album tracks with the ones from the playlist if the playlist returned more tracks
|
||||
// This is the case for albums with more than 200 tracks (e.g. audiobooks)
|
||||
if album.tracks.len() < playlist.tracks.items.len() {
|
||||
let mut tn = last_tn;
|
||||
for mut t in playlist.tracks.items.into_iter().skip(album.tracks.len()) {
|
||||
tn += 1;
|
||||
t.album = album.tracks.first().and_then(|t| t.album.clone());
|
||||
t.track_nr = Some(tn);
|
||||
album.tracks.push(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(album)
|
||||
|
@ -457,6 +479,14 @@ impl MapResponse<MusicAlbum> for response::MusicPlaylist {
|
|||
.unwrap_or_default();
|
||||
let artist_id = artist_id.or_else(|| artists.first().and_then(|a| a.id.clone()));
|
||||
|
||||
let second_subtitle_parts = header
|
||||
.second_subtitle
|
||||
.split(|p| p == DOT_SEPARATOR)
|
||||
.collect::<Vec<_>>();
|
||||
let track_count = second_subtitle_parts
|
||||
.get(usize::from(second_subtitle_parts.len() > 2))
|
||||
.and_then(|txt| util::parse_numeric::<u16>(&txt[0]).ok());
|
||||
|
||||
let mut mapper = MusicListMapper::with_album(
|
||||
ctx.lang,
|
||||
artists.clone(),
|
||||
|
@ -491,6 +521,7 @@ impl MapResponse<MusicAlbum> for response::MusicPlaylist {
|
|||
album_type,
|
||||
year,
|
||||
by_va,
|
||||
track_count: track_count.unwrap_or(tracks_res.c.len() as u16),
|
||||
tracks: tracks_res.c,
|
||||
variants: variants_res.c,
|
||||
},
|
||||
|
|
|
@ -43,6 +43,7 @@ MusicAlbum(
|
|||
album_type: single,
|
||||
year: Some(2020),
|
||||
by_va: false,
|
||||
track_count: 1,
|
||||
tracks: [
|
||||
TrackItem(
|
||||
id: "XX0epju-YvY",
|
||||
|
|
|
@ -43,6 +43,7 @@ MusicAlbum(
|
|||
album_type: album,
|
||||
year: Some(2015),
|
||||
by_va: false,
|
||||
track_count: 11,
|
||||
tracks: [
|
||||
TrackItem(
|
||||
id: "YQHsXMglC9A",
|
||||
|
|
|
@ -39,6 +39,7 @@ MusicAlbum(
|
|||
album_type: album,
|
||||
year: Some(2016),
|
||||
by_va: false,
|
||||
track_count: 18,
|
||||
tracks: [
|
||||
TrackItem(
|
||||
id: "g0iRiJ_ck48",
|
||||
|
|
|
@ -43,6 +43,7 @@ MusicAlbum(
|
|||
album_type: single,
|
||||
year: Some(2020),
|
||||
by_va: false,
|
||||
track_count: 1,
|
||||
tracks: [
|
||||
TrackItem(
|
||||
id: "XX0epju-YvY",
|
||||
|
|
|
@ -34,6 +34,7 @@ MusicAlbum(
|
|||
album_type: album,
|
||||
year: Some(2019),
|
||||
by_va: true,
|
||||
track_count: 18,
|
||||
tracks: [
|
||||
TrackItem(
|
||||
id: "JWeJHN5P-E8",
|
||||
|
|
|
@ -34,6 +34,7 @@ MusicAlbum(
|
|||
album_type: single,
|
||||
year: Some(2022),
|
||||
by_va: true,
|
||||
track_count: 6,
|
||||
tracks: [
|
||||
TrackItem(
|
||||
id: "8IqLxg0GqXc",
|
||||
|
|
|
@ -1234,6 +1234,8 @@ pub struct MusicAlbum {
|
|||
pub year: Option<u16>,
|
||||
/// Is the album by 'Various artists'?
|
||||
pub by_va: bool,
|
||||
/// Number of album tracks
|
||||
pub track_count: u16,
|
||||
/// Album tracks
|
||||
pub tracks: Vec<TrackItem>,
|
||||
/// Album variants
|
||||
|
|
|
@ -245,12 +245,21 @@ mod tests {
|
|||
for _ in 0..4 {
|
||||
cache.get().await.unwrap();
|
||||
}
|
||||
tokio::time::sleep(Duration::from_millis(1000)).await;
|
||||
|
||||
for _ in 0..3 {
|
||||
tokio::time::sleep(Duration::from_millis(1000)).await;
|
||||
{
|
||||
let vd = cache.inner.visitor_data.read().unwrap();
|
||||
if !vd.contains(&v1) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
{
|
||||
let vd = cache.inner.visitor_data.read().unwrap();
|
||||
assert!(!vd.contains(&v1), "first token still present");
|
||||
}
|
||||
|
||||
assert_eq!(cache.get_pot(&v1), None);
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -18,6 +18,7 @@ MusicAlbum(
|
|||
album_type: ep,
|
||||
year: Some(2016),
|
||||
by_va: false,
|
||||
track_count: 5,
|
||||
tracks: [
|
||||
TrackItem(
|
||||
id: "aGd3VKSOTxY",
|
||||
|
|
|
@ -13,6 +13,7 @@ MusicAlbum(
|
|||
album_type: album,
|
||||
year: Some(2024),
|
||||
by_va: true,
|
||||
track_count: 14,
|
||||
tracks: [
|
||||
TrackItem(
|
||||
id: "ilNEztApdjI",
|
||||
|
|
|
@ -26,6 +26,7 @@ MusicAlbum(
|
|||
album_type: single,
|
||||
year: None,
|
||||
by_va: false,
|
||||
track_count: 1,
|
||||
tracks: [
|
||||
TrackItem(
|
||||
id: "1Sz3lUVGBSM",
|
||||
|
|
|
@ -36,6 +36,7 @@ MusicAlbum(
|
|||
album_type: album,
|
||||
year: Some(2011),
|
||||
by_va: false,
|
||||
track_count: 15,
|
||||
tracks: [
|
||||
TrackItem(
|
||||
id: "js0moD0CIRQ",
|
||||
|
|
|
@ -22,6 +22,7 @@ MusicAlbum(
|
|||
album_type: show,
|
||||
year: Some(2015),
|
||||
by_va: false,
|
||||
track_count: 27,
|
||||
tracks: [
|
||||
TrackItem(
|
||||
id: "ZIjGPc6vG0Y",
|
||||
|
|
|
@ -22,6 +22,7 @@ MusicAlbum(
|
|||
album_type: single,
|
||||
year: Some(2020),
|
||||
by_va: false,
|
||||
track_count: 1,
|
||||
tracks: [
|
||||
TrackItem(
|
||||
id: "VU6lEv0PKAo",
|
||||
|
|
|
@ -26,6 +26,7 @@ MusicAlbum(
|
|||
album_type: album,
|
||||
year: Some(2019),
|
||||
by_va: false,
|
||||
track_count: 18,
|
||||
tracks: [
|
||||
TrackItem(
|
||||
id: "R3VIKRtzAdE",
|
||||
|
|
|
@ -13,6 +13,7 @@ MusicAlbum(
|
|||
album_type: single,
|
||||
year: Some(2022),
|
||||
by_va: true,
|
||||
track_count: 6,
|
||||
tracks: [
|
||||
TrackItem(
|
||||
id: "Tzai7JXo45w",
|
||||
|
|
Loading…
Add table
Reference in a new issue