Merge pull request #1895 from lsellens/upstream

SABnzdb-Suite fix keep awake option.
This commit is contained in:
Stefan Saraev 2013-02-11 03:36:16 -08:00
commit 403e846d02

View File

@ -59,7 +59,7 @@ if sabNzbdLaunch:
sabNzbdApiKey = sabConfiguration['misc']['api_key'] sabNzbdApiKey = sabConfiguration['misc']['api_key']
sabNzbdUser = sabConfiguration['misc']['username'] sabNzbdUser = sabConfiguration['misc']['username']
sabNzbdPass = sabConfiguration['misc']['password'] sabNzbdPass = sabConfiguration['misc']['password']
sabNzbdQueue = 'http://' + sabNzbdAddress + '/sabnzbd/api?mode=queue&output=xml&apikey=' + sabNzbdApiKey + '&ma_username=' + sabNzbdUser + '&ma_password=' + sabNzbdUser sabNzbdQueue = 'http://' + sabNzbdAddress + '/api?mode=queue&output=xml&apikey=' + sabNzbdApiKey + '&ma_username=' + sabNzbdUser + '&ma_password=' + sabNzbdPass
# 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)
@ -83,29 +83,30 @@ while (not xbmc.abortRequested):
wakeHourIdx = int(__settings__.getSetting('SABNZBD_WAKE_AT')) wakeHourIdx = int(__settings__.getSetting('SABNZBD_WAKE_AT'))
# check if SABnzbd is downloading # check if SABnzbd is downloading
sabIsActive = False if shouldKeepAwake:
req = urllib2.Request(sabNzbdQueue) sabIsActive = False
try: handle = urllib2.urlopen(req) req = urllib2.Request(sabNzbdQueue)
except IOError, e: try: handle = urllib2.urlopen(req)
xbmc.log('SABnzbd-Suite: could not determine SABnzbds status', level=xbmc.LOGERROR) except IOError, e:
else: xbmc.log('SABnzbd-Suite: could not determine SABnzbds status', level=xbmc.LOGERROR)
queue = handle.read() else:
handle.close() queue = handle.read()
sabIsActive = (queue.find('<status>Downloading</status>') >= 0) handle.close()
sabIsActive = (queue.find('<status>Downloading</status>') >= 0)
# reset idle timer when we're close to idle sleep/shutdown # reset idle timer when we're close to idle sleep/shutdown
if (shouldKeepAwake and sabIsActive): if sabIsActive:
response = xbmc.executehttpapi("GetGUISetting(0;powermanagement.shutdowntime)").replace('<li>','') response = xbmc.executehttpapi("GetGUISetting(0;powermanagement.shutdowntime)").replace('<li>','')
shutdownTime = int(response) * 60 shutdownTime = int(response) * 60
idleTime = xbmc.getGlobalIdleTime() idleTime = xbmc.getGlobalIdleTime()
timeToShutdown = shutdownTime - idleTime timeToShutdown = shutdownTime - idleTime
if (sabIsActive and timeToShutdown <= checkInterval - timeout): if (timeToShutdown <= checkInterval - timeout):
xbmc.log('SABnzbd-Suite: still downloading. Resetting XBMC idle timer.') xbmc.log('SABnzbd-Suite: still downloading. Resetting XBMC idle timer.')
xbmc.executehttpapi("SendKey(0xF000)") xbmc.executehttpapi("SendKey(0xF000)")
# 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:
wakeHour = wakeHourIdx * 2 + 1 wakeHour = wakeHourIdx * 2 + 1
timeOfDay = datetime.time(hour=wakeHour) timeOfDay = datetime.time(hour=wakeHour)
now = datetime.datetime.now() now = datetime.datetime.now()