Skip to content

Commit

Permalink
improved string matching for track search. Now matches also when punc…
Browse files Browse the repository at this point in the history
…tuation differs.

i.e. "Hey Maria - Cid Rim Remix" vs. "Hey Maria (Cid Rim Remix)"
  • Loading branch information
crohrer committed May 7, 2017
1 parent 733e2b9 commit 902e735
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion spotifySearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function sendSearchRequest(track, timeOut){
}

result.tracks.items.some(function(item){ // iterate all items and break on success (return true)
var titleMatches = item.name.toUpperCase() == track.title,
var titleMatches = cleanString(item.name.toUpperCase()) === cleanString(track.title),
isAlreadyInPlaylist = spotifyPlaylist.tracks.indexOf(item.uri) > -1,
artistMatches = item.artists.some(function(artist){
return (track.artist.indexOf(artist.name.toUpperCase()) > -1);
Expand All @@ -86,6 +86,10 @@ function sendSearchRequest(track, timeOut){
}
}

function cleanString(string){
return string.replace(/[\-\(\)\.]/g, '').replace(' ', ' ');
}

module.exports = {
searchTracks: searchTracks
};

0 comments on commit 902e735

Please sign in to comment.