Custom Post Processing Scripts

Donald Webster edited this page Jun 13, 2018 · 21 revisions

If you're looking to trigger a custom script in your download client to tell Sonarr when to update, you can find more details here. Scripts are added to Sonarr via the Connect Settings page.

Overview

Sonarr can execute a custom script when an episode is newly imported or renamed and depending on the action, different parameters are supplied. They are passed to the script through environment variables which allows for more flexibility in what is sent to the script and in no particular order.

Environment Variables

On Grab
Environment Variable Details
sonarr_eventtype Grab
sonarr_series_id Internal ID of the series
sonarr_series_title Title of the series
sonarr_series_tvdbid TVDB ID for the series
sonarr_series_tvmazeid TVMaze ID for the series
sonarr_series_imdbid IMDB ID for the series
sonarr_series_type Type of the series, Anime, Daily or Standard
sonarr_release_episodecount Number of episodes in the release
sonarr_release_seasonnumber Season number from release
sonarr_release_episodenumbers Comma separated list of episode numbers
sonarr_release_episodeairdates Air date from original network
sonarr_release_episodeairdatesutc Air Date with Time in UTC
sonarr_release_episodetitles Pipe (|) separated list of episode titles
sonarr_release_title NZB/Torrent title
sonarr_release_indexer Indexer where the release was grabbed
sonarr_release_size Size of the release reported by the indexer
sonarr_release_quality Quality name from Sonarr
sonarr_release_qualityversion 1 is the default, 2 for proper, 3+ could be used for anime versions
sonarr_release_releasegroup Release Group, will not be set if it is unknown
sonarr_download_id The hash of the torrent/NZB file downloaded (used to uniquely identify the download in the download client)
On Download/On Upgrade
Environment Variable Details
sonarr_eventtype Download
sonarr_isupgrade True when an an existing file is upgraded, otherwise False
sonarr_series_id Internal ID of the series
sonarr_series_title Title of the series
sonarr_series_path Full path to the series
sonarr_series_tvdbid TVDB ID for the series
sonarr_series_tvmazeid TVMaze ID for the series
sonarr_series_imdb IMDB ID for the series
sonarr_series_type Type of the series, Anime, Daily or Standard
sonarr_episodefile_id Internal ID of the episode file
sonarr_episodefile_relativepath Path to the episode file relative to the series' path
sonarr_episodefile_path Full path to the episode file
sonarr_episodefile_episodecount Number of episodes in the episode file
sonarr_episodefile_seasonnumber Season number of episode file
sonarr_episodefile_episodenumbers Comma separated list of episode numbers
sonarr_episodefile_episodeairdates Air date from original network
sonarr_episodefile_episodeairdatesutc Air Date with Time in UTC
sonarr_episodefile_episodetitles Pipe (|) separated list of episode titles
sonarr_episodefile_quality Quality name from Sonarr
sonarr_episodefile_qualityversion 1 is the default, 2 for proper, 3+ could be used for anime versions
sonarr_episodefile_releasegroup Release group, will not be set if it is unknown
sonarr_episodefile_scenename Original release name
sonarr_episodefile_sourcepath Full path to the episode file that was imported
sonarr_episodefile_sourcefolder Full path to the folder the episode file was imported from
sonarr_deletedrelativepaths Pipe (|) separated list of files that were deleted to import this file
sonarr_deletedpaths Pipe (|) separated list of full paths for files that were deleted to import this file
sonarr_download_id The hash of the torrent/NZB file downloaded (used to uniquely identify the download in the download client)
On Rename
Environment Variable Details
sonarr_eventtype Rename
sonarr_series_id Internal ID of the series
sonarr_series_title Title of the series
sonarr_series_path Full path to the series
sonarr_series_tvdbid TVDB ID for the series

Arguments

Additional command line line arguments that are passed to your script, such as running your script through cmd.exe you would set the path to cmd.exe and the arguments to /c C:\Path\to\script.bat.

Specific usage tips

PHP

The information from Sonarr will not be added to $_ENV as one might expect but should be included in the $_SERVER variable. A sample script to use this information to convert a file can be found here.

PowerShell

Sample script using the Sonarr environment variables to create EDL files for all episodes is here.

Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.