Code: Select all
#!/bin/bash
# Script to be executed by Deluge on seedbox when torrent downloads complete which organizes files using filebot and uploads to SFTP site
# Variables
login=xxxxxx
pass=xxxxxx
host=sftp://www.xxxxxx.com:xxxx
remote_dir="/remote/path/to/Complete"
local_dir="/local/path/to/Complete"
# Get arguments from Deluge
torrent_name=$2
torrent_path=$3
# Run FileBot on completed torrent download to extract, rename and hardlink into 'Complete' directory
filebot -script fn:amc --output "$local_dir" --log-file amc.log --action hardlink --conflict override -non-strict --def music=y artwork=y "ut_dir=$torrent_path/$torrent_name" "ut_kind=multi" "ut_title="
# Lock upload
trap "rm -f /tmp/synctorrent.lock" SIGINT SIGTERM
if [ -e /tmp/synctorrent.lock ]
then
echo "Synctorrent is running already."
exit 1
else
touch /tmp/synctorrent.lock
# Upload 'Complete' directory to SFTP and remove source files when complete to save space on seedbox
lftp -u $login,$pass $host << EOF
set ftp:ssl-allow true
set ftp:ssl-force true
set mirror:use-pget-n 5
mirror -R -c --Remove-source-files --log=upload_complete.log $local_dir $remote_dir
quit
EOF
# Unlock upload
rm -f /tmp/synctorrent.lock
exit 0
fi