Last active
September 29, 2023 15:58
-
-
Save fryfrog/b743b523f8cb79ba64e4b466e292c077 to your computer and use it in GitHub Desktop.
A Radarr 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 | |
radarr_label="movies" | |
# Make sure we're working on torrents. | |
if ! [[ "${radarr_moviefile_sourcepath}" =~ torrent ]]; then | |
echo "[Torrent Symlink] Path ${radarr_moviefile_sourcepath} does not contain \"torrent\", exiting." | |
exit | |
fi | |
# If the source file doesn't exist, error out. | |
if ! [[ -f "${radarr_moviefile_sourcepath}" ]]; then | |
echo "[Torrent Symlink] File ${radarr_moviefile_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 "${radarr_moviefile_sourcefolder}" ) | |
if [[ "${base_dir}" != "${radarr_label}" ]] && find "${radarr_moviefile_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 "${radarr_moviefile_sourcepath}") | |
dest_file_size=$(stat -c%s "${radarr_moviefile_path}") | |
# Make the actual symlink. | |
if [[ ${dest_file_size} == "${orig_file_size}" ]]; then | |
echo -n "[Torrent Symlink] Switching ${radarr_moviefile_sourcepath} to symlink pointed at ${radarr_moviefile_path}... " | |
if rm "${radarr_moviefile_sourcepath}" && ln -s "${radarr_moviefile_path}" "${radarr_moviefile_sourcepath}"; then | |
echo "done." | |
else | |
echo "failed." | |
exit 1 | |
fi | |
else | |
echo "[Torrent Symlink] Size of ${radarr_moviefile_sourcepath} and ${radarr_moviefile_path} differ, skipping." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment