Add suppport for tracks, basic design, minor refactor

This commit is contained in:
Jonathan Cremin 2014-12-03 23:03:34 +00:00
parent e20b3b86c4
commit acb129899d
13 changed files with 267 additions and 77 deletions

View file

@ -11,19 +11,49 @@ module.exports.lookupId = function(id, type, next) {
var artist = data.artists[0];
next({
id: data.id,
name: data.name,
url: "https://play.spotify.com/" + type + "/" + data.id,
artwork: data.images ? data.images[0].url.replace("http:", "") : data.album.images[0].url.replace("http:", ""),
artist: {
name: artist.name
}
})
if (type == "album") {
next({
service: "spotify",
type: type,
id: data.id,
name: data.name,
url: "https://play.spotify.com/" + type + "/" + data.id,
artwork: data.images ? data.images[0].url.replace("http:", "") : data.album.images[0].url.replace("http:", ""),
artist: {
name: artist.name
}
});
} else if (type == "track") {
next({
service: "spotify",
type: type,
id: data.id,
name: data.name,
url: "https://play.spotify.com/" + type + "/" + data.id,
artwork: data.images ? data.images[0].url.replace("http:", "") : data.album.images[0].url.replace("http:", ""),
artist: {
name: artist.name
},
album: {
name: data.album.name
}
})
}
});
}
module.exports.search = function(query, type, next) {
module.exports.search = function(data, next) {
var query = "";
var type = data.type;
if (type == "album") {
query = data.artist.name + " " + data.name;
} else if (type == "track") {
query = data.artist.name + " " + data.album.name + " " + data.name;
}
query = query.replace(":", "");
spotify.search({query: query, type: type}, function(err, data) {
if ( err ) {
console.log('Error occurred: ' + err);
@ -40,6 +70,6 @@ module.exports.parseUrl = function(url, next) {
var matches = parse(url).path.match(/\/(album|track)[\/]+([^\/]+)/);
if (matches && matches[2]) {
next({id:matches[2], type: matches[1]})
module.exports.lookupId(matches[2], matches[1], next);
}
}