Add support for matching from Youtube urls

This commit is contained in:
Jonathan Cremin 2015-01-12 17:38:42 +00:00
parent 7d3173c57e
commit 599e9b0850
12 changed files with 130 additions and 14 deletions

View file

@ -72,14 +72,14 @@ module.exports.search = function(data) {
query = "artist:" + data.artist.name.replace(":", "") + " album:" + data.name.replace(":", "");
album = data.name;
} else if (type == "track") {
query = "artist:" + data.artist.name.replace(":", "") + " album:" + data.album.name.replace(":", "") + " track:" + data.name.replace(":", "");
query = "artist:" + data.artist.name.replace(":", "") + " track:" + data.name.replace(":", "") + ( data.album.name.length > 0 ? " album: " + data.album.name.replace(":", ""): "");
album = data.album.name;
}
return spotify.searchAsync({query: query, type: type}).then(function(results) {
if (!results[type + "s"].items[0]) {
var matches = album.match(/^[^\(\[]+/);
if (matches[0] && matches[0] != album) {
if (matches && matches[0] && matches[0] != album) {
var cleanedData = JSON.parse(JSON.stringify(data));
if (type == "album") {
cleanedData.name = matches[0].trim();