diff --git a/autoProcessMedia.cfg.spec b/autoProcessMedia.cfg.spec index 62aef675..c2671a7b 100644 --- a/autoProcessMedia.cfg.spec +++ b/autoProcessMedia.cfg.spec @@ -107,6 +107,7 @@ enabled = 0 host = localhost port = 8081 + apikey = username = password = ###### ADVANCED USE - ONLY EDIT IF YOU KNOW WHAT YOU'RE DOING ###### diff --git a/core/__init__.py b/core/__init__.py index 8b44c1db..a6e627d2 100644 --- a/core/__init__.py +++ b/core/__init__.py @@ -2,6 +2,7 @@ from __future__ import print_function +import itertools import locale import os import re @@ -63,6 +64,7 @@ FORK_FAILED = "failed" FORK_FAILED_TORRENT = "failed-torrent" FORK_SICKRAGETV = "SickRageTV" FORK_SICKRAGE = "SickRage" +FORK_SICKRAGE_API = "SiCKRAGE-api" FORK_MEDUSA = "Medusa" FORK_SICKGEAR = "SickGear" FORKS[FORK_DEFAULT] = {"dir": None} @@ -70,10 +72,10 @@ FORKS[FORK_FAILED] = {"dirName": None, "failed": None} FORKS[FORK_FAILED_TORRENT] = {"dir": None, "failed": None, "process_method": None} FORKS[FORK_SICKRAGETV] = {"proc_dir": None, "failed": None, "process_method": None, "force": None, "delete_on": None} FORKS[FORK_SICKRAGE] = {"proc_dir": None, "failed": None, "process_method": None, "force": None, "delete_on": None, "force_next": None} +FORKS[FORK_SICKRAGE_API] = {"path": None, "failed": None, "process_method": None, "force_replace": None, "return_data": None, "type": None, "delete": None, "force_next": None} FORKS[FORK_MEDUSA] = {"proc_dir": None, "failed": None, "process_method": None, "force": None, "delete_on": None, "ignore_subs":None} FORKS[FORK_SICKGEAR] = {"dir": None, "failed": None, "process_method": None, "force": None} -ALL_FORKS = {"dir": None, "dirName": None, "proc_dir": None, "process_directory": None, "failed": None, "process_method": None, "force": None, - "delete_on": None, "ignore_subs": None, "force_next": None} +ALL_FORKS = {k:None for k in set(list(itertools.chain.from_iterable([FORKS[x].keys() for x in FORKS.keys()])))} # NZBGet Exit Codes NZBGET_POSTPROCESS_PARCHECK = 92 diff --git a/core/autoProcess/autoProcessTV.py b/core/autoProcess/autoProcessTV.py index 9ce67044..e157be74 100644 --- a/core/autoProcess/autoProcessTV.py +++ b/core/autoProcess/autoProcessTV.py @@ -189,8 +189,19 @@ class autoProcessTV(object): if param == "failed": fork_params[param] = failed del fork_params['proc_type'] + if "type" in fork_params: + del fork_params['type'] - if param in ["dirName", "dir", "proc_dir", "process_directory"]: + if param == "return_data": + fork_params[param] = 0 + del fork_params['quiet'] + + if param == "type": + fork_params[param] = 'manual' + if "proc_type" in fork_params: + del fork_params['proc_type'] + + if param in ["dirName", "dir", "proc_dir", "process_directory", "path"]: fork_params[param] = dirName if remote_path: fork_params[param] = remoteDir(dirName) @@ -201,13 +212,13 @@ class autoProcessTV(object): else: del fork_params[param] - if param == "force": + if param in ["force", "force_replace"]: if force: fork_params[param] = force else: del fork_params[param] - if param == "delete_on": + if param in ["delete_on", "delete"]: if delete_on: fork_params[param] = delete_on else: @@ -248,7 +259,10 @@ class autoProcessTV(object): url = None if section == "SickBeard": - url = "{0}{1}:{2}{3}/home/postprocess/processEpisode".format(protocol, host, port, web_root) + if apikey: + url = "{0}{1}:{2}{3}/api/{4}/?cmd=postprocess".format(protocol, host, port, web_root, apikey) + else: + url = "{0}{1}:{2}{3}/home/postprocess/processEpisode".format(protocol, host, port, web_root) elif section == "NzbDrone": url = "{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) @@ -268,12 +282,13 @@ class autoProcessTV(object): if section == "SickBeard": logger.debug("Opening URL: {0} with params: {1}".format(url, fork_params), section) s = requests.Session() - login = "{0}{1}:{2}{3}/login".format(protocol, host, port, web_root) - login_params = {'username': username, 'password': password} - r = s.get(login, verify=False, timeout=(30,60)) - if r.status_code == 401 and r.cookies.get('_xsrf'): - login_params['_xsrf'] = r.cookies.get('_xsrf') - s.post(login, data=login_params, stream=True, verify=False, timeout=(30, 60)) + if not apikey and username and password: + login = "{0}{1}:{2}{3}/login".format(protocol, host, port, web_root) + login_params = {'username': username, 'password': password} + r = s.get(login, verify=False, timeout=(30,60)) + if r.status_code == 401 and r.cookies.get('_xsrf'): + login_params['_xsrf'] = r.cookies.get('_xsrf') + s.post(login, data=login_params, stream=True, verify=False, timeout=(30, 60)) r = s.get(url, auth=(username, password), params=fork_params, stream=True, verify=False, timeout=(30, 1800)) elif section == "NzbDrone": logger.debug("Opening URL: {0} with data: {1}".format(url, data), section) @@ -290,15 +305,20 @@ class autoProcessTV(object): Queued = False Started = False if section == "SickBeard": - for line in r.iter_lines(): - if line: - logger.postprocess("{0}".format(line), section) - if "Moving file from" in line: - inputName = os.path.split(line)[1] - if "added to the queue" in line: - Queued = True - if "Processing succeeded" in line or "Successfully processed" in line: - Success = True + if apikey: + if r.json()['result'] == 'success': + Success = True + else: + for line in r.iter_lines(): + if line: + logger.postprocess("{0}".format(line), section) + if "Moving file from" in line: + inputName = os.path.split(line)[1] + if "added to the queue" in line: + Queued = True + if "Processing succeeded" in line or "Successfully processed" in line: + Success = True + if Queued: time.sleep(60) elif section == "NzbDrone": diff --git a/core/nzbToMediaAutoFork.py b/core/nzbToMediaAutoFork.py index e38f735c..39e676d0 100644 --- a/core/nzbToMediaAutoFork.py +++ b/core/nzbToMediaAutoFork.py @@ -54,12 +54,18 @@ def autoFork(section, inputCategory): logger.info("Attempting to auto-detect {category} fork".format(category=inputCategory)) # define the order to test. Default must be first since the default fork doesn't reject parameters. # then in order of most unique parameters. - url = "{protocol}{host}:{port}{root}/home/postprocess/".format( - protocol=protocol, host=host, port=port, root=web_root) + + if apikey: + url = "{protocol}{host}:{port}{root}/api/{apikey}/?cmd=help&subject=postprocess".format( + protocol=protocol, host=host, port=port, root=web_root, apikey=apikey) + else: + url = "{protocol}{host}:{port}{root}/home/postprocess/".format( + protocol=protocol, host=host, port=port, root=web_root) + # attempting to auto-detect fork try: - if username and password: - s = requests.Session() + s = requests.Session() + if not apikey and username and password: login = "{protocol}{host}:{port}{root}/login".format( protocol=protocol, host=host, port=port, root=web_root) login_params = {'username': username, 'password': password} @@ -67,17 +73,19 @@ def autoFork(section, inputCategory): if r.status_code == 401 and r.cookies.get('_xsrf'): login_params['_xsrf'] = r.cookies.get('_xsrf') s.post(login, data=login_params, stream=True, verify=False) - r = s.get(url, auth=(username, password), verify=False) - else: - r = requests.get(url, verify=False) + r = s.get(url, auth=(username, password), verify=False) except requests.ConnectionError: logger.info("Could not connect to {section}:{category} to perform auto-fork detection!".format (section=section, category=inputCategory)) r = [] if r and r.ok: for param in params: - if not 'name="{param}"'.format(param=param) in r.text: - rem_params.append(param) + if apikey: + if param not in r.json()['data']['optionalParameters'].keys(): + rem_params.append(param) + else: + if 'name="{param}"'.format(param=param) not in r.text: + rem_params.append(param) for param in rem_params: params.pop(param) for fork in sorted(iteritems(core.FORKS), reverse=False):