After the download of nzb-file is completed NZBGet can call post-processing scripts (pp-scripts). The scripts can perform further processing of downloaded files such es delete unwanted files (*.url, etc.), send an e-mail notification, transfer the files to other application and do any other things. Please note that the par-check/repair and unpack are performed by NZBGet internally and are not part of post-processing scripts. You can activate par-check/repair and unpack without using of any post-processing scripts.
When a new nzb-file is added to queue it doesn’t have any pp-scripts assigned to it by default. You can define what scripts should be called for the nzb-file using option Extensions (PostScript in older NZBGet versions) in section EXTENSION SCRIPTS. You can also define a different set of pp-scripts for each category.
Please note that these settings define “defaults” for nzb-file. When you change option Extensions (PostScript) this has no effect on already enqueued downloads. However it’s possible to alter the assigned pp-scripts for each nzb-file individually. To do so click on the nzb-file in the list of downloads, then click on Postprocess.
If you use more than one script for one nzb-file it can be important to set the correct order of execution. The order is controlled by the option ScriptOrder. That is a global setting affecting all categories and also defining the order scripts are listed in the download details dialog.
Post-processing 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 post-processing 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 information about nzb-file which is currently processed:
v13.0
Total status of nzb-file:
v13.0
Summary status of the scripts executed before the current one:
v13.0
v13.0
if [ "$NZBPP_TOTALSTATUS" != "SUCCESS" ]; then
echo "[ERROR] This nzb-file was not processed correctly, terminating the script"
exit 95
fi
Sometimes a script might need an option specific to nzb-file. Best example - unpack password. NZBGet allows pp-script to define nzb-file specific options, so called post-processing parameters (pp-parameters). PP-Parameters must be declared in the configuration definition of the script. NZBGet reads the definition and adds necessary ui-elements to download details dialog on page Postprocess.
Post-processing parameters are declared using configuration section “POST-PROCESSING PARAMETERS”. For example a video recode script could have a parameter “Resolution”:
##############################################################################
### POST-PROCESSING PARAMETERS ###
# Video resolution (default, 480p, 720p, 1080p).
Resolution=default
NOTE: Only post-processing scripts can have post-processing parameters. Scan, queue and scheduler scripts can not have them.
Post-processing parameters are passed using env-vars with prefix NZBPR_. Like script-options there are two env-vars for each parameter:
For example, for pp-parameter Resolution two env-vars are passed: NZBPR_Resolution and NZBPR_RESOLUTION.
NOTE: when nzb-file is added to download queue it doesn’t have any pp-parameters. Only if the user opens edit download dialog and changes pp-parameters they are getting assigned to nzb-file and will be passed to pp-script. The script MUST work properly even if no pp-parameters were passed; it MUST use default values for pp-parameters.
Example (bash):
Resolution=$NZBPR_RESOLUTION
if [ "$Resolution" = "" ]; then
Resolution="480p"
fi
Example (python):
Resolution="480p"
if 'NZBPR_RESOLUTION' in os.environ:
Resolution=os.environ['NZBPR_RESOLUTION']
For post-processing scripts NZBGet checks the exit code of the script and sets the status in history item accordingly. Scripts can use following exit codes:
Scripts MUST return one of the listed status codes. If any other code (including 0) is returned the history item is marked with status FAILURE.
POSTPROCESS_SUCCESS=93
POSTPROCESS_ERROR=94
echo "Hello from test script";
exit $POSTPROCESS_SUCCESS
Post-processing scripts which move downloaded files can inform NZBGet about that by printing special messages into standard output (which is processed by NZBGet). This allows the scripts called thereafter to process the files in the new location. Use command DIRECTORY:
echo "[NZB] DIRECTORY=/path/to/new/location";
The scripts executed after your script assume the files in the directory belong to the current download. If your script moves files into a non empty directory which already contains other files, your should not use that command. Otherwise the other scripts may process all files in the directory, even the files existed before. In that case use command FINALDIR instead (which has less consequences):
echo "[NZB] FINALDIR=/path/to/new/location";
Command FINALDIR sets a separate property FinalDir of the download. If it is set, that path is shown in the history dialog in web-interface. That path is also passed to post-processing scripts in a separate parameter (env. var. NZBPP_FINALDIR), which most scripts ignore. Command DIRECTORY changes the destination path of the download and affects the code accessing that info, for example the command Post-process again will work on new path.
To test a pp-script save it to a text file, make it executable and put into ScriptDir. Then refresh the page in web-browser (a reload of NZBGet is not needed), click on any download in the download list, then click on button Postprocess. Here select your script. When the download is finished the script is executed.
TIP: to test a script after you made changes to it, use command Post-process again from the history page in web-interface.
Example of a very simple post-processing script:
#!/bin/sh
#######################################
### NZBGET POST-PROCESSING SCRIPT ###
# Print test message.
#
# This is a test script. It prints one message to log. Here in the
# long description we could write instructions for user.
#
# The long description can have multiple paragraphs when needed. Like
# this one.
### NZBGET POST-PROCESSING SCRIPT ###
#######################################
echo "post-processing script test"
Our simple test script prints a message to standard output stream:
echo "post-processing script test"
NZBGet receives the message and adds it to Messages-log. You can set message kind by using prefixes:
echo "[DETAIL] This is detail-message"
echo "[INFO] This is info-message"
echo "[WARNING] This is warning-message"
echo "[ERROR] This is error-message"