mirror of
https://github.com/clinton-hall/nzbToMedia.git
synced 2025-07-15 01:32:53 -07:00
add Raddar command status monitoring and CDH handling. Fixes #1170
This commit is contained in:
parent
a0f28804f6
commit
33fb4ce331
1 changed files with 60 additions and 2 deletions
|
@ -104,6 +104,39 @@ class autoProcessMovie(object):
|
||||||
|
|
||||||
return results
|
return results
|
||||||
|
|
||||||
|
def command_complete(self, url, params, headers, section):
|
||||||
|
try:
|
||||||
|
r = requests.get(url, params=params, headers=headers, stream=True, verify=False, timeout=(30, 60))
|
||||||
|
except requests.ConnectionError:
|
||||||
|
logger.error("Unable to open URL: {0}".format(url), section)
|
||||||
|
return None
|
||||||
|
if r.status_code not in [requests.codes.ok, requests.codes.created, requests.codes.accepted]:
|
||||||
|
logger.error("Server returned status {0}".format(r.status_code), section)
|
||||||
|
return None
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
return r.json()['state']
|
||||||
|
except (ValueError, KeyError):
|
||||||
|
# ValueError catches simplejson's JSONDecodeError and json's ValueError
|
||||||
|
logger.error("{0} did not return expected json data.".format(section), section)
|
||||||
|
return None
|
||||||
|
|
||||||
|
def CDH(self, url2, headers, section="MAIN"):
|
||||||
|
try:
|
||||||
|
r = requests.get(url2, params={}, headers=headers, stream=True, verify=False, timeout=(30, 60))
|
||||||
|
except requests.ConnectionError:
|
||||||
|
logger.error("Unable to open URL: {0}".format(url2), section)
|
||||||
|
return False
|
||||||
|
if r.status_code not in [requests.codes.ok, requests.codes.created, requests.codes.accepted]:
|
||||||
|
logger.error("Server returned status {0}".format(r.status_code), section)
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
return r.json().get("enableCompletedDownloadHandling", False)
|
||||||
|
except ValueError:
|
||||||
|
# ValueError catches simplejson's JSONDecodeError and json's ValueError
|
||||||
|
return False
|
||||||
|
|
||||||
def process(self, section, dirName, inputName=None, status=0, clientAgent="manual", download_id="", inputCategory=None, failureLink=None):
|
def process(self, section, dirName, inputName=None, status=0, clientAgent="manual", download_id="", inputCategory=None, failureLink=None):
|
||||||
|
|
||||||
cfg = dict(core.CFG[section][inputCategory])
|
cfg = dict(core.CFG[section][inputCategory])
|
||||||
|
@ -132,6 +165,7 @@ class autoProcessMovie(object):
|
||||||
baseURL = "{0}{1}:{2}{3}/api/{4}/".format(protocol, host, port, web_root, apikey)
|
baseURL = "{0}{1}:{2}{3}/api/{4}/".format(protocol, host, port, web_root, apikey)
|
||||||
if section == "Radarr":
|
if section == "Radarr":
|
||||||
baseURL = "{0}{1}:{2}{3}/api/command".format(protocol, host, port, web_root)
|
baseURL = "{0}{1}:{2}{3}/api/command".format(protocol, host, port, web_root)
|
||||||
|
url2 = "{0}{1}:{2}{3}/api/config/downloadClient".format(protocol, host, port, web_root)
|
||||||
headers = {'X-Api-Key': apikey}
|
headers = {'X-Api-Key': apikey}
|
||||||
if not apikey:
|
if not apikey:
|
||||||
logger.info('No CouchPotato or Radarr apikey entered. Performing transcoder functions only')
|
logger.info('No CouchPotato or Radarr apikey entered. Performing transcoder functions only')
|
||||||
|
@ -273,6 +307,14 @@ class autoProcessMovie(object):
|
||||||
return [0, "{0}: Successfully post-processed {1}".format(section, inputName)]
|
return [0, "{0}: Successfully post-processed {1}".format(section, inputName)]
|
||||||
elif section == "Radarr":
|
elif section == "Radarr":
|
||||||
logger.postprocess("Radarr response: {0}".format(result['state']))
|
logger.postprocess("Radarr response: {0}".format(result['state']))
|
||||||
|
try:
|
||||||
|
res = json.loads(r.content)
|
||||||
|
scan_id = int(res['id'])
|
||||||
|
logger.debug("Scan started with id: {0}".format(scan_id), section)
|
||||||
|
Started = True
|
||||||
|
except Exception as e:
|
||||||
|
logger.warning("No scan id was returned due to: {0}".format(e), section)
|
||||||
|
scan_id = None
|
||||||
else:
|
else:
|
||||||
logger.error("FAILED: {0} scan was unable to finish for folder {1}. exiting!".format(method, dirName),
|
logger.error("FAILED: {0} scan was unable to finish for folder {1}. exiting!".format(method, dirName),
|
||||||
section)
|
section)
|
||||||
|
@ -353,6 +395,7 @@ class autoProcessMovie(object):
|
||||||
logger.postprocess("Checking for status change, please stand by ...", section)
|
logger.postprocess("Checking for status change, please stand by ...", section)
|
||||||
if section == "CouchPotato":
|
if section == "CouchPotato":
|
||||||
release = self.get_release(baseURL, imdbid, download_id, release_id)
|
release = self.get_release(baseURL, imdbid, download_id, release_id)
|
||||||
|
scan_id = None
|
||||||
else:
|
else:
|
||||||
release = None
|
release = None
|
||||||
if release:
|
if release:
|
||||||
|
@ -368,6 +411,18 @@ class autoProcessMovie(object):
|
||||||
return [0, "{0}: Successfully post-processed {1}".format(section, inputName)]
|
return [0, "{0}: Successfully post-processed {1}".format(section, inputName)]
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
elif scan_id:
|
||||||
|
url = "{0}/{1}".format(baseURL, scan_id)
|
||||||
|
command_status = self.command_complete(url, params, headers, section)
|
||||||
|
if command_status:
|
||||||
|
logger.debug("The Scan command return status: {0}".format(command_status), section)
|
||||||
|
if command_status in ['completed']:
|
||||||
|
logger.debug("The Scan command has completed successfully. Renaming was successful.", section)
|
||||||
|
return [0, "{0}: Successfully post-processed {1}".format(section, inputName)]
|
||||||
|
elif command_status in ['failed']:
|
||||||
|
logger.debug("The Scan command has failed. Renaming was not successful.", section)
|
||||||
|
# return [1, "%s: Failed to post-process %s" % (section, inputName) ]
|
||||||
|
|
||||||
if not os.path.isdir(dirName):
|
if not os.path.isdir(dirName):
|
||||||
logger.postprocess("SUCCESS: Input Directory [{0}] has been processed and removed".format(
|
logger.postprocess("SUCCESS: Input Directory [{0}] has been processed and removed".format(
|
||||||
dirName), section)
|
dirName), section)
|
||||||
|
@ -378,10 +433,13 @@ class autoProcessMovie(object):
|
||||||
dirName), section)
|
dirName), section)
|
||||||
return [0, "{0}: Successfully post-processed {1}".format(section, inputName)]
|
return [0, "{0}: Successfully post-processed {1}".format(section, inputName)]
|
||||||
|
|
||||||
# pause and let CouchPotatoServer catch its breath
|
# pause and let CouchPotatoServer/Radarr catch its breath
|
||||||
time.sleep(10 * wait_for)
|
time.sleep(10 * wait_for)
|
||||||
|
|
||||||
# The status hasn't changed. we have waited 2 minutes which is more than enough. uTorrent can resume seeding now.
|
# The status hasn't changed. we have waited wait_for minutes which is more than enough. uTorrent can resume seeding now.
|
||||||
|
if section == "Radarr" and self.CDH(url2, headers, section=section):
|
||||||
|
logger.debug("The Scan command did not return status completed, but complete Download Handling is enabled. Passing back to {0}.".format(section), section)
|
||||||
|
return [status, "{0}: Complete DownLoad Handling is enabled. Passing back to {1}".format(section, section)]
|
||||||
logger.warning(
|
logger.warning(
|
||||||
"{0} does not appear to have changed status after {1} minutes, Please check your logs.".format(inputName, wait_for),
|
"{0} does not appear to have changed status after {1} minutes, Please check your logs.".format(inputName, wait_for),
|
||||||
section)
|
section)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue