Skip to content

Commit

Permalink
Remove additional arists filter (#351)
Browse files Browse the repository at this point in the history
  • Loading branch information
inverse authored Jun 20, 2024
1 parent 451eb33 commit cc1c8a3
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
YOUTUBE_TRACK_FILTER_RULES,
VARIOUS_ARTISTS_FILTER_RULES,
FilterRule,
ADDITIONAL_ARTISTS_FILTER_RULES,
} from './rules';

const escapeHtmlEntityMap: Record<string, RegExp> = {
Expand Down Expand Up @@ -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.
*
Expand Down
6 changes: 6 additions & 0 deletions src/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = [
Expand Down Expand Up @@ -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: '' },
];
12 changes: 12 additions & 0 deletions test/fixtures/functions/remove-additional-artists.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
5 changes: 5 additions & 0 deletions test/fixtures/functions/remove-feature.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
]
2 changes: 2 additions & 0 deletions test/functions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
removeVersion,
removeParody,
removeFeature,
removeAdditionalArtists,
youtube,
fixVariousArtists,
replaceSmartQuotes,
Expand All @@ -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,
};
Expand Down

0 comments on commit cc1c8a3

Please sign in to comment.