this task makes fun
so here it is, fully implemented in python and integrated in cube's plugin:
plugin, needed imports:
plugin, extra function:
Code:
def check_rec():
if pvr_hts.check_hts():
log("Found upcoming recordings")
return True
log("No upcoming recordings found")
return False
seperated python script for checking tvheadend, named pvr_hts.py in plugin root folder (the same folder as inhibit_shutdown.py):
Code:
#!/usr/bin/python
import time
import glob
import os
def check_hts():
current_time = int(time.time())
prevent_time = 300
rec_start = 0
rec_start_extra = 0
rec_stop = 0
rec_stop_extra = 0
recordings = glob.glob(os.path.expanduser('~') + '/.hts/tvheadend/dvr/log/*')
for record in recordings:
rec_file = open(record, 'r')
for line in rec_file:
tmp_line = line.strip()
items = tmp_line.split(':')
if items[0] == "\"start\"":
tmp_rec_start = int(items[1].strip().strip(','))
if items[0] == "\"start_extra\"":
tmp_rec_start_extra = int(items[1].strip().strip(','))
if items[0] == "\"stop\"":
tmp_rec_stop = int(items[1].strip().strip(','))
if items[0] == "\"stop_extra\"":
tmp_rec_stop_extra = int(items[1].strip().strip(','))
rec_file.close()
if (tmp_rec_stop+(tmp_rec_stop_extra*60) > current_time) and (tmp_rec_start > current_time):
if (rec_start == 0) or (tmp_rec_start < rec_start):
rec_start = tmp_rec_start
rec_stop = tmp_rec_stop
rec_start_extra = tmp_rec_start_extra*60
rec_stop_extra = tmp_rec_stop_extra*60
rec_start = rec_start-rec_start_extra
rec_stop = rec_stop+rec_stop_extra
if (rec_start != 0) and (0 < (rec_start-current_time) < prevent_time):
return True
return False
plugin, extra check:
Code:
while not xbmc.abortRequested:
if (check_rec() or check_services()):
xbmc.executebuiltin('InhibitIdleShutdown(true)')
else:
xbmc.executebuiltin('InhibitIdleShutdown(false)')
xbmc.sleep(sleep_time)
this will prevent standby if scheduled recording will record in
prevent_time (seconds, here: 5minutes). So my system won't go automatically to suspend if a recording is upcoming in the next
prevent_time seconds.
Of course, this can be more user friendly by implementing GUI options for
prevent_time and the backend used (pass some variables to my function). But due to the lack of installed backends and hardly freetime, I just implemented this for TVHeadend.
Feel free to implement a more general way of checking schedules.
why I did this:
my old mediacenter software had these functions included and I think they are very useful, e.g. the system supsends 5 seconds before a recording will start, mine won't wake up automatically... so it seems good to have a prevent for some systems.
Also, this is my first python script. If there is a way to do things better, please tell us...