Skip to content

Instantly share code, notes, and snippets.

@fmoledina
Forked from RobertDeRose/unrarer.sh
Last active June 11, 2019 23:05
Show Gist options
  • Save fmoledina/3bf792adb5a671448682969307c5e515 to your computer and use it in GitHub Desktop.
Save fmoledina/3bf792adb5a671448682969307c5e515 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 testing, but it works well for my needs
extract_rar() {
isRar=$(ls ./*.rar)
if [ -n "$isRar" ]; then
# Handle an edge case with some distributors
isPart01="$(ls ./*rar | grep -E part0*1.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 /media/temp/unrar-staging
fileName="$(unrar e -y "$toUnrar" | grep -E "^\\.\\.\\..*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" || exit
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment