Request.YQL + YT
by Oski Krawczyk
HTML
<ul id="tracks"></ul>
JavaScript
Request.YQL = new Class({
Extends: Request.JSONP,
options: {
url: 'http://query.yahooapis.com/v1/public/yql?q=',
allTables: true,
data: {
format: 'json',
env: 'store://datatables.org/alltableswithkeys'
}
},
initialize: function(options) {
this.setOptions(options);
this.options.url = this.options.url + encodeURIComponent(this.options.query);
this.running = false;
this.requests = 0;
this.triesRemaining = [];
}
});
var yqlQuery = "select * from youtube.video where id='{musicId}'".substitute({
musicId: 'PPAXpwu2kFg'
});
// make the YQL call
new Request.YQL({
query: yqlQuery,
allTables: true,
onSuccess: function(result) {
document.body.set('text', 'The track is ' + result.query.results.video.duration + ' seconds long');
}
}).send();