Skip to content
Open
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
13 changes: 13 additions & 0 deletions js/export.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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;
Expand Down