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
|
@ -51,15 +51,16 @@ module.exports.lookupId = function(id, type) {
|
|||
|
||||
module.exports.search = function(data) {
|
||||
var deferred = Q.defer();
|
||||
var query = "";
|
||||
var entity = "";
|
||||
var query, album, entity;
|
||||
var type = data.type;
|
||||
|
||||
if (type == "album") {
|
||||
query = data.artist.name + " " + data.name;
|
||||
album = data.name;
|
||||
entity = "album";
|
||||
} else if (type == "track") {
|
||||
query = data.artist.name + " " + data.album.name + " " + data.name;
|
||||
album = data.album.name;
|
||||
entity = "musicTrack";
|
||||
}
|
||||
|
||||
|
@ -68,7 +69,18 @@ module.exports.search = function(data) {
|
|||
var data = JSON.parse(res.text);
|
||||
|
||||
if (!data.results[0]) {
|
||||
deferred.resolve({service: "itunes"});
|
||||
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: "itunes"});
|
||||
}
|
||||
} else {
|
||||
var result = data.results[0];
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue