Queue scripts are called after the download queue was changed. In the current version the queue scripts are called on defined events, described later. In the future they can be called on other events too.
To activate a queue script or multiple scripts put them into ScriptDir, then choose them in option Extensions (QueueScript in older NZBGet versions).
Queue scripts are a kind of Extension scripts.
Please read Extension scripts for general information about extension scripts first!
This document describes the unique features of queue scripts.
Like other extension scripts the scan scripts get NZBGet configuration options (env. vars with prefix NZBOP_) and Script configuration options (env. vars with prefix NZBPO_) passed. In addition the information about the file currently processed is passed as well:
The event type is passed with env. var NZBNA_EVENT and can have following values:
In the future the list of supported events may be extended. To avoid conflicts with future NZBGet versions the script must exit if the parameter has a value unknown to the script:
if os.environ.get('NZBNA_EVENT') not in ['NZB_ADDED', 'NZB_DOWNLOADED']:
sys.exit(0)
In addition to checking the parameter NZBNA_EVENT the script can tell NZBGet what events it is interested in, using a special event signature following the script signature:
### NZBGET QUEUE SCRIPT
### QUEUE EVENTS: NZB_ADDED, NZB_DOWNLOADED
That has an advantage that the script isn’t called on events it can’t process anyway.
Queue scripts can change properties of nzb-file by printing special messages into standard output (which is processed by NZBGet).
To assign post-processing parameters:
echo "[NZB] NZBPR_myvar=my value";
The prefix “NZBPR_” will be removed. In this example a post-processing parameter with name “myvar” and value “my value” will be associated with nzb-file.
To cancel downloading and mark nzb as bad:
echo "[NZB] MARK=BAD";
When processing event NZB_DOWNLOADED, which is fired after all files are downloaded and just before unpack starts the script can change final directory for nzb:
echo "[NZB] DIRECTORY=/mnt/movies";
Only one queue script is executed at a given time. If other events have occurred during executing of the script the events are stored in a special queue and are processed later, when the script terminates.
There are two kinds of events: synchronous and asynchronous. When a synchronous event must be processed NZBGet executes queue script and waits for its termination before processing the nzb-file further. Only one event is of this kind - it’s NZB_DOWNLOADED.
All other events are asynchronous. When a script is executed for an asynchronous event it’s possible that at the time a certain part of script is being processed the state of nzb-file was changed or the file was even deleted. Scripts must take this possibility into account.
Although events FILE_DOWNLOADED are supposed to be executed after each downloaded file (part of nzb), no more than one event of this kind for a given nzb is preserved in the processing queue. This means that if during execution of queue scripts multiple files were completed only one event “FILE_DOWNLOADED” will be processed. Therefore scripts should not assume to be called for every downloaded file. Furthermore there is a program option EventInterval to reduce the number of script executions (and system load) for event “FILE_DOWNLOADED”.