diff --git a/controllers/api.js b/controllers/api.js index 98c9a17212..9607cfc9be 100644 --- a/controllers/api.js +++ b/controllers/api.js @@ -190,27 +190,56 @@ exports.getLastfm = function(req, res) { secret: '4ae76d10d76cf680cebf4f0c8dea1aa4' }); - lastfm.request("artist.getInfo", { - artist: 'Epica', - handlers: { - success: function(data) { - var artist = { - name: data.artist.name, - image: data.artist.image.slice(-1)[0]['#text'], - tags: data.artist.tags.tag, - bio: data.artist.bio.summary, - stats: data.artist.stats, - similar: data.artist.similar.artist - }; - res.render('api/lastfm', { - title: 'Last.fm API', - artist: artist - }); - }, - error: function(error) { - res.send(error.message); - } + async.parallel({ + artistInfo: function(done) { + lastfm.request("artist.getInfo", { + artist: 'Epica', + handlers: { + success: function(data) { + done(null, data); + }, + error: function(error) { + done(error); + } + } + }); + }, + artistTopAlbums: function(done) { + lastfm.request("artist.getTopAlbums", { + artist: 'Epica', + handlers: { + success: function(data) { + var albums = []; + _.each(data.topalbums.album, function(album) { + albums.push(album.image.slice(-1)[0]['#text']); + }); + done(null, albums); + }, + error: function(error) { + done(error); + } + } + }); } + }, + function(err, results) { + if (err) return res.send(err); + console.log('===') + console.log(err); + console.log(results); + var artist = { + name: results.artistInfo.artist.name, + image: results.artistInfo.artist.image.slice(-1)[0]['#text'], + tags: results.artistInfo.artist.tags.tag, + bio: results.artistInfo.artist.bio.summary, + stats: results.artistInfo.artist.stats, + similar: results.artistInfo.artist.similar.artist, + topAlbums: results.artistTopAlbums + }; + res.render('api/lastfm', { + title: 'Last.fm API', + artist: artist + }); }); }; diff --git a/views/api/lastfm.jade b/views/api/lastfm.jade index cd6a241fe4..5fa4f60f49 100644 --- a/views/api/lastfm.jade +++ b/views/api/lastfm.jade @@ -23,23 +23,31 @@ block content li small.text-primary i.fa.fa-users - strong Listeners: - | #{artist.stats.listeners} + | Listeners: #{artist.stats.listeners} li small.text-primary i.fa.fa-headphones - strong Scrobbles: - | #{artist.stats.playcount} + | Scrobbles: #{artist.stats.playcount} p img(src='#{artist.image}') + p for tag in artist.tags span.label.label-primary i.fa.fa-tag | #{tag.name} |  - p!= artist.bio - strong Similar Artists + + .panel.panel-default + .panel-heading Biography + .panel-body + != artist.bio + + h4 Top Albums + for album in artist.topAlbums + album + + h4 Similar Artists ul.list for similarArtist in artist.similar li