Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 46 additions & 7 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(",")
Expand Down Expand Up @@ -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)

Expand All @@ -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])
Expand All @@ -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])
Expand All @@ -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])
Expand All @@ -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] + '"')
Expand All @@ -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):
Expand All @@ -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):
Expand Down
50 changes: 37 additions & 13 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,30 @@
],
"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'.",
"Example: 'CompletionCheck=True, DownloadStatus=Success'.",
"Default = blank."
],
"select": []
},
{
"name": "SetParamsOnFailure",
"displayName": "SetParamsOnFailure",
"value": "",
"description": [
"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": []
},
{
"name": "CheckLimit",
"displayName": "CheckLimit",
Expand Down Expand Up @@ -133,7 +157,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."
],
Expand All @@ -146,7 +170,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."
],
Expand All @@ -161,7 +185,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": []
Expand Down Expand Up @@ -195,32 +219,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"]
Expand Down