Fix google second search

This commit is contained in:
Jonathan Cremin 2014-12-05 17:40:35 +00:00
parent d48824ab49
commit c8eb31116c

View file

@ -26,7 +26,7 @@ module.exports.lookupId = function(id, type, next) {
var deferred = Q.defer(); var deferred = Q.defer();
ready.promise.then(function() { ready.promise.then(function() {
if (type == "album") { if (type == "album") {
pm.getAlbum(id, true, function(album) { pm.getAlbum(id, false, function(album) {
deferred.resolve({ deferred.resolve({
service: "googleplaymusic", service: "googleplaymusic",
type: "album", type: "album",
@ -39,6 +39,8 @@ module.exports.lookupId = function(id, type, next) {
name: album.artist name: album.artist
} }
}); });
}, function(error) {
deferred.reject(error);
}); });
} else if (type == "track") { } else if (type == "track") {
pm.getAllAccessTrack(id, function(track) { pm.getAllAccessTrack(id, function(track) {
@ -57,6 +59,8 @@ module.exports.lookupId = function(id, type, next) {
name: track.artist name: track.artist
} }
}); });
}, function(error) {
deferred.reject(error);
}); });
} }
}); });
@ -77,8 +81,8 @@ module.exports.search = function(data) {
album = data.album.name; album = data.album.name;
} }
pm.search(query, 5, function(data) { pm.search(query, 5, function(result) {
if (!data.entries) { if (!result.entries) {
var matches = album.match(/^[^\(\[]+/); var matches = album.match(/^[^\(\[]+/);
if (matches[0]) { if (matches[0]) {
var cleanedData = JSON.parse(JSON.stringify(data)); var cleanedData = JSON.parse(JSON.stringify(data));
@ -93,7 +97,7 @@ module.exports.search = function(data) {
} }
return; return;
} }
var result = data.entries.filter(function(result) { var result = result.entries.filter(function(result) {
return result[type]; return result[type];
}).sort(function(a, b) { // sort by match score }).sort(function(a, b) { // sort by match score
return a.score < b.score; return a.score < b.score;