Skip to content

Instantly share code, notes, and snippets.

@rclabs
Created January 18, 2013 11:38
Show Gist options
  • Select an option

  • Save rclabs/4564096 to your computer and use it in GitHub Desktop.

Select an option

Save rclabs/4564096 to your computer and use it in GitHub Desktop.
youtube to xbmc using node.js
// based on
// xbmc api example http://userscripts.org/scripts/review/117046
// node.js example code http://nodejs.org/api/http.html#http_http_request_options_callback
var http = require('http');
var options = {
hostname: '192.168.1.100',
port: 80,
path: '/jsonrpc',
method: 'POST'
};
var responseHandler = function(res) {
console.log('STATUS: ' + res.statusCode);
console.log('HEADERS: ' + JSON.stringify(res.headers));
res.setEncoding('utf8');
res.on('data', function (chunk) {
console.log('BODY: ' + chunk);
});
};
function dorequest() {
request = http.request(options, responseHandler);
request.write(JSON.stringify(data));
request.end();
}
function extractId(url) {
var re = new RegExp(/.*watch\?v=(.*)/);
var matches = re.exec(url);
return matches[1];
}
var data = {
jsonrpc: '2.0',
method: 'Player.Open',
params: {item:
{file: 'plugin://plugin.video.youtube/?action=play_video&videoid=' + extractId(process.argv[2])}
},
id: 1
};
dorequest();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment