feat: add original album track count, fix fetching albums with more than 200 tracks

This commit is contained in:
ThetaDev 2025-02-25 22:16:14 +01:00
parent 83f8652776
commit 544782f8de
Signed by: ThetaDev
GPG key ID: E319D3C5148D65B6
18 changed files with 3870 additions and 5 deletions

View file

@ -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,
},

View file

@ -43,6 +43,7 @@ MusicAlbum(
album_type: single,
year: Some(2020),
by_va: false,
track_count: 1,
tracks: [
TrackItem(
id: "XX0epju-YvY",

View file

@ -43,6 +43,7 @@ MusicAlbum(
album_type: album,
year: Some(2015),
by_va: false,
track_count: 11,
tracks: [
TrackItem(
id: "YQHsXMglC9A",

View file

@ -39,6 +39,7 @@ MusicAlbum(
album_type: album,
year: Some(2016),
by_va: false,
track_count: 18,
tracks: [
TrackItem(
id: "g0iRiJ_ck48",

View file

@ -43,6 +43,7 @@ MusicAlbum(
album_type: single,
year: Some(2020),
by_va: false,
track_count: 1,
tracks: [
TrackItem(
id: "XX0epju-YvY",

View file

@ -34,6 +34,7 @@ MusicAlbum(
album_type: album,
year: Some(2019),
by_va: true,
track_count: 18,
tracks: [
TrackItem(
id: "JWeJHN5P-E8",

View file

@ -34,6 +34,7 @@ MusicAlbum(
album_type: single,
year: Some(2022),
by_va: true,
track_count: 6,
tracks: [
TrackItem(
id: "8IqLxg0GqXc",

View file

@ -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

View file

@ -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

View file

@ -18,6 +18,7 @@ MusicAlbum(
album_type: ep,
year: Some(2016),
by_va: false,
track_count: 5,
tracks: [
TrackItem(
id: "aGd3VKSOTxY",

View file

@ -13,6 +13,7 @@ MusicAlbum(
album_type: album,
year: Some(2024),
by_va: true,
track_count: 14,
tracks: [
TrackItem(
id: "ilNEztApdjI",

View file

@ -26,6 +26,7 @@ MusicAlbum(
album_type: single,
year: None,
by_va: false,
track_count: 1,
tracks: [
TrackItem(
id: "1Sz3lUVGBSM",

View file

@ -36,6 +36,7 @@ MusicAlbum(
album_type: album,
year: Some(2011),
by_va: false,
track_count: 15,
tracks: [
TrackItem(
id: "js0moD0CIRQ",

View file

@ -22,6 +22,7 @@ MusicAlbum(
album_type: show,
year: Some(2015),
by_va: false,
track_count: 27,
tracks: [
TrackItem(
id: "ZIjGPc6vG0Y",

View file

@ -22,6 +22,7 @@ MusicAlbum(
album_type: single,
year: Some(2020),
by_va: false,
track_count: 1,
tracks: [
TrackItem(
id: "VU6lEv0PKAo",

View file

@ -26,6 +26,7 @@ MusicAlbum(
album_type: album,
year: Some(2019),
by_va: false,
track_count: 18,
tracks: [
TrackItem(
id: "R3VIKRtzAdE",

View file

@ -13,6 +13,7 @@ MusicAlbum(
album_type: single,
year: Some(2022),
by_va: true,
track_count: 6,
tracks: [
TrackItem(
id: "Tzai7JXo45w",