Skip to content

Commit 44cf876

Browse files
committed
feat(lookup): Replace DistroKid placeholder labels with [no label]
1 parent b91ff9c commit 44cf876

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

harmonizer/release_label.test.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { DISTRO_KID_PATTERN } from '@/harmonizer/release_label.ts';
2+
import { cleanupBogusReleaseLabels } from '@/harmonizer/release_label.ts';
3+
import type { Label } from '@/harmonizer/types.ts';
4+
import { noLabel } from '@/musicbrainz/special_entities.ts';
5+
import { describe, it } from '@std/testing/bdd';
6+
import { assert } from 'std/assert/assert.ts';
7+
import { assertEquals } from 'std/assert/assert_equals.ts';
8+
9+
describe('cleanupBogusReleaseLabels', () => {
10+
it('replaces DistroKid with [no label]', () => {
11+
const label: Label = {
12+
name: 'DistroKid',
13+
catalogNumber: '12345',
14+
externalIds: [],
15+
};
16+
cleanupBogusReleaseLabels([label]);
17+
assertEquals(label, {
18+
...noLabel,
19+
catalogNumber: '12345',
20+
});
21+
});
22+
23+
const distroKidPlaceholders = [
24+
'Distro Kid', // Tidal
25+
'123456 Records DK',
26+
'1234567 Records DK',
27+
'1234567 Records DK2',
28+
];
29+
30+
for (const label of distroKidPlaceholders) {
31+
it(`detects "${label}" as DistroKid placeholder`, () => {
32+
assert(DISTRO_KID_PATTERN.test(label));
33+
});
34+
}
35+
});

harmonizer/release_label.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { Label } from '@/harmonizer/types.ts';
2+
import { noLabel } from '@/musicbrainz/special_entities.ts';
3+
4+
/** Placeholder label names that are used by DistroKid. */
5+
export const DISTRO_KID_PATTERN = /^(Distro ?Kid|\d+ Records DK\d*)$/;
6+
7+
/** Tries to clean up common cases of release labels which are not considered imprints by MusicBrainz. */
8+
export function cleanupBogusReleaseLabels(labels: Label[]) {
9+
for (const label of labels) {
10+
if (label.name && DISTRO_KID_PATTERN.test(label.name)) {
11+
// DistroKid (https://musicbrainz.org/label/4108147d-f37e-4151-a3e9-d92f0074f1eb) is a distributor
12+
label.name = noLabel.name;
13+
label.mbid = noLabel.mbid;
14+
delete label.externalIds;
15+
}
16+
}
17+
}

lookup.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { detectLanguageAndScript } from '@/harmonizer/language_script.ts';
22
import { mergeRelease } from '@/harmonizer/merge.ts';
3+
import { cleanupBogusReleaseLabels } from '@/harmonizer/release_label.ts';
34
import { defaultProviderPreferences, providers } from '@/providers/mod.ts';
45
import { FeatureQuality } from '@/providers/features.ts';
56
import { LookupError, ProviderError } from '@/utils/errors.ts';
@@ -300,7 +301,12 @@ export class CombinedReleaseLookup {
300301
const release = mergeRelease(releaseMap, providerPreferences);
301302
// Prepend error and warning messages of the combined lookup.
302303
release.info.messages.unshift(...this.messages);
304+
305+
// Provider-independent post-processing of the merged release.
303306
detectLanguageAndScript(release);
307+
if (release.labels) {
308+
cleanupBogusReleaseLabels(release.labels);
309+
}
304310

305311
return release;
306312
}

0 commit comments

Comments
 (0)