Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove additional arists filter #351

Merged
merged 1 commit into from
Jun 20, 2024
Merged
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
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