Skip to content

Instantly share code, notes, and snippets.

@antaflos
Forked from RobertDeRose/unrarer.sh
Created May 21, 2019 23:18
Show Gist options
  • Save antaflos/d2f77700b8c3e02e893156f4f6036c0b to your computer and use it in GitHub Desktop.
Save antaflos/d2f77700b8c3e02e893156f4f6036c0b 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment