Last active
January 8, 2022 09:23
-
-
Save fryfrog/65e3e0e9ae45af694aa86c1e713fa889 to your computer and use it in GitHub Desktop.
A Sonarr post processing script to turn copied torrent imports into symlinks, strongly encourage hard link setup instead.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
sonarr_label="tv" | |
# Make sure we're working on torrents. | |
if ! [[ "${sonarr_episodefile_sourcepath}" =~ torrent ]]; then | |
echo "[Torrent Symlink] Path ${sonarr_episodefile_sourcepath} does not contain \"torrent\", exiting." | |
exit | |
fi | |
# If the source file doesn't exist, error out. | |
if ! [[ -f "${sonarr_episodefile_sourcepath}" ]]; then | |
echo "[Torrent Symlink] File ${sonarr_episodefile_sourcepath} does not exist, exiting." | |
exit 1 | |
fi | |
# If it isn't a single file, it might be a packed release which should be skipped. | |
base_dir=$( basename "${sonarr_episodefile_sourcefolder}" ) | |
if [[ "${base_dir}" != "${sonarr_label}" ]] && find "${sonarr_episodefile_sourcefolder}" -iregex '.*\.r[0-9a][0-9r]$' | grep -Eq '.*'; then | |
echo "[Torrent Symlink] Found rar or r00 files, skipping symlink creation." | |
exit | |
fi | |
# Make sure the copy is done by comparing source and destination file sizes. | |
orig_file_size=$(stat -c%s "${sonarr_episodefile_sourcepath}") | |
dest_file_size=$(stat -c%s "${sonarr_episodefile_path}") | |
# Make the actual symlink. | |
if [[ ${dest_file_size} == "${orig_file_size}" ]]; then | |
echo -n "[Torrent Symlink] Switching ${sonarr_episodefile_sourcepath} to symlink pointed at ${sonarr_episodefile_path}... " | |
if rm "${sonarr_episodefile_sourcepath}" && ln -s "${sonarr_episodefile_path}" "${sonarr_episodefile_sourcepath}"; then | |
echo "done." | |
else | |
echo "failed." | |
fi | |
else | |
echo "[Torrent Symlink] Size of ${sonarr_episodefile_sourcepath} and ${sonarr_episodefile_path} differ, skipping." | |
fi |
If I knew python, I'd have done it in python. Why don't you have a go at it?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi. Can you please post a python version for both Sonarr and Radarr?