diff --git a/autoProcessMedia.cfg.spec b/autoProcessMedia.cfg.spec index f99be837..b80e59bf 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 eb23a558..8200f977 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 @@ -246,10 +248,10 @@ def initialize(section=None): if not makeDir(LOG_DIR): print("No log folder, logging to screen only") - MYAPP = RunningProcess() - while MYAPP.alreadyrunning(): - print("Waiting for existing session to end") - time.sleep(30) + #MYAPP = RunningProcess() + #while MYAPP.alreadyrunning(): + # print("Waiting for existing session to end") + # time.sleep(30) try: locale.setlocale(locale.LC_ALL, "") diff --git a/core/autoProcess/autoProcessTV.py b/core/autoProcess/autoProcessTV.py index 75ff4805..8e14a2e2 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,9 +282,10 @@ 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} - s.post(login, data=login_params, stream=True, verify=False, timeout=(30, 60)) + if not apikey: + login = "{0}{1}:{2}{3}/login".format(protocol, host, port, web_root) + login_params = {'username': username, 'password': password} + 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) @@ -287,15 +302,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 1f5b418f..2deaf3b6 100644 --- a/core/nzbToMediaAutoFork.py +++ b/core/nzbToMediaAutoFork.py @@ -52,8 +52,14 @@ 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: @@ -71,8 +77,12 @@ def autoFork(section, 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):