Skip to content

Instantly share code, notes, and snippets.

@subzero79
Last active October 12, 2022 01:14
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • 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
@stayupthetree
Copy link

Any way to get this to extract the rar files? I can't seem to find a way with ruTorrent

@joq3
Copy link

joq3 commented Oct 25, 2017

Hi subzero,
Just found this script, exactly what I need. I have a script that runs after unrar after Transmission is finished downloading.
Which then Sonarr or Radarr process and what is left is the folder with all the RAR-files and the unrar'ed file which I would like to remove, only to keep the rar-files for seeding.
From what I understand this is it.

I tried it out, set my Completed folder to this:
#sonarr_episodefile_sourcefolder=/pathtomycompletefolder/
and this #sonarr_episodefile_sourcepath=/pathtomycompletefolder/

What happened was that it removed the whole folder in that path.
How do I make it to only delete the movie/tv series files that are extracted? And only from Sonarr and Radarr?

Thank you!

@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