It's been a little while since I messed w/ it but here is my XBMC javascript file
Code:
var MyMovies = new Array();
function updateXBMC() {
}
function loadShare(type, func) {
url = baseurl + xbmcurl + "xbmcCmds/xbmcHttp?command=" + type;
console.log(url);
var request = new XMLHttpRequest();
request.onreadystatechange = function() {
setTimeout(processShare(request,type), 500);
}
request.open("GET", url);
request.send("");
}
function processShare(request, type) {
if (request.readyState != 4 || request.status != 200) return;
var text = request.responseText;
text = text.replace(/\n/g, "");
text = text.replace(/\<html\>/g,"");
text = text.replace(/\<\/html\>/g,"");
text = text.replace(/\<li\>/g,"");
text = text.replace(/\<\/li\>/g,"");
var textarray = text.split("1");
remotescreen = eval('document.getElementById("XBMC-REMOTE3")');
remotescreen.innerHTML = '<li class="group">Video</li>';
for ( var i = 0; i < textarray.length; i++ ) {
var args = textarray[i].split(";");
var label = args[0];
var location = args[1];
if ( !label || !location ) continue;
location = location.replace(/\\/g, '\\\\');
var url = '<li class="XBMCBUTTON"><a href="#_NONE" onclick="drawMovies(' +"'" + location + "'"+ ');">' + label + '</a></li>';
remotescreen.innerHTML += url;
}
showPage('XBMC-REMOTE3');
}
//////////////////
// MOVIE OBJECT //
//////////////////
function loadMovies() {
var url = baseurl + xbmcurl + "xbmcCmds/xbmcHttp?command=queryVideoDatabase(select movie.idFile, c00, c01, c05, c07, c15, strPath, strFileName from movie, files, path where movie.idFile = files.idFile AND files.idPath = path.idPath order by c00 DESC)";
var request = new XMLHttpRequest();
request.open("GET", url);
request.onreadystatechange = function() {
setTimeout(processMoviesHTTP(request), 500);
}
request.send("");
}
function xbmcShowMovies() {
loadShare('GetShares(Video;appendone)', 'type');
loadMovies();
}
function drawMovies(location) {
var i = MyMovies.length;
remotescreen = eval('document.getElementById("XBMC-REMOTE4")');
remotescreen.innerHTML = '';
var i = MyMovies.length;
while (i--) {
remotescreen.innerHTML += MyMovies[i].html;
}
showPage('XBMC-REMOTE4');
}
function MovieFile (movieid,title,plot,rating,year,director,file,path,thumbnail) {
this.movieid;
this.title;
this.plot;
this.rating;
this.year;
this.director;
this.file;
this.path;
this.thumbnail = thumbnail;
this.html = '<li class="group">' + title + '</li>';
this.html += "<A HREF='#_NONE' onclick=";
filepath = path + file;
filepath = filepath.replace(/\\/g, "\\\\");
this.html += '"playMovie(' + "'" + filepath + "');" + '">';
this.html += "<TABLE><TR><TD CLASS='poster'><img height='85' src='" + thumbnail + "'><TD CLASS='plot'>";
this.html += plot + "</TABLE></A>";
}
function playMovie( movie ) {
var request =new XMLHttpRequest();
var url = xbmcurl + "xbmcCmds/xbmcHttp?command=PlayFile(" + movie + ")";
request.open("GET",url,true);
request.send(null);
}
function processMoviesHTTP(request) {
if (request.readyState != 4 || request.status != 200) return;
var text = request.responseText;
text = text.replace(/\<HTML\>/i, '');
text = text.replace(/\<\/HTML\>\n/i, '');
text = text.split('</field><field>');
text[0] = text[0].replace(/\<FIELD\>/i, '');
text[text.length - 1] = text[text.length-1].replace(/\<\/FIELD\>/i, '');
for ( var i=0; i < text.length; ) {
var movieid = text[i++];
var title = text[i++];
var plot = text[i++];
var rating = text[i++];
var year = text[i++];
var director = text[i++];
var path = text[i++];
var file = text[i++];
var crc = FindCRC(path+file);
var thumbnail = baseurl + 'thumbnails/Video/' + crc.charAt(0) + "/" + crc + ".tbn";
var movie = new MovieFile( movieid, title, plot, rating, year, director, file, path, thumbnail);
MyMovies.push(movie);
}
}
function xbmcButton( command ) {
sendEvent('index.html?' + command,updateXBMC);
//startRefreshTimer();
}
function showXBMC( page ) {
// if ( page.indexOf('HOME') > -1 )
// stopOnkyoRefreshTimer();
// else {
// updateOnkyo();
// startOnkyoRefreshTimer();
// }
showPage(page);
}
/////////////////////////////
// THUMBNAIL CRC GENERATOR //
/////////////////////////////
Number.prototype.unsign = function(bytes) {
return this >= 0 ? this : Math.pow(256, bytes || 4) + this;
};
function FindCRC(data) {
var CRC=0xffffffff;
data = data.toLowerCase();
//console.log(data);
for (var j=0; j < data.length; j++) {
var c = data.charCodeAt(j);
CRC ^= c << 24;
for(var i = 0; i<8; i++) {
if(CRC.unsign(8) & 0x80000000)
CRC = (CRC << 1) ^ 0x04C11DB7;
else
CRC <<= 1;
}
}
if ( CRC < 0 ) CRC = CRC>>>0;
return CRC.toString(16);
}