Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions harmonizer/release_label.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
23 changes: 17 additions & 6 deletions harmonizer/release_label.ts
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
2 changes: 1 addition & 1 deletion lookup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ export class CombinedReleaseLookup {
detectLanguageAndScript(release);
normalizeReleaseISRCs(release);
if (release.labels) {
cleanupBogusReleaseLabels(release.labels);
cleanupBogusReleaseLabels(release.labels, release.artists);
}

return release;
Expand Down