diff --git a/app.js b/app.js index e542c5d..e9353f4 100644 --- a/app.js +++ b/app.js @@ -44,7 +44,12 @@ app.get('*', function(req,res,next) { }); app.get('/', function(req, res) { - res.render('index', { error: req.flash('search-error') }); + var samples = [ + {artist: "Aesop Rock", album: "None Shall Pass", url: '/google/album/Bpnz47tzvmp3p46ht3syerwyvva'}, + {artist: "Hozier", album: "self-titled album", url: '/google/album/Bd3mxcy3otokg4yc45qktq7l35q'}, + {artist: "Daft Punk", album: "Discovery", url: '/google/album/B4t6yqqvhnb2hy4st4uisjrcsrm'} + ]; + res.render('index', { samples: samples, error: req.flash('search-error') }); }); app.post('/search', search); diff --git a/lib/services/spotify.js b/lib/services/spotify.js index 111a017..b100fdc 100644 --- a/lib/services/spotify.js +++ b/lib/services/spotify.js @@ -73,6 +73,7 @@ module.exports.search = function(data) { if (!data[type + "s"].items[0]) { deferred.resolve({service:"spotify"}); + return; } var item = data[type + "s"].items[0]; diff --git a/routes/share.js b/routes/share.js index 57c157c..d6b57e8 100644 --- a/routes/share.js +++ b/routes/share.js @@ -4,10 +4,13 @@ var Q = require('q'); var services = {}; +var cache = {}; + require("fs").readdirSync(path.join(__dirname, "..", "lib", "services")).forEach(function(file) { var service = require("../lib/services/" + file); if (service.search) { services[service.id] = service; + cache[service.id] = {}; } }); @@ -17,6 +20,11 @@ module.exports = function(req, res) { var itemId = req.params.id; var promises = []; + if (cache[serviceId][type + "-" + itemId]) { + res.render(type, {items: cache[serviceId][type + "-" + itemId]}); + return; + } + services[serviceId].lookupId(itemId, type).then(function(item) { for (var id in services) { if (id != serviceId) { @@ -38,7 +46,7 @@ module.exports = function(req, res) { }); items.unshift(item); - + cache[serviceId][item.type + "-" + item.id] = items; res.render(type, {items: items}); }); }); diff --git a/views/index.ejs b/views/index.ejs index 5fce0da..35709c7 100644 --- a/views/index.ejs +++ b/views/index.ejs @@ -25,7 +25,7 @@
- + @@ -38,7 +38,8 @@

Make sharing from music services better. We match album and track links from Rdio, Spotify, Deezer, Beats Music, Google Music and iTunes and give you back a link with all of them.

-

Here's a sample.

+ <% var sample = samples[Math.floor(Math.random() * samples.length)] %> +

Here's an example with <%= sample.artist %>'s <%= sample.album %>.