Add html titles, improve youtube track matching

This commit is contained in:
Jonathan Cremin 2014-12-05 23:47:27 +00:00
parent 6decb7e8e3
commit 4d4c078220
3 changed files with 19 additions and 13 deletions

View file

@ -29,13 +29,18 @@ module.exports.search = function(data) {
query = data.artist.name + " " + data.name;
album = data.name;
} else if (type == "track") {
query = data.artist.name + data.name;
query = data.artist.name + " " + data.name;
album = data.album.name
}
var path = "/search?part=snippet&q=" + encodeURIComponent(query) + "&type=video&videoCaption=any&key=" + credentials.key;
request.get(apiRoot + path, function(res) {
var result = res.body.items[0];
if (!result) {
deferred.resolve({service:"youtube", type: "video"});
} else {
deferred.resolve({
service: "youtube",
type: "video",
@ -45,6 +50,7 @@ module.exports.search = function(data) {
purchaseUrl: null,
artwork: result.snippet.thumbnails.medium.url,
});
}
});
return deferred.promise;
};

View file

@ -29,7 +29,7 @@ module.exports = function(req, res, next) {
req.db.matches.findOne({_id:serviceId + itemId}).then(function(doc) {
if (doc) {
res.render(type, {page: type, items: doc.items});
res.render(type, {page: type, title: doc.items[0].name + " by " + doc.items[0].artist.name, items: doc.items});
} else {
Q.timeout(services[serviceId].lookupId(itemId, type), 5000).then(function(item) {
for (var id in services) {
@ -58,7 +58,7 @@ module.exports = function(req, res, next) {
items.unshift(item);
req.db.matches.save({_id:serviceId + itemId, items:items});
cache[serviceId][type + "-" + itemId] = items;
res.render(type, {page: type, items: items});
res.render(type, {page: type, title: item.name + " by " + item.artist.name, items: items});
});
}, function(error) {
if (error.code == "ETIMEDOUT") {

View file

@ -3,7 +3,7 @@
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Match Audio</title>
<title><% if (locals.title) { %><%= title %> - <% } %>Match Audio</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="shortcut icon" href="/images/favicon.png">