File tree Expand file tree Collapse file tree 3 files changed +58
-0
lines changed
Expand file tree Collapse file tree 3 files changed +58
-0
lines changed Original file line number Diff line number Diff line change 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+ } ) ;
Original file line number Diff line number Diff line change 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 = / ^ ( D i s t r o ? K i d | \d + R e c o r d s D K \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+ }
Original file line number Diff line number Diff line change 11import { detectLanguageAndScript } from '@/harmonizer/language_script.ts' ;
22import { mergeRelease } from '@/harmonizer/merge.ts' ;
3+ import { cleanupBogusReleaseLabels } from '@/harmonizer/release_label.ts' ;
34import { defaultProviderPreferences , providers } from '@/providers/mod.ts' ;
45import { FeatureQuality } from '@/providers/features.ts' ;
56import { 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 }
You can’t perform that action at this time.
0 commit comments