Skip to content

Commit

Permalink
Extend Spotify metadata filter
Browse files Browse the repository at this point in the history
Replace "- X Remix" with "(X Remix)".

Closes #1984.
  • Loading branch information
alexesprit committed May 23, 2019
1 parent 5d25543 commit f41156b
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
27 changes: 25 additions & 2 deletions src/core/content/filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,16 @@ class MetadataFilter {
);
}

/**
* Replace "Title - X Remix" suffix with "Title (X Remix)".
* @param {String} text String to be filtered
* @return {String} Filtered string
*/
static fixRemixSuffix(text) {
return MetadataFilter.filterWithFilterSet(
text, MetadataFilter.REMIX_FILTERS
);
}

/**
* "REAL_TITLE : REAL_TILE" -> "REAL_TITLE"
Expand Down Expand Up @@ -376,6 +386,15 @@ class MetadataFilter {
];
}

static get REMIX_FILTERS() {
return [
// "- X Remix" -> "(X Remix)"
{ source: /-\s(.+?)\sRemix$/, target: '($1 Remix)' },
{ source: /-\sRemix$/, target: '(Remix)' },
];
}


/**
* Get simple trim filter object used by default in a Connector object.
* @return {MetadataFilter} Filter object
Expand Down Expand Up @@ -416,10 +435,14 @@ class MetadataFilter {
static getSpotifyFilter() {
return new MetadataFilter({
track: [
MetadataFilter.removeRemastered, MetadataFilter.removeLive
MetadataFilter.removeRemastered,
MetadataFilter.fixRemixSuffix,
MetadataFilter.removeLive,
],
album: [
MetadataFilter.removeRemastered, MetadataFilter.removeLive
MetadataFilter.removeRemastered,
MetadataFilter.fixRemixSuffix,
MetadataFilter.removeLive,
],
});
}
Expand Down
23 changes: 23 additions & 0 deletions tests/core/filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,24 @@ const REMOVE_DOUBLE_TITLE_TEST_DATA = [{
expected: 'this is weird : this is weird : this is weird'
}];

const FIX_REMIX_SUFFIX_TEST_DATA = [{
description: 'should do nothing with correct suffix',
source: 'Track Title (Artist Remix)',
expected: 'Track Title (Artist Remix)'
}, {
description: 'should do nothing with correct suffix',
source: 'Track Title (Remix)',
expected: 'Track Title (Remix)'
}, {
description: 'should replace invalid suffix',
source: 'Track Title - Artist Remix',
expected: 'Track Title (Artist Remix)'
}, {
description: 'should replace invalid suffix',
source: 'Track Title - Remix',
expected: 'Track Title (Remix)'
}];

/**
* Filters data is an array of objects. Each object must contain
* four fields: 'description', 'filter', 'fields' and 'testData'.
Expand Down Expand Up @@ -459,6 +477,11 @@ const FILTERS_DATA = [{
filter: new MetadataFilter({ track: MetadataFilter.removeDoubleTitle }),
fields: ['track'],
testData: REMOVE_DOUBLE_TITLE_TEST_DATA,
}, {
description: 'fixRemixSuffix',
filter: new MetadataFilter({ track: MetadataFilter.fixRemixSuffix }),
fields: ['track'],
testData: FIX_REMIX_SUFFIX_TEST_DATA,
}];

/**
Expand Down

0 comments on commit f41156b

Please sign in to comment.