mirror of
https://github.com/danbee/spotify-client
synced 2025-03-04 08:59:12 +00:00
42 lines
1004 B
JavaScript
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)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
})
|
|
}
|