From 09fd264cf2746d879f9009f34831d2aed7c58507 Mon Sep 17 00:00:00 2001 From: Philipp Wolfer Date: Mon, 12 Jan 2026 08:32:13 +0100 Subject: [PATCH] fix(Tidal): handle duplicate album artists The existing code returned all matching entries from included items, but Tidal API sometimes returns duplicates. Also the included items not necessarily reflect the same order as the relationships. --- providers/Tidal/__snapshots__/mod.test.ts.snap | 12 ++++++------ providers/Tidal/v2/lookup.ts | 16 +++++++++++++--- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/providers/Tidal/__snapshots__/mod.test.ts.snap b/providers/Tidal/__snapshots__/mod.test.ts.snap index a8af2770..bfc2b098 100644 --- a/providers/Tidal/__snapshots__/mod.test.ts.snap +++ b/providers/Tidal/__snapshots__/mod.test.ts.snap @@ -442,26 +442,26 @@ snapshot[`Tidal provider > release lookup > single by two artists (v2 API) 1`] = { artists: [ { - creditedName: "Bruno Mars", + creditedName: "Lady Gaga", externalIds: [ { - id: "3658521", + id: "3534754", provider: "tidal", type: "artist", }, ], - name: "Bruno Mars", + name: "Lady Gaga", }, { - creditedName: "Lady Gaga", + creditedName: "Bruno Mars", externalIds: [ { - id: "3534754", + id: "3658521", provider: "tidal", type: "artist", }, ], - name: "Lady Gaga", + name: "Bruno Mars", }, ], copyright: "© 2024 Interscope Records", diff --git a/providers/Tidal/v2/lookup.ts b/providers/Tidal/v2/lookup.ts index 8f9a5077..79f085a7 100644 --- a/providers/Tidal/v2/lookup.ts +++ b/providers/Tidal/v2/lookup.ts @@ -349,10 +349,20 @@ export class TidalV2ReleaseLookup extends ReleaseApiLookup item.id)); + if (!targetRels) { + return []; + } + const relatedIds = new Set(targetRels.data?.map((item) => item.id)); - return rawRelease.included - .filter((resource) => resource.type === resourceType && relatedIds.has(resource.id)) as T[]; + const items = new Map(); + rawRelease.included.forEach((resource) => { + if (resource.type === resourceType && relatedIds.has(resource.id)) { + items.set(resource.id, resource as T); + } + }); + // Rely on the target relationship to get the correct number and order of related + // items. Consider the case that an item was not actually returned in the includes. + return targetRels.data.map((rel) => items.get(rel.id) || { id: rel.id } as T); } private constructReleaseUrlFromRelease(release: ReleaseResource): URL {