1
0
mirror of https://github.com/danbee/spotify-client synced 2025-03-04 08:59:12 +00:00
spotify-client/spotify-client.js
2014-10-31 17:29:18 +00:00

42 lines
1004 B
JavaScript

if (Meteor.isClient) {
Template.body.helpers({
songs: function () {
return Session.get('songs')
}
})
Template.body.events({
"submit .search": function (event) {
event.preventDefault()
q = event.target.q.value
if (q) {
HTTP.call('get', 'https://api.spotify.com/v1/search', {
params: { type: 'track', market: 'GB', q: q }
}, function (error, result) {
if (!error) {
tracks = []
items = JSON.parse(result.content).tracks.items
items.forEach(function (item) {
tracks.push({
artist: item.artists.map(function (artist) {
return artist.name
}).join(', '),
album: item.album.name,
title: item.name,
image: item.album.images[2].url
})
console.log(item)
})
Session.set('songs', tracks)
}
})
}
}
})
}