From 6e364983e503a0457b62fc64f5699b921cb3bbbd Mon Sep 17 00:00:00 2001 From: Sahat Yalkabov Date: Thu, 5 Jun 2014 12:56:06 -0400 Subject: [PATCH] Updated last.fm api example --- controllers/api.js | 30 ++++++++++++++++++++----- views/api/index.jade | 2 +- views/api/lastfm.jade | 52 +++++++++++++++++-------------------------- 3 files changed, 46 insertions(+), 38 deletions(-) diff --git a/controllers/api.js b/controllers/api.js index 5eba4ff223..4a9af0759e 100644 --- a/controllers/api.js +++ b/controllers/api.js @@ -192,8 +192,8 @@ exports.getLastfm = function(req, res, next) { var lastfm = new LastFmNode(secrets.lastfm); async.parallel({ artistInfo: function(done) { - lastfm.request("artist.getInfo", { - artist: 'Epica', + lastfm.request('artist.getInfo', { + artist: 'Sirenia', handlers: { success: function(data) { done(null, data); @@ -204,9 +204,26 @@ exports.getLastfm = function(req, res, next) { } }); }, + artistTopTracks: function(done) { + lastfm.request('artist.getTopTracks', { + artist: 'Sirenia', + handlers: { + success: function(data) { + var tracks = []; + _.each(data.toptracks.track, function(track) { + tracks.push(track); + }); + done(null, tracks.slice(0,10)); + }, + error: function(err) { + done(err); + } + } + }); + }, artistTopAlbums: function(done) { - lastfm.request("artist.getTopAlbums", { - artist: 'Epica', + lastfm.request('artist.getTopAlbums', { + artist: 'Sirenia', handlers: { success: function(data) { var albums = []; @@ -231,7 +248,8 @@ exports.getLastfm = function(req, res, next) { bio: results.artistInfo.artist.bio.summary, stats: results.artistInfo.artist.stats, similar: results.artistInfo.artist.similar.artist, - topAlbums: results.artistTopAlbums + topAlbums: results.artistTopAlbums, + topTracks: results.artistTopTracks }; res.render('api/lastfm', { title: 'Last.fm API', @@ -556,7 +574,7 @@ exports.getInstagram = function(req, res, next) { async.parallel({ searchByUsername: function(done) { - ig.user_search('lisa_veronica', function(err, users, limit) { + ig.user_search('richellemead', function(err, users, limit) { done(err, users); }); }, diff --git a/views/api/index.jade b/views/api/index.jade index 4764bf3178..7eaffe770d 100644 --- a/views/api/index.jade +++ b/views/api/index.jade @@ -38,7 +38,7 @@ block content .col-sm-4 .panel.panel-default .panel-body - img(src='http://www.bigbigtrain.com/pics/gfx/lastfm_logo.png', height=40) + img(src='http://fontslogo.com/wp-content/uploads/2013/02/Lastfm-Logo-Font.jpg', height=40) a(href='/api/lastfm') Last.fm .col-sm-4 .panel.panel-default diff --git a/views/api/lastfm.jade b/views/api/lastfm.jade index 46f17baca5..2c57e3e84b 100644 --- a/views/api/lastfm.jade +++ b/views/api/lastfm.jade @@ -3,9 +3,8 @@ extends ../layout block content .page-header h2 - i.fa.fa-music + i.fa.fa-play-circle-o(style='color: #db1302') | Last.fm API - .btn-group.btn-group-justified a.btn.btn-primary(href='https://github.com/jammus/lastfm-node#lastfm-node', target='_blank') i.fa.fa-check-square-o @@ -17,41 +16,32 @@ block content i.fa.fa-code-fork | API Endpoints - h3.text-primary Artist Information + h3= artist.name + img.thumbnail(src='#{artist.image}') - h4= artist.name - ul.list-inline - li - small.text-primary - i.fa.fa-users - | Listeners: #{artist.stats.listeners} - li - small.text-primary - i.fa.fa-headphones - | Scrobbles: #{artist.stats.playcount} + h3 Tags + for tag in artist.tags + span.label.label-primary + i.fa.fa-tag + | #{tag.name} + |  - p - img(src='#{artist.image}') + h3 Biography + p!= artist.bio - p - for tag in artist.tags - span.label.label-primary - i.fa.fa-tag - | #{tag.name} - |  - - .panel.panel-primary - .panel-heading Biography - .panel-body - != artist.bio - - h4 Top Albums + h3 Top Albums for album in artist.topAlbums img(src='#{album}', width=150, height=150) |  - h4 Similar Artists - ul.list-unstyled + h3 Top Tracks + ol + for track in artist.topTracks + li + a(href='#{track.url}') #{track.name} + + h3 Similar Artists + ul.list-unstyled.list-inline for similarArtist in artist.similar li - a.lead(href='#{similarArtist.url}') #{similarArtist.name} \ No newline at end of file + a(href='#{similarArtist.url}') #{similarArtist.name} \ No newline at end of file