Programming‎ > ‎

OS X SABnzbd Handbrake and iTunes Post Processing Script


This is a post processing script for SABnzbd on OS X. It does the following things:
  • convert video files using HandBrakeCLI
  • optional post-processing after video has been converted
  • optional import into iTunes as either Movie or TV Show
    • TV show details are extrapolated fromt he file name


After importing to iTunes:


You can download from here.


I have tested the script on:
  • OS X 10.5+
  • SABnzbd 0.5+
  • HandBrakeCLI 64bit 0.9.5

Configuration Options

There are some configuration options at the top of the script. Here is their explanation: 

OptionValid ValuesDetails
IS_LIONTrue or FalseSet to True if you're using OS X Lion (10.7+).
DATE_TIME_FORMATstringThe date and time format of the output.

Use for valid directives for a list of valid options.

Example: DATE_TIME_FORMAT = "[ %Y-%m-%d @ %H:%M:%S ] "
SEPARATORstringThe separator used in program output.

Example: SEPARATOR = " : "
PRINT_CONFIGTrue or FalseSet to True if you want to print config details.
HANDBRAKE_PATHstringThe full path to HandBrakeCLI.

Example: HANDBRAKE_PATH = "/usr/bin/HandBrakeCLI"
HANDBRAKE_PARAMATERS_BEFORE_PRESETFalse or stringUnless set to False, the command line parameters for HandBrake before the preset parameter.

Example: HANDBRAKE_PARAMATERS_BEFORE_PRESET = "-T"                 
HANDBRAKE_PARAMATERS_AFTER_PRESETFalse or stringUnless set to False, the Commandline parameters for HandBrake after the preset parameter.

HANDBRAKE_PRESETFalse or stringUnless set to False, the name of the HandBrake preset to use.

See for a complete list.

Example: HANDBRAKE_PRESET = "iPhone 4"
HANDBRAKE_COMMAND_OUTPUTTrue or FalseIf set to True HandBrakeCLI output will be inline of the rest of the output. If set to False the output will be saved and can be later appended with the OUTPUT_APPEND option.
HANDBRAKE_ALL_AUDIOTrue or FalseSet to True if you want to scan the input file for the number of audio channels and include them all in the output.
FILE_TYPESarray of stringsArray of files to process. Each file supports the UNIX wildcard character (*).

Example: FILE_TYPES = [ "*.avi" ]
Example: FILE_TYPES = [ "*.avi", "*.mkv", "*something*.avi" ]
OUTPUT_EXTENSIONstringThe extension of the output file. This must match the expected extension based on your HandBrakeCLI settings.

Example: OUTPUT_EXTENSION = "mp4"
OUTPUT_PREFIXstringPrefix for the output file.

Example: OUTPUT_PREFIX = ""
Example: OUTPUT_PREFIX = "Converted - "
OUTPUT_POSTFIXstringPostfix for the output file.

Example: OUTPUT_POSTFIX = ""
Example: OUTPUT_POSTFIX = " - iPhone"
OUTPUT_DIRECTORYFalse or stringThe output directory to save the file. If set to False use the same as the input directory.

Example: OUTPUT_DIRECTORY = False Example: OUTPUT_DIRECTORY = "/some/path"
POST_PROCESSINGTrue or FalseSet to True if you want to run extra post-processing on the file once HandBrakeCLI is done with it.
POST_PROCESSING_COMMANDstringThe command to run after HandBrakeCLI is done.

Use "{filename}" and/or "{directory}" to reference the processed file and/or output directory.

Example: POST_PROCESSING_COMMAND = 'ls -la "{directory}"'
Example: POST_PROCESSING_COMMAND = 'ls -la "{directory}/{filename}"'
POST_PROCESSING_OUTPUTTrue or FalseIf set to True the output of the post-processing will be inline of the rest of the output. If set to False the output will be saved and can be later appended with the OUTPUT_APPEND option.
IMPORT_TO_ITUNESTrue or FalseIf set to True the converted video will be imported to iTunes.
TV_FORMATregular expression stringThe regular expression string used to extrapolate TV show information from the file.

The captured named groups need to match the iTunes AppleScript track properties (use underscore [_] for spaces). Some of the common ones are:
  • show -> show
  • season number -> season_number
  • episode number -> episode_number
  • episode ID -> episode_ID
Example: TV_FORMAT = "^(?P.*) - (?P\d+)x(?P\d+) - (?P.*)$"
DELETE_AFTER_IMPORTTrue or FalseIf set to True the converted file will be deleted after it has been imported into iTunes.
DELETE_ORIGINALTrue or FalseIf set to True the original file will be deleted after everything is done.
OUTPUT_APPENDTrue or FalseIf set to True all captured output will be appended to the end. Any in-line output will not be showed here.

Contact Me

I do not have a lot of time to test/debug every possible scenario so if you see any problems, or have any questions, please feel free to contact me at emailyoumust at


Uhhh...I don't know? Use your common sense I suppose. Do with my script what you will as long as it doesn't involve money. Any questions just ask me.