Added SiCKRAGE API support for post-processing

This commit is contained in:
echel0n 2018-06-21 19:53:48 -07:00
commit 5f2a5499b8
4 changed files with 59 additions and 26 deletions

View file

@ -107,6 +107,7 @@
enabled = 0
host = localhost
port = 8081
apikey =
username =
password =
###### ADVANCED USE - ONLY EDIT IF YOU KNOW WHAT YOU'RE DOING ######

View file

@ -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, "")

View file

@ -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,6 +259,9 @@ class autoProcessTV(object):
url = None
if section == "SickBeard":
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)
@ -268,6 +282,7 @@ class autoProcessTV(object):
if section == "SickBeard":
logger.debug("Opening URL: {0} with params: {1}".format(url, fork_params), section)
s = requests.Session()
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))
@ -287,6 +302,10 @@ class autoProcessTV(object):
Queued = False
Started = False
if section == "SickBeard":
if apikey:
if r.json()['result'] == 'success':
Success = True
else:
for line in r.iter_lines():
if line:
logger.postprocess("{0}".format(line), section)
@ -296,6 +315,7 @@ class autoProcessTV(object):
Queued = True
if "Processing succeeded" in line or "Successfully processed" in line:
Success = True
if Queued:
time.sleep(60)
elif section == "NzbDrone":

View file

@ -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.
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,7 +77,11 @@ def autoFork(section, inputCategory):
r = []
if r and r.ok:
for param in params:
if not 'name="{param}"'.format(param=param) in r.text:
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)