mirror of
https://github.com/LibreELEC/LibreELEC.tv.git
synced 2025-07-28 13:16:41 +00:00
SABnzbd-Suite: Prevent idle shutdown on verify/repair/extract
This commit is contained in:
parent
1d525659cc
commit
f6db055fc6
@ -40,9 +40,10 @@ __stop__ = xbmc.translatePath( os.path.join( __cwd__, 'bin', "SABnzbd-Suit
|
|||||||
#make binary files executable in adson bin folder
|
#make binary files executable in adson bin folder
|
||||||
subprocess.Popen("chmod -R +x " + __cwd__ + "/bin/*" , shell=True, close_fds=True)
|
subprocess.Popen("chmod -R +x " + __cwd__ + "/bin/*" , shell=True, close_fds=True)
|
||||||
|
|
||||||
checkInterval = 120
|
checkInterval = 240
|
||||||
timeout = 20
|
timeout = 20
|
||||||
wake_times = ['01:00','03:00','05:00','07:00','09:00','11:00','13:00','15:00','17:00','19:00','21:00','23:00']
|
wake_times = ['01:00','03:00','05:00','07:00','09:00','11:00','13:00','15:00','17:00','19:00','21:00','23:00']
|
||||||
|
idleTimer = 0
|
||||||
|
|
||||||
# Launch Suite
|
# Launch Suite
|
||||||
subprocess.call(['python',__start__])
|
subprocess.call(['python',__start__])
|
||||||
@ -62,6 +63,9 @@ if sabNzbdLaunch:
|
|||||||
sabNzbdUser = sabConfiguration['misc']['username']
|
sabNzbdUser = sabConfiguration['misc']['username']
|
||||||
sabNzbdPass = sabConfiguration['misc']['password']
|
sabNzbdPass = sabConfiguration['misc']['password']
|
||||||
sabNzbdQueue = 'http://' + sabNzbdAddress + '/api?mode=queue&output=xml&apikey=' + sabNzbdApiKey + '&ma_username=' + sabNzbdUser + '&ma_password=' + sabNzbdPass
|
sabNzbdQueue = 'http://' + sabNzbdAddress + '/api?mode=queue&output=xml&apikey=' + sabNzbdApiKey + '&ma_username=' + sabNzbdUser + '&ma_password=' + sabNzbdPass
|
||||||
|
sabNzbdHistory = 'http://' + sabNzbdAddress + '/api?mode=history&output=xml&apikey=' + sabNzbdApiKey + '&ma_username=' + sabNzbdUser + '&ma_password=' + sabNzbdPass
|
||||||
|
sabNzbdQueueKeywords = ['<status>Downloading</status>', '<status>Fetching</status>']
|
||||||
|
sabNzbdHistoryKeywords = ['<status>Repairing</status>', '<status>Verifying</status>', '<status>Extracting</status>']
|
||||||
|
|
||||||
# start checking SABnzbd for activity and prevent sleeping if necessary
|
# start checking SABnzbd for activity and prevent sleeping if necessary
|
||||||
socket.setdefaulttimeout(timeout)
|
socket.setdefaulttimeout(timeout)
|
||||||
@ -86,21 +90,38 @@ while (not xbmc.abortRequested):
|
|||||||
|
|
||||||
# check if SABnzbd is downloading
|
# check if SABnzbd is downloading
|
||||||
if shouldKeepAwake:
|
if shouldKeepAwake:
|
||||||
|
idleTimer += 1
|
||||||
|
# check SABnzbd every ~60s (240 cycles)
|
||||||
|
if idleTimer == checkInterval:
|
||||||
sabIsActive = False
|
sabIsActive = False
|
||||||
|
idleTimer = 0
|
||||||
req = urllib2.Request(sabNzbdQueue)
|
req = urllib2.Request(sabNzbdQueue)
|
||||||
try: handle = urllib2.urlopen(req)
|
try: handle = urllib2.urlopen(req)
|
||||||
except IOError, e:
|
except IOError, e:
|
||||||
xbmc.log('SABnzbd-Suite: could not determine SABnzbds status', level=xbmc.LOGERROR)
|
xbmc.log('SABnzbd-Suite: could not determine SABnzbds queue status', level=xbmc.LOGERROR)
|
||||||
else:
|
else:
|
||||||
queue = handle.read()
|
queue = handle.read()
|
||||||
handle.close()
|
handle.close()
|
||||||
sabIsActive = (queue.find('<status>Downloading</status>') >= 0)
|
if any(x in queue for x in sabNzbdQueueKeywords):
|
||||||
|
sabIsActive = True
|
||||||
|
|
||||||
# reset idle timer when we're close to idle sleep/shutdown
|
req = urllib2.Request(sabNzbdHistory)
|
||||||
|
try: handle = urllib2.urlopen(req)
|
||||||
|
except IOError, e:
|
||||||
|
xbmc.log('SABnzbd-Suite: could not determine SABnzbds history status', level=xbmc.LOGERROR)
|
||||||
|
else:
|
||||||
|
history = handle.read()
|
||||||
|
handle.close()
|
||||||
|
if any(x in history for x in sabNzbdHistoryKeywords):
|
||||||
|
sabIsActive = True
|
||||||
|
|
||||||
|
# reset idle timer if queue is downloading/reparing/verifying/extracting
|
||||||
if sabIsActive:
|
if sabIsActive:
|
||||||
xbmc.executebuiltin('InhibitIdleShutdown(true)')
|
xbmc.executebuiltin('InhibitIdleShutdown(true)')
|
||||||
|
xbmc.log('preventing sleep')
|
||||||
else:
|
else:
|
||||||
xbmc.executebuiltin('InhibitIdleShutdown(false)')
|
xbmc.executebuiltin('InhibitIdleShutdown(false)')
|
||||||
|
xbmc.log('not preventing sleep')
|
||||||
|
|
||||||
# calculate and set the time to wake up at (if any)
|
# calculate and set the time to wake up at (if any)
|
||||||
if wakePeriodically:
|
if wakePeriodically:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user