Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: edgecase/spotbox
...
head fork: edgecase/spotbox
compare: a6ce957bd7
  • 3 commits
  • 2 files changed
  • 0 commit comments
  • 1 contributor
View
51 app/lib/apis/acoustid_api.js
@@ -68,7 +68,7 @@ function buildRecordingTracks(recording) {
album: {
name: group.title,
id: group.id,
- released: group.releases[0].date.year
+ released: (group.releases[0].date || {}).year
}
};
});
@@ -80,6 +80,20 @@ function findBestResult(results) {
})[0];
};
+function scoreMatch(string, part) {
+ // TODO: This should match only whole words, not parts of words
+ // ie: 'if' should match 'if', but not 'infamous'
+ // TODO: If this changes, the split needs to change
+ var points = 0;
+ if (part.length >= 3) {
+ // TODO: should be something like ^||\s part $||\s
+ if (string.match(part)) {
+ points += Math.pow(part.length, 2);
+ };
+ }
+ return points;
+};
+
var Acoustid = function() {};
@@ -145,22 +159,27 @@ Acoustid.bestMatchLookup = function(acoustidId, sourceTrack, hollaback) {
var filteredTracks = underscore.filter(tracks, function(track) {
return track.artists && track.artists.length && track.length && track.name;
});
- if (sourceTrack.name) {
- var orderedTracks = underscore.sortBy(filteredTracks, function(track) {
- var parts = sourceTrack.name.split(/\s/);
- return -underscore.reduce(parts, function(memo, part) {
- if (part.length >= 3) {
- if (track.name.match(part)) {
- memo += part.length;
- };
- }
- return memo;
+ var orderedTracks = underscore.sortBy(filteredTracks, function(track) {
+ var points = 0;
+ var nameParts = sourceTrack.name.split(/\s/);
+ var artistParts = underscore.map(sourceTrack.artists, function(artist) {
+ artist.name.split(/\s/)
+ }).join(" ");
+ points += underscore.reduce(nameParts, function(memo, part) {
+ return memo + scoreMatch(track.name, part);;
+ }, 0);
+ points += underscore.reduce(artistParts, function(artistsPoints, part) {
+ return artistsPoints + underscore.reduce(track.artists, function(artistPoints, artist) {
+ return artistPoints + scoreMatch(artist.name, part);
}, 0);
- });
- hollaback(null, orderedTracks[0]);
- } else {
- hollaback(null, filteredTracks[0]);
- }
+ }, 0);
+ points -= Math.abs(sourceTrack.length - track.length);
+ if (track.year) {
+ points += 5;
+ }
+ return -points;
+ });
+ hollaback(null, orderedTracks[0]);
});
};
View
7 app/lib/application_interfaces/itunes.js
@@ -8,7 +8,7 @@ var RateLimiter = require(path.join(app.root, "app", "lib", "rate_limiter"));
var Applescript = require(path.join(app.root, "app", "lib", "applescript"));
var AcoustidApi = require(path.join(app.root, "app", "lib", "apis", "acoustid_api"));
-var rateLimiter = new RateLimiter(1000.0 / 3); // 3 calls per second
+var rateLimiter = new RateLimiter(1000.0 / 3);
var pollingId = null;
@@ -205,7 +205,10 @@ Itunes.search = function(searchString, hollaback) {
};
Itunes.retag = function(track, hollaback) {
- rateLimiter.queue(function() { retag(track, hollaback)});
+ // itunes gots 99 problems, and this is one of 'em.
+ setTimeout(function() {
+ rateLimiter.queue(function() { retag(track, hollaback); });
+ }, 100);
};
Itunes.import = function(unixPath, hollaback) {

No commit comments for this range

Something went wrong with that request. Please try again.