From a09d9919556b128177c0be6b6e3137a5b9448e63 Mon Sep 17 00:00:00 2001 From: Eva Date: Wed, 5 Aug 2026 23:27:39 +0200 Subject: [PATCH] feat(lookup): Replace labels matching the artist name with [no label] --- harmonizer/release_label.test.ts | 19 +++++++++++++++++++ harmonizer/release_label.ts | 23 +++++++++++++++++------ lookup.ts | 2 +- 3 files changed, 37 insertions(+), 7 deletions(-) diff --git a/harmonizer/release_label.test.ts b/harmonizer/release_label.test.ts index 7859e7fa..3daa5e76 100644 --- a/harmonizer/release_label.test.ts +++ b/harmonizer/release_label.test.ts @@ -20,6 +20,25 @@ describe('cleanupBogusReleaseLabels', () => { }); }); + it('replaces self-published label matching the artist name with [no label]', () => { + const label: Label = { + name: 'Test Artist', + catalogNumber: '12345', + externalIds: [], + }; + cleanupBogusReleaseLabels([label], [{ name: 'Test Artist' }]); + assertEquals(label, { + ...noLabel, + catalogNumber: '12345', + }); + }); + + it('replaces a label matching the credited artist alias', () => { + const label: Label = { name: 'Test Artist Alias', externalIds: [] }; + cleanupBogusReleaseLabels([label], [{ name: 'Test Artist', creditedName: 'Test Artist Alias' }]); + assertEquals(label, noLabel); + }); + const distroKidPlaceholders = [ 'Distro Kid', // Tidal '123456 Records DK', diff --git a/harmonizer/release_label.ts b/harmonizer/release_label.ts index 407b4839..7f037641 100644 --- a/harmonizer/release_label.ts +++ b/harmonizer/release_label.ts @@ -1,17 +1,28 @@ -import { Label } from '@/harmonizer/types.ts'; +import { ArtistCreditName, Label } from '@/harmonizer/types.ts'; import { noLabel } from '@/musicbrainz/special_entities.ts'; /** Placeholder label names that are used by DistroKid. */ export const DISTRO_KID_PATTERN = /^(Distro ?Kid|\d+ Records DK\d*)$/; +function replaceByNoLabel(label: Label) { + label.name = noLabel.name; + label.mbid = noLabel.mbid; + delete label.externalIds; +} + /** Tries to clean up common cases of release labels which are not considered imprints by MusicBrainz. */ -export function cleanupBogusReleaseLabels(labels: Label[]) { +export function cleanupBogusReleaseLabels(labels: Label[], artists?: ArtistCreditName[]) { + const artistNames = artists?.map(({ name, creditedName }) => creditedName ?? name); + for (const label of labels) { - if (label.name && DISTRO_KID_PATTERN.test(label.name)) { + // Labels are not considered an imprint if the release was self-published. + // Stores sometimes require a label for self-releases and therefore use the artist name + // (https://musicbrainz.org/doc/Style/Unknown_and_untitled/Special_purpose_label#About_auto-releases_or_self-releases) + if (label.name && artistNames?.includes(label.name)) { + replaceByNoLabel(label); + } else if (label.name && DISTRO_KID_PATTERN.test(label.name)) { // DistroKid (https://musicbrainz.org/label/4108147d-f37e-4151-a3e9-d92f0074f1eb) is a distributor - label.name = noLabel.name; - label.mbid = noLabel.mbid; - delete label.externalIds; + replaceByNoLabel(label); } } } diff --git a/lookup.ts b/lookup.ts index b033c768..874dd08b 100644 --- a/lookup.ts +++ b/lookup.ts @@ -306,7 +306,7 @@ export class CombinedReleaseLookup { detectLanguageAndScript(release); normalizeReleaseISRCs(release); if (release.labels) { - cleanupBogusReleaseLabels(release.labels); + cleanupBogusReleaseLabels(release.labels, release.artists); } return release;