Your Universal Remote Control Center
RemoteCentral.com
Philips Pronto Professional Forum - View Post
Up level
Up level
The following page was printed from RemoteCentral.com:

Login:
Pass:
 
 

Original thread:
Post 41 made on Friday August 7, 2020 at 15:00
mpg7321
Regular Member
Joined:
Posts:
June 2020
51
So far this is the code that does work with KODI feedback. Do need to clean it up a bit but does pull all data I wanted. THIS IS FOR MOVIES ONLY. Have not modified to work properly on TV shows or music yet. So this gives me , Title, Progress slider, Cover Art, total time, time remaining, displaying play speed, IE 2x 4x 8x 16x & 32x both Fastforward and Rewind, show or hide the Play or Pause buttons.

System.setDebugMask(9);
var url = CF.widget("Kodi_aURL","Kodi_PARAMETERS_test").label;
var cover;
var data;
function kodi1(){
var socket = new TCPSocket();
socket.onConnect = function() {
prefix = 'GET /jsonrpc?request={"jsonrpc": "2.0", "method": "Player.GetItem", "params": { "properties": ["title", "thumbnail"], "playerid": 1 }, "id": "1"}'
postfix = ' HTTP/1.0\r\n'
try {
socket.write(prefix+postfix);
socket.write("HOST:+url+\r\n\r\n");
} catch(e) {
socket.close()
}}
socket.onData = function() {
var info1 = socket.read();
cover = info1.split('original%2f').pop().split('.jpg')[0];
//CF.widget("MOVIE_COVER").label=cover;
if (info1.indexOf('unknown') !== -1) {
CF.widget("KODI_TITLE").label="Nothing Playing";
}else{
var title = info1.split('title":"').pop().split('","type')[0];
CF.widget("KODI_TITLE").label=title;
};
socket.close()
CF.activity().scheduleAfter(500,kodi2);
}
socket.onIOError = function(e) {
socket.close()
}
socket.connect(url, 9090, 500);
};


function kodi2(){
var socket = new TCPSocket();
var receivedData = "";
socket.onConnect = function() {
socket.write("GET /t/p/w185/"+cover+".jpg HTTP/1.0\r\n");
socket.write("HOST: image.tmdb.org\r\n");
socket.write("CONNECTION: close\r\n");
socket.write("\r\n");
};
socket.onData = function() {
receivedData += socket.read();
};
socket.onIOError = function (e) {
CF.widget("data").label = "IOError " + e;
};
socket.onClose = function () {
var imageStartIndex, bitmapData, myImage;
// remove the HTTP header from the received data
imageStartIndex = receivedData.indexOf("\r\n\r\n");
bitmapData = receivedData.substring(imageStartIndex+4);
// make and display the image
myImage = new Image(bitmapData);
CF.widget("MOVIE_COVER").setImage(myImage);
//CF.widget("MOVIE_COVER").width=100;
//CF.widget("MOVIE_COVER").height=200;
//CF.widget("MOVIE_COVER").label=cover;
CF.activity().scheduleAfter(500,kodi3);
};
socket.connect("image.tmdb.org",80, 500);
}


function kodi3(){
var socket = new TCPSocket();
socket.onConnect = function() {
prefix2 = 'GET /jsonrpc?request={"jsonrpc": "2.0", "method": "Player.GetProperties", "params": { "properties": ["percentage", "totaltime", "time", "speed"], "playerid": 1 }, "id": "1"}'
postfix2 = ' HTTP/1.0\r\n'
try {
socket.write(prefix2+postfix2);
socket.write("HOST:+url+\r\n\r\n");
} catch(e) {
socket.close()
}}
socket.onData = function() {
var info = socket.read();
var percentage = info.split('percentage":').pop().split('.')[0];
var speed = info.split('"speed":').pop().split(',')[0];
var totaltime = info.split('"totaltime"').pop().split('}')[0];
var totaltime_hour = totaltime.split('"hours":').pop().split(',')[0];
var totaltime_minute = totaltime.split('"minutes":').pop().split(',')[0];
if (totaltime_minute <= 9){
totaltime_minute =(0+totaltime_minute);
};
var totaltime_caculated = parseInt(totaltime_minute) + (parseInt(totaltime_hour)*60);
var time = info.split('"time"').pop().split('}')[0];
var time_hour = time.split('"hours":').pop().split(',')[0];
var time_minute = time.split('"minutes":').pop().split(',')[0];
var time_caculated = parseInt(time_minute) + (parseInt(time_hour)*60);
var time_remaning = totaltime_caculated-time_caculated;
if (time_remaning <= 9){
CF.widget("RUN_TIME_REMAIN").label="-0H : 0"+time_remaning + "m";
}else if (time_remaning <= 60){
CF.widget("RUN_TIME_REMAIN").label="-0H : "+time_remaning + "m";
}else{
var hours =time_remaning/60;
var rhours = Math.floor(hours);
var minutes = (hours - rhours) * 60;
var rminutes = Math.round(minutes);
if (rminutes <= 9){
rminutes=("0"+rminutes);
};
CF.widget("RUN_TIME_REMAIN").label="-"+rhours + "H : " + rminutes + "m";
};
if (totaltime_hour == 0){
CF.widget("RUN_TIME").label=": " + totaltime_minute + " m";
//CF.widget("RUN_TIME_REMAIN").label="To Go = : " + (totaltime_minute-time_minute) + " m";
}else{
CF.widget("RUN_TIME").label=totaltime_hour+ "H : " + totaltime_minute + "m";
//CF.widget("RUN_TIME_REMAIN").label="To Go = " + (totaltime_hour-time_hour) + "H : " + (totaltime_minute-time_minute) + "m";
}
if (speed == 1) {
CF.widget("Play").visible = false;
CF.widget("Pause").visible = true;
CF.widget("FF_Speed").label="-";
CF.widget("RR_Speed").label="-";
} else if (speed == 0){
CF.widget("Play").visible = true;
CF.widget("Pause").visible = false;
CF.widget("FF_Speed").label="-";
CF.widget("RR_Speed").label="-";
}else if (speed > 1){
CF.widget("Play").visible = true;
CF.widget("Pause").visible = false;
CF.widget("FF_Speed").label=speed+"x";
CF.widget("RR_Speed").label="-";
}else if (speed < 0){
CF.widget("Play").visible = true;
CF.widget("Pause").visible = false;
CF.widget("RR_Speed").label=speed+"x";
CF.widget("FF_Speed").label="-";
};
if (percentage == 0.0) {
CF.widget("PROGRESS").width=1;
} else {
CF.widget("PROGRESS").width=(percentage/100)*620;
}
socket.close()
}
socket.onIOError = function(e) {
socket.close()
}
socket.connect(url, 9090, 500);
};


Hosting Services by ipHouse