Incorrect or missing information? Post-processing scripts
SABnzbd can run a user-provided script to be executed when a job has completed without errors.
Scripts can be Python scripts, bash scripts and BAT scripts. All scripts must be located in the scripts-directory, that can be specified in Config->Folders. Furthermore, the script must be executable. On Linux this means the x-bit must be on. On Windows, the requirement is that the script's extension is listed in your system's PATHEXT environment variable.
The scripts can be used in these contexts:
- Associated with a job entry on the Main page
- Changed for a job on the Queue page
- Associated with a user-defined category
- Associated with the empty-queue event on the Queue page
A post-processing script will only run when the job has completed without errors. If you want to run the script always, you need to disable the option "Post-Process Only Verified Jobs".
The console output of the script is captured by SABnzbd and is saved in the so called "Script Log" which can be opened from the history details. The output will be added to the (optional) notification email and can be examined in the History page.
The script will receive the parameters described below.
Please note: Use %1 in Windows scripts and $1 in Unix scripts. In Windows the parameters will be enclosed in double quotes ("my name").
On Posix systems (macOS, Linux, Unix) the parameters will not have quotes at all.
NOTE In SABnzbd 2.0.0 and above more information is available to scripts via environment variables, see below!
|1||The final directory of the job (full path)|
|2||The original name of the NZB file|
|3||Clean version of the job name (no path info and ".nzb" removed)|
|4||Indexer's report number (if supported)|
|6||Group that the NZB was posted in e.g. alt.binaries.x|
|7||Status of post processing.
|8||URL to be called when job failed (if provided by the server, it is always sent, so check parameter 7!).
The URL is provided by some indexers as the X-DNZB-Failure header.
All parameters are properly quoted so that they may contain embedded spaces.
The "return" code that your script itself returns should be 0 if all went well or non-zero if errors occurred. If the return code is something else than 0, SABnzbd's History will show that return code (also known as exit code) in green surrounded by "Exit(...)".
A script can return an exit code. SABnzbd will show a non-zero code in the download report, but the job will not be flagged as failed.
Note: Release 1.0.0 has an option in Config->Switches to let a non-zero code mark the job as failed.
Example Python script
The get the parameters in python, you can do this:
Enviroment variables available in SABnzbd 2.0.0+
Your script can now get extra information via environment variables:
|SAB_SCRIPT||The name of the current script|
|SAB_NZO_ID||The unique ID assigned to the job|
|SAB_FILENAME||The NZB filename (after grabbing from the URL)|
|SAB_PP_STATUS||Was post-processing succesfull (repair/unpack)|
|SAB_BYTES||Total number of bytes|
|SAB_BYTES_TRIED||How many bytes of the total bytes were tried|
|SAB_BYTES_DOWNLOADED||How many bytes were recieved (can be more than tried, due to overhead)|
|SAB_DUPLICATE||Was it detected as duplicate|
|SAB_UNWANTED_EXT||Were there unwanted extensions|
|SAB_FINAL_NAME||The folder name for the end result|
|SAB_COMPLETE_DIR||The whole path to the output directory of the job|
|SAB_OVERSIZED||Was the job over the user's size limit|
|SAB_PASSWORD||What was the password supplied by the NZB or the user|
|SAB_ENCRYPTED||Was the job detected as encrypted|
|SAB_STATUS||Current status (completed/failed/running)|
|SAB_AGE||Average age of the articles in the post|
|SAB_URL||URL from which the NZB was retrieved|
|SAB_AVG_BPS||Average bytes/second speed during active downloading|
|SAB_DOWNLOAD_TIME||How many seconds did we download|
|SAB_CAT||What category was assigned|
|SAB_PP||What post-processing was activated (download/repair/unpack/delete)|
|SAB_REPAIR||Was repair selected by user|
|SAB_UNPACK||Was unpack selected by user|
|SAB_FAILURE_URL||Provided by some indexers as alternative NZB if download fails|
|SAB_PRIORITY||Priority set by user|
|SAB_FAIL_MSG||If job failed, why did it fail|
|SAB_GROUP||Newsgroup where most of the job's articles came from|
|SAB_VERSION||The version of SABnzbd used|