An NZBGet Scheduler script that allows you to identify additional locations you intend to place NZB-Files in outside of what is already configured. Basically NZBGet limits you to identifying one directory it should scan for NZB-Files in.
This script allows you to do the following:
- Push NZB-Files (including compressed ones) residing in multiple directories and on multiple systems to a central NZBGet Server.
- Optionally assign fixed categories to any NZB-Files found within a specific directory.
- Full CLI support, so you can run all this from multiple servers in a cron to achieve the same results.
- It can also just be a very basic file moving tool reading from a series of local directories and moving it to one central one.
This script utilizes the pynzbget I wrote which simplifies NZBGet script development.
DirWatch NZBGet Script Details
Author: Chris Caron <lead2gold@gmail.com>
Current Version: 0.5.0
Release Date: Jul 19th, 2019
License: GPLv3
Source: GitHub / Direct Download Link
Updates:
- Jul 19th, 2019 Update (v0.5.0):
- Directory Watch files created to manage the handling of nzbfiles that might have already been handled.
- Small bugfixes dating back to 2017
- Python 3 Support Added
- Carrying supported packages dropped and replaced with a requirements.txt file.
- Feb 19th, 2017 Update (v0.2.0):
- Supports category -> directory assignments. Now you can scan directories such as /Movies for NZB-Files and assign each NZB-File the 'movie' category (as a example). There is no limit to the number of directories you scan or the number of categories you wish to use.
- Supports remote NZB-File loading from across the network. You can now run this script on any server/pc in your network and report NZB-Files directly to your central NZBGet server.
- Nov 22nd, 2016 Update (v0.1.0):
Now runs concurrently next to NZBGet and can poll your files every 30 seconds or more. Configuration will be incredibly easy when NZBGet v18 rolls out because it will support auto-launching things. But for now it still works great; you just need to set a schedule to have it launch.
Once NZBGet spawns an instance from the scheduler; it will remain in memory and run on it's own cycle. Every 30 seconds, every 60 seconds; it'll run for whatever you tell it to. It will shut down when NZBGet shuts down and also when it gets a Reload signal.
If another (NZBGet) scheduled time rolls by and tries to launch another instance, that instance will gracefully close itself off. - Nov 9th, 2016 Update (v0.0.3):
Made an official release out of some additional testing and minor bug fixes. - Nov 1st, 2016 Update (v0.0.2):
Minor release adding:- Support for Zip files; the Zip files themselves are moved if they only contain NZB-Files within them.
The following needs to be ran in order to pull the packages this script depends on into your environment:
Code: Select all
# The requirements.txt can be found included in this package
pip install -r requirements.txt
How do I make it Work?
From the NZBGet settings, you can configure all of the directories you want to scan. You can also set a Poll time (no smaller then 30 seconds). This is the time the script will automatically check your specified directories for new NZB-Files that it should hand off to NZBGet.
To get the script running, you need to create a Schedule; you can do this from inside NZBGet. From the Settings -> Scheduler section, you can choose to [Add Task].
You'll need to specify the following:
- TaskX.Time:
- Setting for NZBGet Versions < v18: *:00,*:05,*:10,*:15,*:20,*:25,*:30,*:35,*:40,*:45,*:50,*:55
This basically does a check every 5 minutes; This means if you restart NZBGet or reload it's configuration for whatever reason; you'll just have to wait up to 5 minutes before the script launches and takes over (using it's configured poll time). - Setting for NZBGet Versions >= v18: *
A new feature allowing NZBGet to automatically start up any Scheduled service if you simply define a single asterix (*) as it's scheduled start time. So your configuration for time entries just need to be.
- Setting for NZBGet Versions < v18: *:00,*:05,*:10,*:15,*:20,*:25,*:30,*:35,*:40,*:45,*:50,*:55
- TaskX.Weekdays: 1-7
- TaskX.Command: Script
- TaskX.Param: DirWatch.py
In the WatchPaths location, you can specify as many directories as you like (use a comma and space to delimit more the one entry).
You can additionally (optionally) associate a category with any directory you add by simply adding a ?category=name where name identifies the category itself. For example, you might set up a WatchPaths path such as:
Code: Select all
/path/to/NZBFiles/Movies?category=movie, /path/to/NZBFiles/Shows?category=tv, /path/to/NZBFiles/General
- associate the category 'movie' with all (NZB-File) content found in /path/to/NZBFile/Movies.
- associate the category 'tv' with all (NZB-File) content found in /path/to/NZBFile/Shows.
- just process NZB-Files found in /path/to/NZBFile/Shows as they are (no additional assignments).
Command Line
Here is what the tool offers so far (from the command line):
Code: Select all
Usage: DirWatch.py [options] [SrcDir1 [SrcDir2 [...]]]
Options:
-h, --help show this help message and exit
-t DIR, --target-dir=DIR
The directory you want to move found NZB-Files from
the identified source directories to. This option is
required if not using the --remote (-r) switch.
-a AGE_IN_SEC, --min-age=AGE_IN_SEC
Specify the minimum age a NZB-File must be before
considering it for processing. This value is
interpreted in seconds and defaults to 30 sec(s). This
is just a safety switch to prevent us from creating a
racing condition where an NZB-File is still being
written to disk at the same time as we're trying to
process it.
-s SIZE_IN_KB, --max-archive-size=SIZE_IN_KB
Specify the maximum size a detected compressed file
can be before ignoring it. If the found compressed
file is within this specified value, it's contents
will be scanned to see if it (only) contains NZB-
Files. These types of files would qualify to be moved
as well. Set this value to Zero (0) to not process
compressed files. The value is interpreted in
Kilobytes and has a default value of 150if not
otherwise specified.
-p, --preview This is like a test switch; the actions the script
would have otherwise performed are instead just
printed to the screen.
-L FILE, --logfile=FILE
Send output to the specified logfile instead of
stdout.
-u API_URL, --api-url=API_URL
Specify the URL of the NZB-Get API server such as:
nzbget://user:pass@control.nzbget.host (to access
insecure port 6789),
nzbgets://user:pass@control.nzbget.host (to access
secure port 6791),
nzbget://user:pass@control.nzbget.host:port (to
specify your own insecure port), and
nzbgets://user:pass@control.nzbget.host:port (to
specify your own secure port). By default
nzbget://127.0.0.1 is used.
-r, --remote-push Perform a remote push to NZBGet. This allows you to
scan directories for NZB-Files on different machines
and still remotely push them to your central NZBGet
server.
-D, --debug Debug Mode
Code: Select all
# Scan your library for NZB-Files and print to the sreen what
# you plan on doing (observe the -p switch):
python DirWatch.py -p -t /path/to/NZBGet/NzbDir
/path/to/location/with/NZB-Files
# Happy with the plan of action? Just drop the -p switch and the
# matched NZB-Files will be moved:
python DirWatch.py -t /path/to/NZBGet/NzbDir
/path/to/location/with/NZB-Files
Code: Select all
# Scan your libraries for NZB-Files and move them
# into: /path/to/NZBGet/NzbDir
python DirWatch.py -t /path/to/NZBGet/NzbDir \
/home/joe/Downloads \
/home/jason/Downloads \
/home/trevor/Downloads \
/home/joe/Dropbox/NZBFiles \
/home/jason/Dropbox/NZBFiles \
/home/trevor/Dropbox/NZBFiles \
# Don't forget to use the power of shells wildcards to accomplish the same feat:
python DirWatch.py -t /path/to/NZBGet/NzbDir \
/home/*/Downloads /home/*/Dropbox/NZBFiles
Code: Select all
# $> crontab -e
# Scan a directory every 2 minutes
*/2 * * * * /path/to/DirWatch.py -t /path/to/NZBGet/NzbDir ~/DropBox/NZB-Files
Code: Select all
# $> crontab -e
# Scan a directory every 2 minutes and post the content directly to nzbget
*/2 * * * * /path/to/DirWatch.py -r -u nzbget://nzbget.host.name ~/DropBox/NZB-Files
Code: Select all
# $> crontab -e
# Scan a directory every 2 minutes and post the content directly to nzbget
# Also assigns everything found in the NZB-Files the category 'movie' prior
# to loading it
*/2 * * * * /path/to/DirWatch.py -r -u nzbget://nzbget.host.name ~/DropBox/NZB-Files?c=movie