Here's a script I use to carry on watching a program (tv show of film) in bed
When I run the "bed time" scene it triggers this script (and turns lots of lights off).
This script checks to see if the lounge kodi is paused and therefore assumes i want to carry on watching it in bed.
If not paused then it doesn't run - i'm going to bed to sleep lol
commandArray = {};
FullResult=""
function send(msg)
runcommand = "echo "..string.char(34).."POST "..msg.. " HTTP/1.1"..string.char(13)..string.char(10)..string.char(13)..string.char(10)..string.char(34).."| telnet "..IP.." "..Port.." "
print (runcommand)
os.execute(runcommand)
end
function urlencode(str)
if (str) then
str = string.gsub (str, "\n", "\r\n")
str = string.gsub (str, "([^%w ])",
function (c) return string.format ("%%%02X", string.byte(c)) end)
str = string.gsub (str, " ", "+")
end
return str
end
function os.capture(cmd, raw)
local f = assert(io.popen(cmd, 'r'))
local s = assert(f:read('*a'))
f:close()
if raw then return s end
s = string.gsub(s, '^%s+', '')
s = string.gsub(s, '%s+$', '')
s = string.gsub(s, '[\n\r]+', ' ')
FullResult=s
return s
end
function sendToKodi(IP, msg)
msg2="jsonrpc?request="..urlencode(msg)
runcommand = "curl http://"..(IP)..":"..(8080).."/"..(msg2)..""
print (runcommand)
os.capture(runcommand,false)
end
function sleep(n)
os.execute("sleep " .. tonumber(n))
end
if devicechanged['LoungeToBedroomKodi'] and devicechanged['LoungeToBedroomKodi']=='On' then
print("Kodi Lounge To Bedroom Script Started..")
PausedType=""
PausedID=0
--if lounge xbmc paused:
if otherdevices['Lounge (Kodi)'] == 'Paused' then
--query currently playing
sendToKodi('192.168.2.105','{"jsonrpc":"2.0","method":"Player.GetItem","params":{"properties":[],"playerid":1},"id":"VideoGetItem"}')
print(" Full Result: "..FullResult)
--store id and type playing
if string.len(FullResult) > 0 then
PausedType=string.sub(FullResult, string.find(FullResult,"type")+7, -5)
idstart=string.find(FullResult,"item")+12
idend=string.find(FullResult,",",idstart)-1
PausedID=string.sub(FullResult,idstart,idend)
print(PausedType.." "..PausedID)
end
if PausedType == 'movie' or PausedType == 'episode' then
--stop lounge kodi so it updates resume point
sendToKodi('192.168.2.105','{"jsonrpc":"2.0","id":1,"method":"Player.Stop","params":{"playerid":1}}')
--turn bedroom tv On
commandArray['Bedroom TV']='Set Level 10'
--wait a small delay to allow resume point to be updated in kodi sql database
sleep(2)
--start movie/tv show playing with resume
if PausedType == 'movie' then
sendToKodi('192.168.2.140','{"jsonrpc":"2.0","id":"1","method":"Player.Open","params":{"item":{"movieid":'..PausedID..'},"options":{"resume":true}}}')
end
if PausedType == 'episode' then
sendToKodi('192.168.2.140','{"jsonrpc": "2.0","id": "1","method":"Player.Open","params":{"item":{"episodeid":'..PausedID..'},"options":{"resume":true}}}')
end
--wait a small delay to allow kodi to get ready to pause
sleep(1)
--pause it, ready to watch!
sendToKodi('192.168.2.140','{"jsonrpc":"2.0","id":1,"method":"Player.PlayPause","params":{"playerid":1}}')
end
end
end
return commandArray