A module for cleaning up artist, album, and song names.
Installation
npm i metadata-filter
Usage
Single filter functions
You can call filter functions for basic, one-line filter functionality. These filter functions are intended to be used on a single field, such as an artist, album, or track.
However, it is possible (not officially supported) to use some of these on combined fields ("Artist - Song", "Artist - Album"), as in the third example below.
const MetadataFilter = require('metadata-filter');
console.log(MetadataFilter.removeRemastered('Jane Doe (Remastered)')); // Jane Doe
console.log(MetadataFilter.removeVersion('Get Lucky (Album Version)')); // Get Lucky
console.log(
MetadataFilter.youtube(
'Car Bomb - Scattered Sprites (Official Music Video)'
)
); // Car Bomb - Scattered Sprites
See src/functions.ts for more details.
Multiple filters
You can also to use multiple filters on a string at once by creating a
MetadataFilter
object which combines multiple functions from above,
or by using one of the pre-existing filter objects.
First, create a filter set. This is a set of rules for artists, albums, tracks, and albumArtists.
const filterSet = {
track: [
MetadataFilter.removeRemastered,
MetadataFilter.fixTrackSuffix,
MetadataFilter.removeLive,
],
album: [
MetadataFilter.removeRemastered,
MetadataFilter.fixTrackSuffix,
MetadataFilter.removeLive,
],
};
Then, construct a MetadataFilter using this filter set.
const filter = MetadataFilter.createFilter(filterSet);
console.log(filter.filterField('album', 'Nevermind (Remastered)')); // Nevermind
console.log(filter.filterField('track', 'In Bloom - Nevermind Version')); // In Bloom
Predefined filters
There are also predefined filters available for easy access. For example,
the above filter set can be acquired using getSpotifyFilter()
:
const filter = MetadataFilter.getSpotifyFilter();
See src/filters.ts for more details.
Extending filters
Finally, you can take existing MetadataFilter objects and extend them with another filter.
This is done by providing the .extend()
method with another MetadataFilter object.
const filter = MetadataFilter.getSpotifyFilter();
filter.extend(MetadataFilter.getAmazonFilter());
// This would also work: filter.extend(MetadataFilter.createFilter(filterSet));
console.log(
filter.filterField('track', 'Seasons in the Abyss (Album Version)')
); // Seasons in the Abyss
As an alternative, you can use the .append()
method to apply a filter set to
the existing MetadataFilter.
const filter = MetadataFilter.createFilter({ track: filterTrack });
filter.append({ artist: filterArtist });
Since these methods return a MetadataFilter instance, you can chain method calls.
const filter = MetadataFilter.createFilter({ track: filterTrack }).append({
artist: filterArtist,
});
Development
# Install dev dependencies
> npm install
# Build the dist file
> npm run build
# Lint source files
> npm run lint
# Run tests
> npm test
# Run tests with a coverage report
> npm run test-with-coverage
License
Licensed under the MIT License.