SABnzbd

Wiki

Incorrect or missing information? Pre-queue scripts

Introduction

You can choose to let SABnzbd run a script just before an NZB enters the queue. This script will tell whether the NZB should be accepted or not and can modify some parameters.

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 sorting info is passed independently to the actual Sorting settings. Only the SeasonSort method will be used for analysis.

The script must send results to the console. Exit code 0 will make SABnzbd inspect the returned output. If the script has an exit code other than 0, it's assumed the script failed, and the NZB will be accepted without changes.

Input parameters

All parameters (except 1) can be empty, meaning a default value.

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.

Position Description
1 Name of the NZB (no path, no ".nzb")
2 Post Processing (PP) flags:
  • 0 = Download
  • 1 = +Repair
  • 2 = +Unpack
  • 3 = +Delete
3 Category
4 Script (no path)
5 Priority
  • -100 = Default
  • -2 = Paused
  • -1 = Low
  • 0 = Normal
  • 1 = High
  • 2 = Force
6 Size of the download (in bytes)
7 Group list (separated by spaces)
8 Show name
9 Season (1..99)
10 Episode (1..99)
11 Episode name

Return parameters

The script can refuse or accept the NZB and it can also return alternative parameters.
When you want to manipulate the season parameters, you should assemble a new name and return a recognized format.

The script writes the results to the console, each parameter on a separate line.
SABnzbd uses the first 7 lines of output, so they should only contain proper data (or be empty). Anything after line 7 is ignored.

Position Description
1
  • 0 = Refuse
  • 1 = Accept
  • 2 = Accept but fail, this way post-processing scripts for the job will be activated if necessary.
2 Name of the NZB (no path, no ".nzb")
3 Post Processing (PP) flags:
  • 0 = Download
  • 1 = +Repair
  • 2 = +Unpack
  • 3 = +Delete
4 Category
5 Script (no path)
6 Priority
  • -100 = Default
  • -2 = Paused
  • -1 = Low
  • 0 = Normal
  • 1 = High
  • 2 = Force
7 Group to be used (in case your provider doesn't carry all groups and there are multiple groups in the NZB)

Example Script

Example of a Windows batch file that forces high priority on anything smaller than 2GB.

@echo off
echo 1
echo.
echo.
echo.
echo.
if %6 LSS 2000000000 echo 1

Save it as file size-checker.cmd and put in the scripts folder.

A python script to set prio to Force on downloads smaller than 50MB:

import sys

try:
    (scriptname, nzbname, postprocflags, category, script, prio, downloadsize, grouplist, showname, season, episodenumber, episodename) = sys.argv
    downloadsize = int(downloadsize)
except:
    sys.exit(1)    # exit with 1 causes SABnzbd to ignore the output of this script

prio = -100    # Default
if downloadsize > 50111222:
    prio = 2

print "1"    # Accept
print
print
print
print
print prio
print
# 0 means OK
sys.exit(0)