Skip to content

Instantly share code, notes, and snippets.

@RobertDeRose
Last active November 18, 2022 10:04
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save RobertDeRose/9391f5da6273eab26f00d2e7c3c945d3 to your computer and use it in GitHub Desktop.
Save RobertDeRose/9391f5da6273eab26f00d2e7c3c945d3 to your computer and use it in GitHub Desktop.
Transmission unrar script to handle Sonarr from prematurely moving files
#!/bin/bash
# The script could use more tesing, but it works well for my needs
function extract_rar() {
isRar=$(ls | grep *.rar)
if [ -n "$isRar" ]; then
# Handle an edge case with some distributors
isPart01="$(ls *.rar | egrep -i 'part01.rar|part1.rar')"
if [ -n "$isPart01" ]; then
isRar=$isPart01
fi
toUnrar="$(pwd)/$isRar"
# we need to move to new location so sonarr doesn't try to mv before its done
# also, unrar doesn't support changing the filename on extracting, makes sense a little bit
pushd /mnt/media/Bittorrent/unrar_staging
fileName="$(unrar e -y $toUnrar | egrep "^\.\.\..*OK" | awk '{ print $2 }')"
# put it back so sonarr can now find it
mv $fileName $(dirname $toUnrar)
popd
fi
}
echo "Starting - $(date)"
cd "$TR_TORRENT_DIR"
if [ -d "$TR_TORRENT_NAME" ]; then
cd "$TR_TORRENT_NAME"
#handle multiple episode packs, like those that contain a whole season, or just a single episode
for rar in $(find . -name '*.rar' -exec dirname {} \; | sort -u);
do
pushd $rar
extract_rar
popd
done
fi
@peelos
Copy link

peelos commented Oct 11, 2016

This is exactly what I was looking for, unfortunately cannot get it to run - what permissions should the unrarer.sh file have?

@RobertDeRose
Copy link
Author

Sorry @peelos, I am just seeing this comment. I have it set to 755 owned by the same user that Transmission runs under.

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