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

@ -120,7 +120,11 @@ module.exports.search = function(data) {
albumClean = data.name.match(/([^\(\[]+)/)[0];
} else if (type == "track") {
query = data.artist.name + " " + data.album.name + " " + data.name;
albumClean = data.album.name.match(/([^\(\[]+)/)[0];
try {
albumClean = data.album.name.match(/([^\(\[]+)/)[0];
} catch(e) {
albumClean = "";
}
}
return rdio.apiAsync("", "", {query: query, method: 'search', types: type}).then(function(results) {
@ -129,14 +133,14 @@ module.exports.search = function(data) {
var result = results.filter(function(result) {
if (type == "album" && result.name.match(/([^\(\[]+)/)[0] == albumClean) {
return result;
} else if (type == "track" && result.album.match(/([^\(\[]+)/)[0] == albumClean) {
} else if (type == "track" && (result.album.match(/([^\(\[]+)/)[0] == albumClean || !albumClean)) {
return result;
}
}).shift();
if (!result) {
var matches = albumClean.match(/^[^\(\[]+/);
if (matches[0] && matches[0] != albumClean) {
if (matches && matches[0] && matches[0] != albumClean) {
var cleanedData = JSON.parse(JSON.stringify(data));
if (type == "album") {
cleanedData.name = matches[0].trim();