-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEchonest.js
56 lines (39 loc) · 1.57 KB
/
Echonest.js
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
define(['jquery'], function ($) {
var exports = {},
sp = getSpotifyApi(1),
models = sp.require('sp://import/scripts/api/models');
function normalizeRelatedArtistsResults (data) {
var normalizedData = [],
item,
artists = data['response']['artists'];
for (var index in artists) {
item = {};
item.name = artists[index]['name'];
item.track = artists[index]['songs'][0]['title'];
item.musicbrainzid = artists[index]['foreign_ids'][0]['foreign_id'].replace('musicbrainz:artist:', '');
normalizedData.push(item);
}
return normalizedData;
}
exports.getRelatedArtistsData = function (spotifyArtistCode, callback) {
$.ajax({
url : "http://developer.echonest.com/api/v4/artist/similar?api_key=FILDTEOIK2HBORODV&id=spotify-WW:artist:"
+ spotifyArtistCode
+ '&bucket=songs&bucket=id:musicbrainz',
success : function (data) {
callback(normalizeRelatedArtistsResults(data));
}
});
};
exports.getMusicBrainzId = function(spotifyArtistId, spotifyTrackId, callback){
$.ajax({
url : "http://developer.echonest.com/api/v4/artist/profile?api_key=FILDTEOIK2HBORODV&id=spotify-WW:artist:"
+ spotifyArtistId,
success : function (data) {
console.log(data);
callback(data.response.artist.id, spotifyTrackId);
}
});
};
return exports;
});