From f892870de019b8872bf5e8f283341f128284d0ef Mon Sep 17 00:00:00 2001 From: geroyche Date: Tue, 18 May 2021 00:55:36 +0200 Subject: [PATCH] strip b-side title --- js/export.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/js/export.js b/js/export.js index d816930..5def2f7 100644 --- a/js/export.js +++ b/js/export.js @@ -158,6 +158,8 @@ var adedArtistCount = 0; //How many artists are in the user's collection in total? var totalArtists = 0; +//regex that checks if a release might be a two-track vinyl single +var singleTitleRegex = new RegExp(/^([^\/]*)\s\/\s[^\/]*$/); function releaseObject(title, artistName, year) { this.title = title; @@ -536,6 +538,7 @@ function searchReleaseOnSpotify(release) { if (rTitle) { rTitle = stripSingleQuotes(rTitle); + rTitle = stripBSide(rTitle); for (var i = 0; i < formatSuffixes.length; i++) { // ensure there is a leading space, so that potential acronym titles ("W.E.L.P.") do not get filtered out // this also prevents issues with releases such as "L.P." by "The Rembrandts" @@ -734,6 +737,16 @@ function saveAlbumTracks(tracks) { }); } +/** checks if the release is most likely a single, if so, it returns only the a side title */ +function stripBSide(string) { + var couldBeASingle = singleTitleRegex.test(string); + if (couldBeASingle === false) { + return string; + } + var strippedString = singleTitleRegex.exec(string)[1].trim(); + return strippedString; +} + /** strips single quotes because Spotify's search cannot consistently handle them */ function stripSingleQuotes(string) { var strippedString = string.replace(/(\w)('\w')(\w)/g, '$1 $2 $3'); // Twists'n'Turns => Twists 'n' Turns;