Quantcast
Channel: The Echo Nest Developer Forum
Viewing all articles
Browse latest Browse all 1582

Javascript Track Analysis Segments

$
0
0

Hi all,
I'm trying to get the analysis segments (timbre/pitch) for a track with a particular track ID in Javascript. I would like my application to be fully client-side so Javascript is a must for me.

When I look at the documentation for tracks

http://developer.echonest.com/docs/v4/track.html

I see that the JSON response has many of the fields mentioned in the "Analyze Documentation," but it is missing the segments. I then started digging into the code for Remix.js, and I found a code segment that proxies a call through the yahoo query engine, which returns the segments eventually. This sometimes works, and it works great! But more often than not, it stalls and is unable to complete the query (and it's random, so not likely related to any rate limits). I've tried this for about a dozen different track IDs, and it has both worked and not worked on each one of them at different times. Is it possible to get segment data more reliably for a particular track in Javascript?

I apologize if I missed something simple on the forums or in the documentation! Also I am new to Javascript (though very experienced in other languages including C++, Java, and Python), so perhaps I made a mistake there. Thank you very much for your help, and for making such a cool project!
Sincerely,
Chris Tralie

Code I've been exploring:


function lookForAnalysis(trackID) {
    var url = 'http://developer.echonest.com/api/v4/track/profile?format=json&bucket=audio_summary';
    var track;
$.getJSON(url, {id:trackID, api_key:ECHONESTKEY}, function(data) {
    var analysisURL = data.response.track.audio_summary.analysis_url;
    track = data.response.track;

    // This call is proxied through the yahoo query engine.  
    // This is temporary, but works.
    $.getJSON("http://query.yahooapis.com/v1/public/yql", 
        { q: "select * from json where url=\"" + analysisURL + "\"", format: "json"}, 
        function(data) {
            if (data.query.results != null) {
                track.analysis = data.query.results.json;
                console.log("Got analysis");
                getSegmentsText(track);
            }
            else {
                retryCount = retryCount - 1;
                retryInterval = retryInterval + 1000;
                if (retryCount > 0) {
                    console.log('Analysis pending, trying again')
                    setTimeout(function () {
                        lookForAnalysis(trackID);
                    }, retryInterval);
                } else {
                    console.log('error', 'No analysis data returned:  try again, or try another trackID');   
                }
            }
    }); // end yahoo proxy getJson
});

} // end lookForAnalysis


Viewing all articles
Browse latest Browse all 1582

Trending Articles