Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add: manifest.json #2

Merged
merged 1 commit into from
Mar 27, 2024
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
3 changes: 2 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ on:
branches:
- feature/*
- main
pull_request:
branches:
- main

jobs:
tests:
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
51 changes: 4 additions & 47 deletions SpeedControl.py → main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <http://www.gnu.org/licenses/>.
# along with the program. If not, see <https://www.gnu.org/licenses/>.
#

##############################################################################
### 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 <Extensions>. NZBGet v19 or newer is requried.
#
# Info about script:
# Author: Andrey Prygunkov ([email protected]).
# 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
Expand All @@ -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
Expand Down
79 changes: 79 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -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
}
]
}
29 changes: 27 additions & 2 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <http://www.gnu.org/licenses/>.
# along with the program. If not, see <https://www.gnu.org/licenses/>.
#


import sys
from os.path import dirname
import os
Expand Down Expand Up @@ -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
Expand All @@ -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):
Expand All @@ -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)

Expand Down