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
31 changes: 27 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Completion.py script for NZBGet
#
# Copyright (C) 2014-2017 kloaknet.
# Copyright (C) 2024 Denis <denis@nzbget.com>
# Copyright (C) 2024-2025 Denis <denis@nzbget.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand All @@ -20,15 +20,15 @@


import os
import urllib.request, urllib.error, urllib.parse
import urllib.request
import base64
import json
import time
import sys
import socket
import ssl
import traceback
import html.parser
import html
import errno
from xmlrpc.client import ServerProxy
from operator import itemgetter
Expand Down Expand Up @@ -1531,6 +1531,24 @@ def check_failure_status(rar_msg_ids, failed_limit, nzb_age):
return failed_ratio


def handle_corrupted_lock_file(f_name, server_time):
print(f"[WARNING] Corrupted lock file found at {f_name}. Attempting to recreate.")
try:
os.remove(f_name)
except OSError as e:
print(f"[ERROR] Failed to remove corrupted lock file, reason {e}")
return True
try:
with open(f_name, encoding="utf-8", mode="w") as fd:
fd.write(str(server_time))
print(f"[INFO] New completion.lock file created.")
return False

except OSError as e:
print(f"[ERROR] recreating lock file after corruption: {e}")
return True


def lock_file():
"""
This function checks if the .lock file is there, if it is created
Expand All @@ -1556,7 +1574,12 @@ def lock_file():
file_exists = os.path.isfile(f_name)
if file_exists:
fd = open(f_name, encoding="utf-8")
time_stamp = int(fd.readline())
time_stamp = 0
try:
time_stamp = int(fd.readline())
except ValueError:
return handle_corrupted_lock_file(f_name, server_time)

if VERBOSE:
print(
"[V] time_stamp from completion.lock file= " + str(time_stamp)
Expand Down
30 changes: 18 additions & 12 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,27 @@
"about": "Verifies that enough articles are available before starting the download.",
"queueEvents": "NZB_ADDED, NZB_DOWNLOADED, NZB_DELETED, NZB_MARKED",
"requirements": [
"This script requires Python 3.8.0 and above to be installed on your system."
"Python 3.8.0 or higher is required to be installed on your system."
],
"description": [
"For NZBGet versions 18+, this script needs to be:",
"- listed in EXTENSION SCRIPTS under Extensions.",
"- listed in CATEGORIES for each CategoryX.Extension if not left empty.",
"- optionally the user can add it as scheduler script to manually specify",
"different scheduler intervals instead of checking each 15 minutes by default.",
"For NZBGet versions prior to 18, this script should be added as:",
"- Scan script: to pause incoming NZBs.",
"- Queue script: to check newly added, and by the script paused NZBs, and resume when OK.",
"- Scheduler script: to regularly check completeness of by the script paused NZBs in the queue.",
"- listed in CATEGORIES for each CategoryX.Extension if not left empty.",
"The extension checks if the data in the NZB file is sufficiently complete at your usenet provider(s),",
"before starting the download.",
"If incomplete it would wait for a certain period and check the completion of the NZB file again.",
"This check is done by requesting the header STAT/HEAD,",
"and is in normal cases done within seconds (like 1 - 5 sec. for a 1 GB file).",
"This method is significantly faster than when NZBGet would report a failure,",
"after actual downloading a (part of) the files that end up incomplete.",
"The script is typically useful for issues related to:",
"- very recent posts",
"- failed downloads, which after a while are just ok (propagation issues),",
"- incomplete posts,",
"- taken down posts (DMCA, etc.),",
"- old posts,",
"- long par repair times,",
"- downloading (parts of) NZB files beyond repair,",
"- unnecessary use of expensive block / slow fill accounts.",
"",
"NOTE: To stop the script or remove the .lock file, reload NZBGet via SYSTEM."
"NOTE: To stop the script or delete the .lock file, restart NZBGet via SYSTEM."
],
"options": [
{
Expand Down