Skip to content

Instantly share code, notes, and snippets.

@subzero79
Last active October 12, 2022 01:14
Show Gist options
  • Save subzero79/87a347a07964390884c9 to your computer and use it in GitHub Desktop.
Save subzero79/87a347a07964390884c9 to your computer and use it in GitHub Desktop.
Sonarr post processing script to clean video files if the source is rar (packed) content
#!/bin/bash
#sonarr_episodefile_sourcefolder="/torrent/finish/tv-sonarr/Penny.Dreadful.S01E01.720p.HDTV.x264-2HD"
#sonarr_episodefile_sourcepath="/torrent/finish/tv-sonarr/Penny.Dreadful.S01E01.720p.HDTV.x264-2HD/penny.dreadful.s01e01.720p.hdtv.x264-2hd.mkv"
sonarr_label="tv-sonarr"
base_dir=$(basename $sonarr_episodefile_sourcefolder)
if [ "${base_dir}" == "${sonarr_label}" ];then
echo "Single file torrent"
exit
fi
find $sonarr_episodefile_sourcefolder -name \*.r[0-9][0-9] | egrep '.*' &>/dev/null
case $? in
0)
echo "Rar files present, deleting video files"
echo `rm -rv "${sonarr_episodefile_sourcepath}"`
;;
*)
echo "No rar files, nothing to clean"
;;
esac
@CyCLoBoT
Copy link

CyCLoBoT commented Nov 4, 2017

I also tried this script and it deleted the entire data folder where the torrents are downloaded. I am using Deluge client. How can I configure this script so that it deletes the video file and keeps the rar files? My downloads go under torrents/data and Sonarr moves the extracted video files to Media/TV.

@fryfrog
Copy link

fryfrog commented Jun 13, 2018

I wish I'd realized you could fork a gist, but I suggest -iregex '.*\.r[0-9a][0-9r]$' for your find argument. It accounts for (rare) files named like part01.rar as well as numbered .r00 files. Though I suppose it could choke if the movie isn't really rar'd, but instead comes w/ a small .rar file for some reason.

My version: https://gist.github.com/fryfrog/94716e7e27ba38dff57c7631d9f58bed

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