Skip to content

Instantly share code, notes, and snippets.

@also
Created February 13, 2011 02:20
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save also/824361 to your computer and use it in GitHub Desktop.
Save also/824361 to your computer and use it in GitHub Desktop.
function Nest(api_key) {
this.api_key = api_key;
}
Nest.prototype = {
analyzeFile: function(file, type, options) {
var form = new FormData();
form.append('api_key', this.api_key);
form.append('track', file);
form.append('filetype', type);
form.append('bucket', 'audio_summary');
var request = new XMLHttpRequest();
request.open('POST', 'http://developer.echonest.com/api/v4/track/upload');
request.onload = function (e) {
var result = JSON.parse(request.responseText);
result.response.track.audio_summary.analysis_url = 'http://developer.echonest.com' + result.response.track.audio_summary.analysis_url.substr(46);
options.onload(result);
}
request.onerror = function (e) {
options.onerror(e);
}
request.send(form);
},
loadAnalysis: function (url, options) {
var request = new XMLHttpRequest();
request.open('GET', url);
request.onload = function (e) {
options.onload(JSON.parse(request.responseText));
}
request.onerror = function (e) {
options.onerror();
}
request.send();
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment