From 05f73c3e035d60568c1edb29a6b9fa188fa0a181 Mon Sep 17 00:00:00 2001 From: dnzbk Date: Mon, 25 Mar 2024 13:51:40 +0300 Subject: [PATCH] Add: manifest.json --- .github/workflows/release.yml | 3 +- .github/workflows/tests.yml | 3 ++ README.md | 5 +++ SpeedControl.py => main.py | 51 ++-------------------- manifest.json | 79 +++++++++++++++++++++++++++++++++++ tests.py | 29 ++++++++++++- 6 files changed, 120 insertions(+), 50 deletions(-) rename SpeedControl.py => main.py (80%) create mode 100644 manifest.json diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 357000b..19a3844 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -9,5 +9,6 @@ jobs: release: uses: nzbgetcom/nzbget-extensions/.github/workflows/extension-release.yml@main with: - release-file-list: SpeedControl.py + release-file-list: main.py manifest.json release-file-name: speedcontrol + release-dir: SpeedControl diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 4669ee0..9de08c3 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -5,6 +5,9 @@ on: branches: - feature/* - main + pull_request: + branches: + - main jobs: tests: diff --git a/README.md b/README.md index a13eea4..398073b 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,11 @@ > **Note:** This script is compatible with python 3.8.x and above. If you need support for Python 2.x versions then you can get legacy version [here](https://forum.nzbget.net/viewtopic.php?f=8&t=3913&sid=280a49a37e67bdd24b21f7b7b16b4a7f). +## NZBGet Versions + +- stable v23.1 [v3.0](https://github.com/nzbgetcom/Extension-SpeedControl/releases/tag/v3.0) +- legacy v22 [v2.0](https://github.com/nzbgetcom/Extension-SpeedControl/releases/tag/v2.0) + # SpeedControl diff --git a/SpeedControl.py b/main.py similarity index 80% rename from SpeedControl.py rename to main.py index 3270618..079760f 100644 --- a/SpeedControl.py +++ b/main.py @@ -15,52 +15,9 @@ # GNU Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public License -# along with the program. If not, see . +# along with the program. If not, see . # -############################################################################## -### TASK TIME: * -### NZBGET SCHEDULER SCRIPT - -# Sets speed limit based on category. -# -# This script monitors download queue and changes download speed limit -# depending on category of item being currently downloaded. -# -# To activate the script select it in option . NZBGet v19 or newer is requried. -# -# Info about script: -# Author: Andrey Prygunkov (nzbget@gmail.com). -# License: GPLv3 (http://www.gnu.org/licenses/gpl.html). -# PP-Script Version: 2.0. -# -# NOTE: This script requires Python 3.8+ to be installed on your system. - -############################################################################## -### OPTIONS ### - -# Check interval (seconds). -#Interval=5 - -# Print more logging messages (yes, no). -# -# For debugging or if you need to report a bug. -#Verbose=no - -# Click to test the script. -#Test@Check now - -############################################################################## -### CATEGORIES ### - -# Name of the category to monitor. -#Category1.Name= - -# Speed limit for that category (KB). -#Category1.DownloadRate=0 - -### NZBGET SCHEDULER SCRIPT -############################################################################## import os import sys @@ -73,11 +30,11 @@ SCRIPT_SUCCESS = 93 SCRIPT_ERROR = 94 -# Check if the script is called from nzbget 19.0 or later +# Check if the script is called from nzbget 23.1 or later nzbget_version = float(os.environ.get('NZBOP_Version', '1')[0:4]) -if nzbget_version < 19: +if nzbget_version < 23.1: print('*** NZBGet extension script ***') - print('This script is supposed to be called from nzbget (19.0 or later).') + print('This script is supposed to be called from nzbget (23.1 or later).') sys.exit(SCRIPT_ERROR) # Check if all script options are available diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..feab50e --- /dev/null +++ b/manifest.json @@ -0,0 +1,79 @@ +{ + "main": "main.py", + "name": "SpeedControl", + "homepage": "https://github.com/nzbgetcom/Extension-SpeedControl/", + "kind": "SCHEDULER", + "displayName": "Speed Control", + "version": "3.0", + "author": "Andrey Prygunkov", + "license": "GPLv3", + "about": "Sets speed limit based on category.", + "queueEvents": "", + "taskTime": "*", + "description": [ + "This extension monitors download queue and changes download speed limit." + ], + "requirements": [ + "Requires NZBGet v23.1 and above.", + "Requires Python 3.8 and above to be installed on your system." + ], + "options": [ + { + "name": "Interval", + "displayName": "Interval", + "value": "5", + "description": [ + "Check interval (seconds)" + ], + "select": [] + }, + { + "name": "Verbose", + "displayName": "Verbose", + "value": "no", + "description": [ + "Print more logging messages", + "", + "For debugging or if you need to report a bug." + ], + "select": ["yes", "no"] + }, + { + "section": "Categories", + "name": "Name", + "displayName": "Name", + "value": "", + "description": [ + "Name of the category to monitor." + ], + "select": [] + }, + { + "section": "Categories", + "name": "DownloadRate", + "displayName": "Download Rate", + "value": 0, + "description": [ + "Speed limit for that category (KB)." + ], + "select": [] + } + ], + "commands": [ + { + "name": "Test", + "action": "Check now", + "displayName": "Test", + "description": [ + "Click to test the script." + ] + } + ], + "sections": [ + { + "name": "Categories", + "prefix": "Category", + "multi": true + } + ] +} \ No newline at end of file diff --git a/tests.py b/tests.py index dfb6412..bce574b 100644 --- a/tests.py +++ b/tests.py @@ -12,9 +12,10 @@ # GNU Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public License -# along with the program. If not, see . +# along with the program. If not, see . # + import sys from os.path import dirname import os @@ -54,7 +55,7 @@ def do_POST(self): def run_script(): sys.stdout.flush() - proc = subprocess.Popen([get_python(), root + '/SpeedControl.py'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=os.environ.copy()) + proc = subprocess.Popen([get_python(), root + '/main.py'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=os.environ.copy()) out, err = proc.communicate() proc.pid ret_code = proc.returncode @@ -72,6 +73,7 @@ def set_defaults_env(): os.environ['NZBOP_Version'] = '20' os.environ['NZBPO_Verbose'] = 'no' os.environ['NZBPO_Interval'] = '5' + os.environ['NZBOP_Version'] = '23.1' os.environ['NZBOP_DownloadRate'] = '15' class Tests(unittest.TestCase): @@ -84,6 +86,29 @@ def test_command(self): thread.start() [_, code, _] = run_script() server.shutdown() + server.server_close() + thread.join() + self.assertTrue(code, SUCCESS) + + def test_nzbget_version(self): + set_defaults_env() + os.environ['NZBOP_Version'] = '22' + server = http.server.HTTPServer((host, int(port)), Request) + thread = threading.Thread(target=server.serve_forever) + thread.start() + [_, code, _] = run_script() + server.shutdown() + server.server_close() + thread.join() + self.assertTrue(code, ERROR) + + os.environ['NZBOP_Version'] = '23.1' + server = http.server.HTTPServer((host, int(port)), Request) + thread = threading.Thread(target=server.serve_forever) + thread.start() + [_, code, _] = run_script() + server.shutdown() + server.server_close() thread.join() self.assertTrue(code, SUCCESS)