feat: assorted music fixes

This commit is contained in:
Cory Dransfeldt 2023-10-09 12:27:18 -07:00
parent 1c46e9b3e2
commit 521bd5d879
3 changed files with 78 additions and 32 deletions

41
src/utils/media.js Normal file
View file

@ -0,0 +1,41 @@
const artistAliases = require('../_data/json/artist-aliases.json')
module.exports = {
/**
* Accepts a string representing an artist name, checks to see if said artist name
* exists in an artist alias group of shape string[]. If so, replaces the provided
* artist name with the canonical artist name.
*
* @name aliasArtist
* @param {string} artist
* @returns {string}
*/
aliasArtist: (artist) => {
const aliased = artistAliases.aliases.find((alias) => alias.aliases.includes(artist))
if (aliased) artist = aliased.artist
return artist
},
/**
* Accepts a media name represented as a string (album or song name) and replaces
* matches in the `denyList` with an empty string before returning the result.
*
* @name sanitizeMedia
* @param {string} media
* @returns {string}
*/
sanitizeMedia: (media) => {
const denyList =
/-\s*(?:single|ep)\s*|(\[|\()(Deluxe Edition|Special Edition|Remastered|Full Dynamic Range Edition|Anniversary Edition|Expanded Edition)(\]|\))/gi
return media.replace(denyList, '').trim()
},
/**
* Sorts an array of media objects by the number of plays in descending order.
*
* @name sortByPlays
* @param {Array} array - an array of media objects.
* @returns {Array} - a new array sorted by the number of plays in descending order.
*/
sortByPlays: (array) => Object.values(array).sort((a, b) => b.plays - a.plays),
}