Skip to content

Instantly share code, notes, and snippets.

@jhenkens
Last active August 29, 2015 14:02
Show Gist options
  • Save jhenkens/cca1554ac8a5a3ebfb63 to your computer and use it in GitHub Desktop.
Save jhenkens/cca1554ac8a5a3ebfb63 to your computer and use it in GitHub Desktop.

These are some scripts I have to manage two versions of transmission that I run on my server. transmission.sh is the script I use with transmission's script-torrent-done. It gets the torrent, and copies all of its files to another hard drive, but leaves the original copies alone. It then calls my sickbeard post-processing script on the copy-directory, and the sickbeard post processing script does all the deleting it wants.

The second script I call now and then to move all the torrents from my sickbeard managed instance of transmission over to my normal instance of transmission. I didn't want to do this automatically as part of the script-torrent-done because sometimes I will set shows to sequential download (using the patch in another one of my gists) and watch them as they are downloading on XBMC. I wouldn't want those files to disappear while watching them! So instead I just call this script manually. Maybe I'll crontab it once a week or something, I don't know.

#! /bin/bash
set -x
TORRENT_ID=$1
TORRENT_HASH=$2
TORRENT_DIR=$3
TORRENT_NAME=$4
TR_REMOTE="/usr/local/bin/transmission-remote"
SCRIPT_PATH="/home/sabnzbd/sickbeardsabautocompletescripts"
LOG_PATH="$SCRIPT_PATH/transmission.complete.log.d"
LOGFILE="$LOG_PATH/transmission-completed-$TORRENT_NAME-$(date +"%Y%m%d%H%M%S").log"
HOST="http://daenerys.lan/transmission-sickbeard"
DEST_DIR="/mnt/data/Transmission.Downloads/sickbeard"
if [[ "$#" != "4" ]]; then
exit 1;
fi
echo $@ >> "$LOGFILE"
echo about to execute $TR_REMOTE $HOST -t $TORRENT_ID -f \| tail -n +3 \| cut -c 35- >> "$LOGFILE"
FILES=$($TR_REMOTE $HOST -t $TORRENT_ID -f | tail -n +3 | cut -c 35-)
echo transmission-worker.sh running on `date` >> "$LOGFILE"
echo Directory is "$TORRENT_DIR" >> "$LOGFILE"
echo Torrent ID is "$TORRENT_ID" >> "$LOGFILE"
echo Torrent Hash is "$TORRENT_HASH" >> "$LOGFILE"
echo "Files are:" >> "$LOGFILE"
echo "$FILES" >> "$LOGFILE"
IFS=$'\n'
echo "Beginning copy block:" >> "$LOGFILE"
for file in $FILES; do
file_dest_dir="$DEST_DIR/$(dirname $file)"
mkdir -p "$file_dest_dir"
echo "Copying $TORRENT_DIR/$FILE to $file_dest_dir" >> "$LOGFILE"
cp "$TORRENT_DIR/$file" "$file_dest_dir"
done
cd /home/sabnzbd/sickbeardsabautocompletescripts
echo "Beginning sickbeard callback" >> "$LOGFILE"
./sabToSickBeardTransmission.py "$DEST_DIR" >> "$LOGFILE"
#! /bin/bash
SCRIPT_PATH="/home/sabnzbd/sickbeardsabautocompletescripts"
cd $SCRIPT_PATH
echo "Calling: ./transmission-worker.sh \"$TR_TORRENT_ID\" \"$TR_TORRENT_HASH\" \"$TR_TORRENT_DIR\" \"$TR_TORRENT_NAME\""
./transmission-worker.sh "$TR_TORRENT_ID" "$TR_TORRENT_HASH" "$TR_TORRENT_DIR" "$TR_TORRENT_NAME"
#! /bin/bash
SICK_HOST="http://daenerys.lan/transmission-sickbeard"
DEST_DIR="/mnt/WD1TB1/Torrents/"
TMP_DIR=$(mktemp -d -t transmission-done-script-XXXXXX)
WATCH_DIR="/home/transmission/watch"
TORRENTS_DIR="/var/lib/transmission-daemon/info-sickbeard/torrents"
sudo chmod g+r "$TORRENTS_DIR"/*
echo "All torrents:"
transmission-remote $SICK_HOST --list
IDS=$(transmission-remote $SICK_HOST --list | sed '$d' | sed "1d" | awk '{ if ($5 == "Done") {print $1}}')
IFS=$'\n'
for id in $IDS; do
echo "Transfering torrent: $id"
transmission-remote $SICK_HOST -t $id --move "$DEST_DIR"
HASH=$(transmission-remote $SICK_HOST -t $id -i | sed -n -r 's/^ Hash: (.{12}).*$/\1/p')
find $TORRENTS_DIR -name "*$HASH*.torrent" -type f -exec cp {} $TMP_DIR/ \;
transmission-remote $SICK_HOST -t $id --remove
done
cp "$TMP_DIR"/* "$WATCH_DIR"
#rm -r "$TMP_DIR"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment