Added artist information on last.fm example with bio, tags, cover image, and stats

This commit is contained in:
Sahat Yalkabov
2013-12-09 23:11:41 -05:00
parent e8f2a6688b
commit c5d2513e43
3 changed files with 49 additions and 21 deletions

1
app.js
View File

@ -26,6 +26,7 @@ var app = express();
app.set('port', process.env.PORT || 3000); app.set('port', process.env.PORT || 3000);
app.set('views', path.join(__dirname, 'views')); app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade'); app.set('view engine', 'jade');
app.locals.pretty = true;
app.use(express.favicon()); app.use(express.favicon());
app.use(express.logger('dev')); app.use(express.logger('dev'));
app.use(express.cookieParser()); app.use(express.cookieParser());

View File

@ -174,6 +174,10 @@ exports.getEtsy = function(req, res) {
*/ */
exports.getNewYorkTimes = function(req, res) { exports.getNewYorkTimes = function(req, res) {
res.render('api/nyt', {
title: 'New York Times API',
});
}; };
/** /**
@ -186,10 +190,34 @@ exports.getLastfm = function(req, res) {
secret: '4ae76d10d76cf680cebf4f0c8dea1aa4' secret: '4ae76d10d76cf680cebf4f0c8dea1aa4'
}); });
res.render('api/lastfm', { lastfm.request("artist.getInfo", {
title: 'Last.fm API', artist: 'Epica',
handlers: {
success: function(data) {
console.log(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
};
res.render('api/lastfm', {
title: 'Last.fm API',
artist: artist
});
//return res.send(data.artist);
},
error: function(error) {
console.log(error.message);
return error.message;
}
}
}); });
}; };
/** /**

View File

@ -17,26 +17,25 @@ block content
| Documentation | Documentation
h3.text-primary Artist Information h3.text-primary Artist Information
form.form-horizontal(role='form', method='POST')
.form-group
label(class='col-sm-2 control-label', for='artist') Artist
.col-sm-4
input.form-control(type='text', name='artist', id='artist')
.form-group
.col-sm-offset-2.col-sm-4
button.btn.btn-primary-outline(type='submit') Submit
.panel.panel-default h4= artist.name
.panel-heading .btn.btn-sm.btn-primary-outline
h3.title #{artist.name} i.fa.fa-users
.panel-body | Listeners: #{artist.stats.listeners}
.row .btn.btn-sm.btn-primary-outline
.col-xs-3 i.fa.fa-headphones
img(src='#{artist.image}') | Scrobbles #{artist.stats.playcount}
.col-xs-9 p
strong Artist Bio img(src='#{artist.image}')
br p
p= artist.bio for tag in artist.tags
span.label.label-primary
i.fa.fa-tag
| #{tag.name}
| 
p!= artist.bio
h3.text-primary Song Information h3.text-primary Song Information