Handle bad rdio urls
This commit is contained in:
parent
e5a69d684e
commit
7468cc4ea6
2 changed files with 30 additions and 22 deletions
|
@ -18,7 +18,6 @@ module.exports.lookupId = function(id, type, cc) {
|
||||||
if (id.match(/^[a-z]{2}/)) {
|
if (id.match(/^[a-z]{2}/)) {
|
||||||
cc = id.substr(0,2);
|
cc = id.substr(0,2);
|
||||||
id = id.substr(2);
|
id = id.substr(2);
|
||||||
console.log(id)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var path = "/lookup?id=" + id;
|
var path = "/lookup?id=" + id;
|
||||||
|
|
|
@ -74,32 +74,41 @@ module.exports.parseUrl = function(url) {
|
||||||
url: parsed.path,
|
url: parsed.path,
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
return;
|
var error = new Error("Not Found");
|
||||||
|
error.status = 404;
|
||||||
|
deferred.reject(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
rdio.api("", "", data, function(err, results) {
|
rdio.api("", "", data, function(err, results) {
|
||||||
var result = JSON.parse(results).result;
|
var results = JSON.parse(results);
|
||||||
var parsed = parse(result.shortUrl)
|
var result = results.result;
|
||||||
var id = parsed.path.replace("/x/", "").replace("/", "");
|
if (!result || results.status != "ok") {
|
||||||
var type = result.album ? "track" : "album";
|
var error = new Error("Not Found");
|
||||||
var item = {
|
error.status = 404;
|
||||||
service: "rdio",
|
deferred.reject(error);
|
||||||
type: type,
|
} else {
|
||||||
id: id,
|
var parsed = parse(result.shortUrl)
|
||||||
name: result.name,
|
var id = parsed.path.replace("/x/", "").replace("/", "");
|
||||||
streamUrl: result.shortUrl,
|
var type = result.album ? "track" : "album";
|
||||||
purchaseUrl: null,
|
var item = {
|
||||||
artwork: result.icon.replace("square-200", "square-250").replace("http:", "https:"),
|
service: "rdio",
|
||||||
artist: {
|
type: type,
|
||||||
name: result.artist
|
id: id,
|
||||||
}
|
name: result.name,
|
||||||
};
|
streamUrl: result.shortUrl,
|
||||||
if (type == "track") {
|
purchaseUrl: null,
|
||||||
item.album = {
|
artwork: result.icon.replace("square-200", "square-250").replace("http:", "https:"),
|
||||||
name: result.album
|
artist: {
|
||||||
|
name: result.artist
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
if (type == "track") {
|
||||||
|
item.album = {
|
||||||
|
name: result.album
|
||||||
|
};
|
||||||
|
}
|
||||||
|
deferred.resolve(item);
|
||||||
}
|
}
|
||||||
deferred.resolve(item);
|
|
||||||
});
|
});
|
||||||
return deferred.promise;
|
return deferred.promise;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue