From 58c998712fcca1addc5deb24dddc543844b883f1 Mon Sep 17 00:00:00 2001 From: Labrys of Knossos Date: Thu, 24 Nov 2022 23:33:17 -0500 Subject: [PATCH] Extract sabnzb processing from `nzbToMedia.main` -> `core.processor.sabnzbd` --- core/processor/sab.py | 67 +++++++++++++++++++++++++++++++++++++++++++ nzbToMedia.py | 35 +++------------------- 2 files changed, 71 insertions(+), 31 deletions(-) create mode 100644 core/processor/sab.py diff --git a/core/processor/sab.py b/core/processor/sab.py new file mode 100644 index 00000000..3e9f4050 --- /dev/null +++ b/core/processor/sab.py @@ -0,0 +1,67 @@ +import os + +from core import logger +from core.processor import nzb + + +def process_script(): + client_agent = 'sabnzbd' + logger.info('Script triggered from SABnzbd Version {0}.'.format( + os.environ['SAB_VERSION'])) + return nzb.process( + os.environ['SAB_COMPLETE_DIR'], + input_name=os.environ['SAB_FINAL_NAME'], + status=int(os.environ['SAB_PP_STATUS']), + client_agent=client_agent, + download_id=os.environ['SAB_NZO_ID'], + input_category=os.environ['SAB_CAT'], + failure_link=os.environ['SAB_FAILURE_URL'], + ) + + +def process_legacy(args): + # SABnzbd argv: + # 1 The final directory of the job (full path) + # 2 The original name of the NZB file + # 3 Clean version of the job name (no path info and '.nzb' removed) + # 4 Indexer's report number (if supported) + # 5 User-defined category + # 6 Group that the NZB was posted in e.g. alt.binaries.x + # 7 Status of post processing. + # 0 = OK + # 1 = failed verification + # 2 = failed unpack + # 3 = 1+2 + client_agent = 'sabnzbd' + logger.info('Script triggered from SABnzbd') + return nzb.process( + args[1], + input_name=args[2], + status=int(args[7]), + input_category=args[5], + client_agent=client_agent, + download_id='', + ) + + +def process_0717(args): + # SABnzbd argv: + # 1 The final directory of the job (full path) + # 2 The original name of the NZB file + # 3 Clean version of the job name (no path info and '.nzb' removed) + # 4 Indexer's report number (if supported) + # 5 User-defined category + # 6 Group that the NZB was posted in e.g. alt.binaries.x + # 7 Status of post processing. 0 = OK, 1=failed verification, 2=failed unpack, 3=1+2 + # 8 Failure URL + client_agent = 'sabnzbd' + logger.info('Script triggered from SABnzbd 0.7.17+') + return nzb.process( + args[1], + input_name=args[2], + status=int(args[7]), + input_category=args[5], + client_agent=client_agent, + download_id='', + failure_link=''.join(args[8:]), + ) diff --git a/nzbToMedia.py b/nzbToMedia.py index bb88ce0b..d561e6d9 100755 --- a/nzbToMedia.py +++ b/nzbToMedia.py @@ -733,7 +733,7 @@ cleanup.clean(cleanup.FOLDER_STRUCTURE) import core from core import logger -from core.processor import nzbget +from core.processor import nzbget, sab from core.processor.nzb import process from core.auto_process.common import ProcessResult from core.utils import ( @@ -769,40 +769,13 @@ def main(args, section=None): result = nzbget.process() # SABnzbd elif 'SAB_SCRIPT' in os.environ: - client_agent = 'sabnzbd' - logger.info('Script triggered from SABnzbd Version {0}.'.format(os.environ['SAB_VERSION'])) - result = process(os.environ['SAB_COMPLETE_DIR'], input_name=os.environ['SAB_FINAL_NAME'], status=int(os.environ['SAB_PP_STATUS']), - client_agent=client_agent, download_id=os.environ['SAB_NZO_ID'], input_category=os.environ['SAB_CAT'], - failure_link=os.environ['SAB_FAILURE_URL']) + result = sab.process_script() # SABnzbd Pre 0.7.17 elif len(args) == core.SABNZB_NO_OF_ARGUMENTS: - # SABnzbd argv: - # 1 The final directory of the job (full path) - # 2 The original name of the NZB file - # 3 Clean version of the job name (no path info and '.nzb' removed) - # 4 Indexer's report number (if supported) - # 5 User-defined category - # 6 Group that the NZB was posted in e.g. alt.binaries.x - # 7 Status of post processing. 0 = OK, 1=failed verification, 2=failed unpack, 3=1+2 - client_agent = 'sabnzbd' - logger.info('Script triggered from SABnzbd') - result = process(args[1], input_name=args[2], status=int(args[7]), input_category=args[5], client_agent=client_agent, - download_id='') + result = sab.process_legacy(args) # SABnzbd 0.7.17+ elif len(args) >= core.SABNZB_0717_NO_OF_ARGUMENTS: - # SABnzbd argv: - # 1 The final directory of the job (full path) - # 2 The original name of the NZB file - # 3 Clean version of the job name (no path info and '.nzb' removed) - # 4 Indexer's report number (if supported) - # 5 User-defined category - # 6 Group that the NZB was posted in e.g. alt.binaries.x - # 7 Status of post processing. 0 = OK, 1=failed verification, 2=failed unpack, 3=1+2 - # 8 Failure URL - client_agent = 'sabnzbd' - logger.info('Script triggered from SABnzbd 0.7.17+') - result = process(args[1], input_name=args[2], status=int(args[7]), input_category=args[5], client_agent=client_agent, - download_id='', failure_link=''.join(args[8:])) + result = sab.process_0717(args) # Generic program elif len(args) > 5 and args[5] == 'generic': logger.info('Script triggered from generic program')