-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
72 lines (63 loc) · 2.57 KB
/
Copy pathmain.py
File metadata and controls
72 lines (63 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#
# Example post-processing script for NZBGet
#
# Copyright (C) 2024 phnzb <pavel@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
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
import os
import sys
from datetime import datetime
# Exit codes used by NZBGet
POSTPROCESS_SUCCESS = 93
POSTPROCESS_ERROR = 94
POSTPROCESS_NONE = 95
print("[DETAIL] Script successfully started")
sys.stdout.flush()
# Options passed to script as environment variables
# Check required options
required_options = (
"NZBPO_OPTIONSELECT",
"NZBPO_OPTIONSTRING",
"NZBPO_OPTIONNUMBER"
)
for optname in required_options:
if optname not in os.environ:
print(f"[ERROR] Option {optname[6:]} is missing in configuration file. Please check script settings")
sys.exit(POSTPROCESS_ERROR)
# Check if the script is executed from settings page with a custom command
command = os.environ.get("NZBCP_COMMAND")
test_mode = command == "Test"
if command is not None and not test_mode:
print("[ERROR] Invalid command " + command)
sys.exit(POSTPROCESS_ERROR)
OptionSelect = os.environ["NZBPO_OPTIONSELECT"]
OptionString = os.environ["NZBPO_OPTIONSTRING"]
OptionNumber = int(os.environ["NZBPO_OPTIONNUMBER"])
if test_mode:
print(f"[DETAIL] Script successfully invoked with params: OptionSelect: {OptionSelect}, OptionString: {OptionString}, OptionNumber: {OptionNumber}")
else:
if not os.path.exists(os.environ["NZBPP_DIRECTORY"]):
print("Destination directory doesn\'t exist, exiting")
sys.exit(POSTPROCESS_NONE)
with open(f"{os.environ['NZBPP_DIRECTORY']}/_status.txt", "w", encoding="utf-8") as status:
now = datetime.now()
status.writelines([
f"Completed at: {now}\n",
f"Options: OptionSelect: {OptionSelect}, OptionString: {OptionString}, OptionNumber: {OptionNumber}\n"
])
print("[INFO] Example extension successfully completed")
# All OK, returning exit status 'POSTPROCESS_SUCCESS' (int <93>) to let NZBGet know
# that our script has successfully completed.
sys.exit(POSTPROCESS_SUCCESS)