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
|
@ -71,19 +71,32 @@ module.exports.lookupId = function(id) {
|
|||
|
||||
module.exports.search = function(data) {
|
||||
var deferred = Q.defer();
|
||||
var query;
|
||||
var query, album;
|
||||
var type = data.type;
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
var path = "/search?q=" + encodeURIComponent(query) + "&type=" + type + "&client_id=" + credentials.key;
|
||||
request.get(apiRoot + path, function(res) {
|
||||
if (!res.body.data[0]) {
|
||||
deferred.resolve({service: "beats"});
|
||||
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: "beats"});
|
||||
}
|
||||
} else {
|
||||
module.exports.lookupId(res.body.data[0].id).then(deferred.resolve);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue