From e072a5316698fd098309b362bba397a2b45829b1 Mon Sep 17 00:00:00 2001 From: Malachi Soord Date: Thu, 20 Jun 2024 20:56:15 +0200 Subject: [PATCH] Remove additional arists filter --- src/functions.ts | 12 ++++++++++++ src/rules.ts | 6 ++++++ .../functions/remove-additional-artists.json | 12 ++++++++++++ test/fixtures/functions/remove-feature.json | 5 +++++ test/functions.spec.ts | 2 ++ 5 files changed, 37 insertions(+) create mode 100644 test/fixtures/functions/remove-additional-artists.json diff --git a/src/functions.ts b/src/functions.ts index bcd9f184..818144cc 100644 --- a/src/functions.ts +++ b/src/functions.ts @@ -12,6 +12,7 @@ import { YOUTUBE_TRACK_FILTER_RULES, VARIOUS_ARTISTS_FILTER_RULES, FilterRule, + ADDITIONAL_ARTISTS_FILTER_RULES, } from './rules'; const escapeHtmlEntityMap: Record = { @@ -135,6 +136,17 @@ export function removeFeature(text: string): string { return filterWithFilterRules(text, FEATURE_FILTER_RULES); } +/** + * Remove "&" and "x"-like strings from the text. + * + * @param text String to be filtered + * + * @return Filtered string + */ +export function removeAdditionalArtists(text: string): string { + return filterWithFilterRules(text, ADDITIONAL_ARTISTS_FILTER_RULES); +} + /** * Remove "Live..."-like strings from the text. * diff --git a/src/rules.ts b/src/rules.ts index 35848230..33773994 100644 --- a/src/rules.ts +++ b/src/rules.ts @@ -28,6 +28,7 @@ export const CLEAN_EXPLICIT_FILTER_RULES: FilterRule[] = [ export const FEATURE_FILTER_RULES: FilterRule[] = [ // [Feat. Artist] or (Feat. Artist) { source: /\s[([]feat. .+[)\]]/i, target: '' }, + { source: /\s(feat. .+)/i, target: '' }, ]; export const LIVE_FILTER_RULES: FilterRule[] = [ @@ -227,3 +228,8 @@ export const YOUTUBE_TRACK_FILTER_RULES: FilterRule[] = [ // Sub Español { source: /sub\s*español/i, target: '' }, ]; + +export const ADDITIONAL_ARTISTS_FILTER_RULES: FilterRule[] = [ + { source: /\s(& .+)/i, target: '' }, + { source: /\s(x .+)/i, target: '' }, +]; diff --git a/test/fixtures/functions/remove-additional-artists.json b/test/fixtures/functions/remove-additional-artists.json new file mode 100644 index 00000000..ddcffd24 --- /dev/null +++ b/test/fixtures/functions/remove-additional-artists.json @@ -0,0 +1,12 @@ +[ + { + "description": "should x artist from suffix", + "funcParameter": "Artist A x Artist B", + "expectedValue": "Artist A" + }, + { + "description": "should & artist from suffix", + "funcParameter": "Artist A & Artist B", + "expectedValue": "Artist A" + } +] diff --git a/test/fixtures/functions/remove-feature.json b/test/fixtures/functions/remove-feature.json index 0d30c659..af2a2031 100644 --- a/test/fixtures/functions/remove-feature.json +++ b/test/fixtures/functions/remove-feature.json @@ -8,5 +8,10 @@ "description": "should remove featured artist from suffix", "funcParameter": "Artist A (feat. Artist B)", "expectedValue": "Artist A" + }, + { + "description": "should remove featured artist from suffix", + "funcParameter": "Artist A feat. Artist B", + "expectedValue": "Artist A" } ] diff --git a/test/functions.spec.ts b/test/functions.spec.ts index 27b42cff..a2b50df4 100644 --- a/test/functions.spec.ts +++ b/test/functions.spec.ts @@ -19,6 +19,7 @@ import { removeVersion, removeParody, removeFeature, + removeAdditionalArtists, youtube, fixVariousArtists, replaceSmartQuotes, @@ -39,6 +40,7 @@ const functionsToTest = { 'remove-version': removeVersion, 'remove-parody': removeParody, 'remove-feature': removeFeature, + 'remove-additional-artists': removeAdditionalArtists, 'replace-smart-quotes': replaceSmartQuotes, youtube: youtube, };