-
Notifications
You must be signed in to change notification settings - Fork 0
/
earrelevant.coffee
56 lines (47 loc) · 1.46 KB
/
earrelevant.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
Albums = new Meteor.Collection("albums")
if Meteor.isClient
Template.album_list.albums =->
return Albums.find({})
Template.input.events
"click button": ->
artist = $("input.artist").val()
album = $("input.album").val()
Meteor.call "getAlbumArt",
artist,
album,
(error, result) ->
if not error?
Albums.insert
name: album
artist: artist
cover: result
Template.album_info.events
"click .close": ->
Albums.remove
name: this.name
artist: this.artist
Template.album_info.rendered =->
$cover = $(this.find(".cover"))
console.log($cover)
Meteor.defer =>
$cover.removeClass("loading", 1000, "easeOutBounce")
if Meteor.isServer
Meteor.startup =>
Future = NodeModules.require("fibers/future")
LastFmNode = NodeModules.require("lastfm").LastFmNode
lastfm = new LastFmNode
api_key: "d57272a26ba342b4e2ca59617a7ab7df"
secret: "7e71cc886f09e5dc696af9ab16beb8ba"
Meteor.methods
getAlbumArt: (artist, album) ->
fut = new Future()
lastfm.request "album.getInfo",
artist: artist
album: album
handlers:
success: (data) ->
fut.ret(data.album.image[2]["#text"])
error: (error) ->
console.log("Error: " + error.message)
fut.ret("/images/default_album.gif")
return fut.wait()