From 2a0407b37f2a5acf783a98999d81cfd9a95d2067 Mon Sep 17 00:00:00 2001 From: dnzbk Date: Mon, 5 May 2025 11:21:41 +0300 Subject: [PATCH 1/3] Add: additional options for setting post-processing params on completion success/failure --- main.py | 53 ++++++++++++++++++++++++++++++++++++++++++++------- manifest.json | 42 ++++++++++++++++++++++++++++++---------- 2 files changed, 78 insertions(+), 17 deletions(-) diff --git a/main.py b/main.py index 93a615a..67818b1 100644 --- a/main.py +++ b/main.py @@ -51,6 +51,16 @@ + "does not work" ) FORCE_FAILURE = os.environ.get("NZBPO_ForceFailure", "No") == "Yes" +PP_PARAMS_ON_SUCCESS = [ + p.strip() + for p in os.environ.get("NZBPO_SetParamsOnSuccess", "").split(",") + if os.environ.get("NZBPO_SetParamsOnSuccess", "") +] +PP_PARAMS_ON_FAILURE = [ + p.strip() + for p in os.environ.get("NZBPO_SetParamsOnFailure", "").split(",") + if os.environ.get("NZBPO_SetParamsOnFailure", "") +] CATEGORIES = os.environ.get("NZBPO_Categories", "").lower().split(",") CATEGORIES = [c.strip(" ") for c in CATEGORIES] SERVERS = os.environ.get("NZBPO_Servers", "").lower().split(",") @@ -231,6 +241,30 @@ def get_nzb_filename(parameters): return p["Value"] +def set_pp_parameters(nzb_id, params) -> None: + """ + Sets post-processing parameters for a specific group (NZB) in the NZBGet queue. + """ + + if not params: + return + + try: + NZBGet = connect_to_nzbget() + except Exception as e: + print(f"[ERROR] Failed to connect to NZBGet: {e}") + return + + if VERBOSE: + print(f"[V] Setting post-processing parameters for group {nzb_id}: {str(params)}") + + for param in params: + try: + NZBGet.editqueue("GroupSetParameter", 0, param, [int(nzb_id)]) + except Exception as e: + print(f"[ERROR] Error setting parameter {param} for {nzb_id}: {e}") + + def get_max_failed_limit(critical_health) -> float: return round(100 - critical_health / 10.0, 1) @@ -249,7 +283,7 @@ def get_nzb_status(nzb): # collect rar msg ids that need to be checked rar_msg_ids = get_nzb_data(nzb[1]) if rar_msg_ids == -1: # no such NZB file - succes = True # file send back to queue + success = True # file send back to queue print( "[WARNING] The NZB file " + str(nzb[1]) @@ -258,7 +292,7 @@ def get_nzb_status(nzb): ) unpause_nzb(nzb[0]) # unpause based on NZBGet ID elif rar_msg_ids == -2: # empty NZB or no group - succes = True # file send back to queue + success = True # file send back to queue print( "[WARNING] The NZB file " + str(nzb[1]) @@ -267,7 +301,7 @@ def get_nzb_status(nzb): ) unpause_nzb(nzb[0]) # unpause based on NZBGet ID elif rar_msg_ids == -3: # NZB without RAR files. - succes = True # file send back to queue + success = True # file send back to queue print( "[WARNING] The NZB file " + str(nzb[1]) @@ -291,15 +325,20 @@ def get_nzb_status(nzb): failed_ratio < failed_limit and (failed_ratio < MAX_FAILURE or MAX_FAILURE == 0) ) or failed_ratio == 0: - succes = True + success = True print('Resuming: "' + nzb[1] + '"') sys.stdout.flush() + + set_pp_parameters(nzb[0], PP_PARAMS_ON_SUCCESS) unpause_nzb(nzb[0]) # unpause based on NZBGet ID elif ( failed_ratio >= failed_limit or (failed_ratio >= MAX_FAILURE and MAX_FAILURE > 0) ) and nzb[2] < (int(time.time()) - int(AGE_LIMIT_SEC)): - succes = False + success = False + + set_pp_parameters(nzb[0], PP_PARAMS_ON_FAILURE) + if VERBOSE: if not FORCE_FAILURE: print('[V] Marked as BAD: "' + nzb[1] + '"') @@ -309,7 +348,7 @@ def get_nzb_status(nzb): else: mark_bad(nzb[0]) else: - succes = False + success = False # dupekey should not be '', that would mean it is not added by RSS if CHECK_DUPES != "no" and nzb[4] != "": if get_dupe_nzb_status(nzb): @@ -334,7 +373,7 @@ def get_nzb_status(nzb): + "the dupekey is empty and checking for DUPEs in the history " + "is skipped." ) - return succes + return success def get_dupe_nzb_status(nzb): diff --git a/manifest.json b/manifest.json index 7f85423..c2e7ded 100644 --- a/manifest.json +++ b/manifest.json @@ -91,6 +91,28 @@ ], "select": ["Yes", "No"] }, + { + "name": "SetParamsOnSuccess", + "displayName": "SetParamsOnSuccess", + "value": "", + "description": [ + "Sets post-processing parameters for the group when the completion check succeeds.", + "Specify parameters as 'ParamName=ParamValue, ParamName2=ParamValue2'.", + "Default = blank." + ], + "select": [] + }, + { + "name": "SetParamsOnFailure", + "displayName": "SetParamsOnFailure", + "value": "", + "description": [ + "Sets post-processing parameters for the group when the completion check fails.", + "Specify parameters as 'ParamName=ParamValue, ParamName2=ParamValue2'.", + "Default = blank." + ], + "select": [] + }, { "name": "CheckLimit", "displayName": "CheckLimit", @@ -195,32 +217,32 @@ "select": [] }, { - "name": "Verbose", - "displayName": "Verbose", + "name": "IgnoreQueuePriority", + "displayName": "IgnoreQueuePriority", "value": "No", "description": [ - "Print more info to the log for debugging.", + "Ignore queue priority and always validate items immediately", "Default = No." ], "select": ["Yes", "No"] }, { - "name": "Extreme", - "displayName": "Extreme", + "name": "Verbose", + "displayName": "Verbose", "value": "No", "description": [ - "Print even more info to the log for debugging.", - "This will print your news-server passwords in the logs too!.", + "Print more info to the log for debugging.", "Default = No." ], "select": ["Yes", "No"] }, { - "name": "IgnoreQueuePriority", - "displayName": "IgnoreQueuePriority", + "name": "Extreme", + "displayName": "Extreme", "value": "No", "description": [ - "Ignore queue priority and always validate items immediately", + "Print even more info to the log for debugging.", + "This will print your news-server passwords in the logs too!.", "Default = No." ], "select": ["Yes", "No"] From ce48c290dc63a3d622d11daf929260cb77af6cc1 Mon Sep 17 00:00:00 2001 From: dnzbk Date: Mon, 5 May 2025 14:29:30 +0300 Subject: [PATCH 2/3] Fix: option descriprions, some typos --- manifest.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/manifest.json b/manifest.json index c2e7ded..0bdf683 100644 --- a/manifest.json +++ b/manifest.json @@ -97,7 +97,7 @@ "value": "", "description": [ "Sets post-processing parameters for the group when the completion check succeeds.", - "Specify parameters as 'ParamName=ParamValue, ParamName2=ParamValue2'.", + "Specify parameters as 'CompletionCheck=False, DownloadStatus=Failure'.", "Default = blank." ], "select": [] @@ -108,7 +108,7 @@ "value": "", "description": [ "Sets post-processing parameters for the group when the completion check fails.", - "Specify parameters as 'ParamName=ParamValue, ParamName2=ParamValue2'.", + "Specify parameters as 'CompletionCheck=True, DownloadStatus=Success'.", "Default = blank." ], "select": [] @@ -155,7 +155,7 @@ "description": [ "Check all archives when no pars.", "Force a full check on all the archives articles in the release when no or", - "only 1 par file is included. This to garantee all articles are there and you", + "only 1 par file is included. This to guarantee all articles are there and you", "don't waste bandwidth because just 1 article is missing.", "Default = Yes." ], @@ -168,7 +168,7 @@ "description": [ "Categories to check for completion.", "Comma separated list like 'TV-HD, TV, Movies, etc'. Leave blank for all", - "categories. Note that the category of an NZB file is shown in the donwload", + "categories. Note that the category of an NZB file is shown in the download", "and history queue.", "Default = blank." ], @@ -183,7 +183,7 @@ "Comma separated list like '1, 3, 4'. Leave blank for all news-servers.", "News-server numbers are equal to the server numbering in the NZBGet settings", "on the NEWS-SERVERS tab.", - "Suggestion is the specify atleast your main news-servers.", + "Suggestion is the specify at least your main news-servers.", "Default = blank." ], "select": [] From 1f21f0df9c764599e3dc8529e74e59bf86a4969d Mon Sep 17 00:00:00 2001 From: dnzbk Date: Mon, 5 May 2025 14:46:26 +0300 Subject: [PATCH 3/3] Add: examples --- manifest.json | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/manifest.json b/manifest.json index 0bdf683..f0f19ac 100644 --- a/manifest.json +++ b/manifest.json @@ -97,7 +97,8 @@ "value": "", "description": [ "Sets post-processing parameters for the group when the completion check succeeds.", - "Specify parameters as 'CompletionCheck=False, DownloadStatus=Failure'.", + "Specify parameters as 'ParamName=ParamValue, ParamName2=ParamValue2'.", + "Example: 'CompletionCheck=True, DownloadStatus=Success'.", "Default = blank." ], "select": [] @@ -107,8 +108,9 @@ "displayName": "SetParamsOnFailure", "value": "", "description": [ - "Sets post-processing parameters for the group when the completion check fails.", - "Specify parameters as 'CompletionCheck=True, DownloadStatus=Success'.", + "Sets post-processing parameters for the group when the completion check succeeds.", + "Specify parameters as 'ParamName=ParamValue, ParamName2=ParamValue2'.", + "Example: 'CompletionCheck=False, DownloadStatus=Failure'.", "Default = blank." ], "select": []