Add some error handling to sabnzbd statuscheck
This commit is contained in:
@@ -2,8 +2,8 @@ from couchpotato.core.downloaders.base import Downloader
|
|||||||
from couchpotato.core.helpers.encoding import tryUrlencode
|
from couchpotato.core.helpers.encoding import tryUrlencode
|
||||||
from couchpotato.core.helpers.variable import cleanHost
|
from couchpotato.core.helpers.variable import cleanHost
|
||||||
from couchpotato.core.logger import CPLog
|
from couchpotato.core.logger import CPLog
|
||||||
import traceback
|
|
||||||
import json
|
import json
|
||||||
|
import traceback
|
||||||
|
|
||||||
log = CPLog(__name__)
|
log = CPLog(__name__)
|
||||||
|
|
||||||
@@ -91,10 +91,13 @@ class Sabnzbd(Downloader):
|
|||||||
log.error('Failed parsing json status: %s', traceback.format_exc())
|
log.error('Failed parsing json status: %s', traceback.format_exc())
|
||||||
return False
|
return False
|
||||||
|
|
||||||
for slot in history['queue']['slots']:
|
try:
|
||||||
log.debug('Found %s in SabNZBd queue, which is %s, with %s left', (slot['filename'], slot['status'], slot['timeleft']))
|
for slot in history['queue']['slots']:
|
||||||
if slot['filename'] == nzbname:
|
log.debug('Found %s in SabNZBd queue, which is %s, with %s left', (slot['filename'], slot['status'], slot['timeleft']))
|
||||||
return slot['status'].lower()
|
if slot['filename'] == nzbname:
|
||||||
|
return slot['status'].lower()
|
||||||
|
except:
|
||||||
|
log.debug('No items in queue: %s', (traceback.format_exc()))
|
||||||
|
|
||||||
# Go through history items
|
# Go through history items
|
||||||
params = {
|
params = {
|
||||||
@@ -118,45 +121,48 @@ class Sabnzbd(Downloader):
|
|||||||
log.error('Failed parsing history json: %s', traceback.format_exc())
|
log.error('Failed parsing history json: %s', traceback.format_exc())
|
||||||
return
|
return
|
||||||
|
|
||||||
for slot in history['history']['slots']:
|
try:
|
||||||
log.debug('Found %s in SabNZBd history, which has %s', (slot['name'], slot['status']))
|
for slot in history['history']['slots']:
|
||||||
if slot['name'] == nzbname:
|
log.debug('Found %s in SabNZBd history, which has %s', (slot['name'], slot['status']))
|
||||||
# Note: if post process even if failed is on in SabNZBd, it will complete with a fail message
|
if slot['name'] == nzbname:
|
||||||
if slot['status'] == 'Failed' or (slot['status'] == 'Completed' and slot['fail_message'].strip()):
|
# Note: if post process even if failed is on in SabNZBd, it will complete with a fail message
|
||||||
|
if slot['status'] == 'Failed' or (slot['status'] == 'Completed' and slot['fail_message'].strip()):
|
||||||
|
|
||||||
# Delete failed download
|
# Delete failed download
|
||||||
if self.conf('delete_failed', default = True):
|
if self.conf('delete_failed', default = True):
|
||||||
|
|
||||||
log.info('%s failed downloading, deleting...', slot['name'])
|
log.info('%s failed downloading, deleting...', slot['name'])
|
||||||
params = {
|
params = {
|
||||||
'apikey': self.conf('api_key'),
|
'apikey': self.conf('api_key'),
|
||||||
'mode': 'history',
|
'mode': 'history',
|
||||||
'name': 'delete',
|
'name': 'delete',
|
||||||
'del_files': '1',
|
'del_files': '1',
|
||||||
'value': slot['nzo_id']
|
'value': slot['nzo_id']
|
||||||
}
|
}
|
||||||
url = cleanHost(self.conf('host')) + "api?" + tryUrlencode(params)
|
url = cleanHost(self.conf('host')) + "api?" + tryUrlencode(params)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
sab = self.urlopen(url, timeout = 60, show_error = False)
|
sab = self.urlopen(url, timeout = 60, show_error = False)
|
||||||
except:
|
except:
|
||||||
log.error('Failed deleting: %s', traceback.format_exc())
|
log.error('Failed deleting: %s', traceback.format_exc())
|
||||||
return False
|
return False
|
||||||
|
|
||||||
result = sab.strip()
|
result = sab.strip()
|
||||||
if not result:
|
if not result:
|
||||||
log.error("SABnzbd didn't return anything.")
|
log.error("SABnzbd didn't return anything.")
|
||||||
|
|
||||||
log.debug("Result text from SAB: " + result[:40])
|
log.debug("Result text from SAB: " + result[:40])
|
||||||
if result == "ok":
|
if result == "ok":
|
||||||
log.info('SabNZBd deleted failed release %s successfully.', slot['name'])
|
log.info('SabNZBd deleted failed release %s successfully.', slot['name'])
|
||||||
elif result == "Missing authentication":
|
elif result == "Missing authentication":
|
||||||
log.error("Incorrect username/password or API?.")
|
log.error("Incorrect username/password or API?.")
|
||||||
else:
|
else:
|
||||||
log.error("Unknown error: " + result[:40])
|
log.error("Unknown error: " + result[:40])
|
||||||
|
|
||||||
return 'failed'
|
return 'failed'
|
||||||
else:
|
else:
|
||||||
return slot['status'].lower()
|
return slot['status'].lower()
|
||||||
|
except:
|
||||||
|
log.debug('No items in history: %s', (traceback.format_exc()))
|
||||||
|
|
||||||
return 'not_found'
|
return 'not_found'
|
||||||
|
|||||||
Reference in New Issue
Block a user