Do a second search without trailing brackets
This commit is contained in:
parent
f7b1fcd53f
commit
8802ffe959
6 changed files with 113 additions and 39 deletions
|
@ -65,8 +65,10 @@ module.exports.search = function(data) {
|
|||
|
||||
if (type == "album") {
|
||||
query = data.artist.name + " " + data.name;
|
||||
album = data.name;
|
||||
} else if (type == "track") {
|
||||
query = data.artist.name + " " + data.album.name + " " + data.name;
|
||||
album = data.album.name;
|
||||
}
|
||||
|
||||
pm.search(query, 5, function(data) {
|
||||
|
@ -80,18 +82,29 @@ module.exports.search = function(data) {
|
|||
return a.score < b.score;
|
||||
}).shift();
|
||||
|
||||
if (!result.album && !result.track) {
|
||||
deferred.resolve({service:"googleplaymusic"});
|
||||
}
|
||||
if (!result) {
|
||||
var matches = album.match(/^[^\(\[]+/);
|
||||
if (matches[0]) {
|
||||
var cleanedData = JSON.parse(JSON.stringify(data));
|
||||
if (type == "album") {
|
||||
cleanedData.name = matches[0].trim();
|
||||
} else if (type == "track") {
|
||||
cleanedData.album = matches[0].trim();
|
||||
}
|
||||
module.exports.search(cleanedData).then(deferred.resolve);
|
||||
} else {
|
||||
deferred.resolve({service: "googleplaymusic"});
|
||||
}
|
||||
} else {
|
||||
var id;
|
||||
if (type == "album") {
|
||||
id = result.album.albumId;
|
||||
} else if (type == "track") {
|
||||
id = result.track.nid;
|
||||
}
|
||||
|
||||
var id;
|
||||
if (type == "album") {
|
||||
id = result.album.albumId;
|
||||
} else if (type == "track") {
|
||||
id = result.track.nid;
|
||||
module.exports.lookupId(id, type).then(deferred.resolve);
|
||||
}
|
||||
|
||||
module.exports.lookupId(id, type).then(deferred.resolve);
|
||||
});
|
||||
return deferred.promise;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue