Default Location: ~\Torrents\Completed
Keep Incomplete Files In: ~\Torrents\Incomplete
Call Script When Download Completes: txunrar.sh
The script runs fine but it doesn't seem to extract any files. I have Unrar installed which I did so using Homebrew and when laucnhing the unrar command it does work however, it seems like the script isn't picking up the RAR files when extracting.
Here are the contents of txunrar.sh. Any ideas/suggestions would be appreciated.
Code: Select all
#!/bin/sh
if [ -z "$TR_TORRENT_DIR" ]; then
TR_TORRENT_DIR="/nodir"
fi
if [ -z "$TR_TORRENT_NAME" ]; then
TR_TORRENT_NAME="nofile"
fi
EXTRACT_DIR=~/Torrents/Extracted
LOG_FILE="$EXTRACT_DIR/expand.log"
TORRENT_PATH="$TR_TORRENT_DIR/$TR_TORRENT_NAME"
# create the extraction directory if it doesn't exist
if [ ! -d "$EXTRACT_DIR" ]; then
mkdir -p "$EXTRACT_DIR"
fi
function log() {
echo "`date` - $TORRENT_PATH - $1" >> "$LOG_FILE"
}
log "Extracting torrent"
# torrent is a single file
if [ -f "$TORRENT_PATH" ]; then
TORRENT_EXT="${TR_TORRENT_NAME##*.}"
if [ "rar" == "$TORRENT_EXT" ]; then
unrar e -y "$TORRENT_PATH" "$EXTRACT_DIR" > /dev/null
else
log "Error: Torrent is not a RAR file"
fi
# torrent is a directory
elif [ -d "$TORRENT_PATH" ]; then
RAR_FILES=`find "$TORRENT_PATH" -name "*.rar"`
if [ ! -z "$RAR_FILES" ]; then
find "$TORRENT_PATH" -name "*.rar" -exec unrar e -y {} "$EXTRACT_DIR" \; > /dev/null
else
log "Error: Torrent does not have a RAR file"
fi
# torrent is not a file or directory
else
log "Error: Torrent is not a file or directory"
fi
if [ ! $? -eq 0 ]; then
log "Error: Extraction of torrent failed"
fi
log "Finished processing torrent"