Skip to content

Commit 7378d71

Browse files
fix artist page missing album aggregation
Agent-Logs-Url: https://github.com/DanTheMan827/monochrome/sessions/8437a3f1-f7de-49d3-af64-b279ee108459 Co-authored-by: DanTheMan827 <790119+DanTheMan827@users.noreply.github.com>
1 parent cfc4fa5 commit 7378d71

1 file changed

Lines changed: 35 additions & 5 deletions

File tree

js/api.js

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,6 +1157,23 @@ export class LosslessAPI {
11571157
};
11581158

11591159
if (!options.lightweight) {
1160+
try {
1161+
// v2 /artist?id can return a partial album relationship set; merge with
1162+
// the dedicated releases route to avoid dropping albums on artist pages.
1163+
const releasesResponse = await this.fetchWithRetry(`/artist/?f=${artistId}&skip_tracks=true`);
1164+
const releasesJson = await releasesResponse.json();
1165+
const releasesData = releasesJson.data || releasesJson;
1166+
const releaseItems = releasesData?.albums?.items || [];
1167+
for (const entry of releaseItems) {
1168+
const release = entry?.item || entry;
1169+
if (release?.id) {
1170+
albumMap.set(release.id, this.prepareAlbum(release));
1171+
}
1172+
}
1173+
} catch (e) {
1174+
console.warn('Failed to fetch additional artist releases:', e);
1175+
}
1176+
11601177
try {
11611178
const videoSearch = await this.searchVideos(artist.name);
11621179
if (videoSearch && videoSearch.items) {
@@ -1171,18 +1188,31 @@ export class LosslessAPI {
11711188
}
11721189
}
11731190

1174-
const rawReleases = Array.from(albumMap.values()).filter(matchesArtistId);
1191+
const topTracksPool = Array.from(trackMap.values()).filter(matchesArtistId);
1192+
for (const track of topTracksPool) {
1193+
if (!track?.album?.id || albumMap.has(track.album.id)) continue;
1194+
albumMap.set(
1195+
track.album.id,
1196+
this.prepareAlbum({
1197+
...track.album,
1198+
artist: track.artist || track.album.artist,
1199+
artists: track.artists?.length ? track.artists : track.album.artists,
1200+
})
1201+
);
1202+
}
1203+
1204+
const topTrackAlbumIds = new Set(topTracksPool.map((track) => Number(track?.album?.id)).filter(Boolean));
1205+
const rawReleases = Array.from(albumMap.values()).filter(
1206+
(album) => matchesArtistId(album) || topTrackAlbumIds.has(Number(album?.id))
1207+
);
11751208
const allReleases = this.deduplicateAlbums(rawReleases).sort(
11761209
(a, b) => new Date(b.releaseDate || 0) - new Date(a.releaseDate || 0)
11771210
);
11781211

11791212
const eps = allReleases.filter((a) => a.type === 'EP' || a.type === 'SINGLE');
11801213
const albums = allReleases.filter((a) => !eps.includes(a));
11811214

1182-
const topTracks = Array.from(trackMap.values())
1183-
.filter(matchesArtistId)
1184-
.sort((a, b) => (b.popularity || 0) - (a.popularity || 0))
1185-
.slice(0, 15);
1215+
const topTracks = topTracksPool.sort((a, b) => (b.popularity || 0) - (a.popularity || 0)).slice(0, 15);
11861216

11871217
const videos = Array.from(videoMap.values()).sort(
11881218
(a, b) => new Date(b.releaseDate || 0) - new Date(a.releaseDate || 0)

0 commit comments

Comments
 (0)