Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save BlindByrd/97a785a0f16cdf10cb76486e871ac032 to your computer and use it in GitHub Desktop.
Save BlindByrd/97a785a0f16cdf10cb76486e871ac032 to your computer and use it in GitHub Desktop.
Sonarr post processing script to remove video file from packed torrent, modified version of subzero79/87a347a07964390884c9
#!/bin/bash
# Setup in Sonarr: Settings -> Connect -> Add Custom Script, enable Download and Upgrade (or Import and Upgrade in v3)
# Examples for testing
# sonarr_episodefile_sourcefolder="/data/torrent/tv/Penny.Dreadful.S01E01.720p.HDTV.x264-2HD" sonarr_episodefile_sourcepath="/data/torrent/tv/Penny.Dreadful.S01E01.720p.HDTV.x264-2HD/penny.dreadful.s01e01.720p.hdtv.x264-2hd.mkv"
# The final base directory torrents end up in, for example "tv" from /data/torrents/tv
sonarr_final_dir="Complete"
# Identifiable portion of path to torrents, so it will only run on torrents.
# For example, a path of "/data/torrents/tv", "torrents" is a good choice.
torrent_path_portion="Complete"
if ! [[ "${sonarr_episodefile_sourcepath}" =~ ${torrent_path_portion} ]]; then
echo "[Torrent Cleanup] Path ${sonarr_episodefile_sourcepath} does not contain ${torrent_path_portion}, exiting."
exit
fi
base_dir=$( basename "${sonarr_episodefile_sourcefolder}" )
if [[ "${base_dir}" == "${sonarr_final_dir}" ]]; then
echo "[Torrent Cleanup] Single file torrent, exiting."
exit
fi
if find "${sonarr_episodefile_sourcefolder}" -iregex '.*\.r[0-9a][0-9r]$' | grep -Eq '.*'; then
echo "[Torrent Cleanup] Found rar or r00 files, deleting video file."
rm "${sonarr_episodefile_sourcepath}"
else
echo "[Torrent Cleanup] No rar files, exiting."
fi
@BlindByrd
Copy link
Author

BlindByrd commented Jan 29, 2019

  1. Have your Torrent client extract the file into the same folder that the rar's are in. For Deluge, I am using the built-in Extractor plugin. Extractor Picture

  2. Modify sonarr_cleanup_packed_torrent.sh for your file structure, then download and extract where you want to store it.

  • For my modification to the script, I have my torrent client put completed torrents in /data/Complete (which is mapped to /mnt/user/Downloads/Complete).
  1. Navigate to the file in Windows, right click > properties > security tab > enable read & execute for all listed users, mine are "everyone", "nobody", and "users". Security Picture. If you do not enable this, Sonarr will give you an Access Denied error when running the script.

  2. Make sure your Sonarr docker has access to where you put the script file, for example I put mine in a new share called Scripts, so I added /Scripts to Sonarr's access. Sonarr Access in unRAID

  3. In Sonarr settings, go to connect > + > custom script. Name it whatever you like. Disable "On Grab", Enable "On Download" and "On Upgrade", Disable "On Rename". Leave "filter series tags" blank. For the path, navigate to the location of the script. If you did not give Sonarr access to the script's location you will not be able to find it here. Leave "arguments" blank. Test and make sure it succeeds. Hit save. Script Picture

Important: If you are getting an error that says "Unable to send OnDownload notification to: ..."
This error is caused by Sonarr not having permission to execute the script. In windows, navigate to the file, right click > properties > security tab > edit -- Check Allow for Read & execute for all users. My user names were: "Everyone" "nobody (Unix User\nobody)" and "users (Unix group\users)". Then hit "Okay"

This can also be modified to work with Radarr! Just change all the instances of sonarr in the code to radarr and fix the permission with windows.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment