Skip to content

Instantly share code, notes, and snippets.

@JSouthGB
Created July 19, 2022 03:53
Show Gist options
  • Save JSouthGB/5b48201d18635f13569f090b802039a0 to your computer and use it in GitHub Desktop.
Save JSouthGB/5b48201d18635f13569f090b802039a0 to your computer and use it in GitHub Desktop.
#!/bin/bash
# deluge2rtorrent
# deluge handles downloading and initial sorting
# this script is to move everything to rtorrent
# torrents and torrent data only
# torrent info will not be preserved (seed time, etc)
# -P flag and echo because i dont run this unattended
# this is quick and dirty, i have no idea what im doing
# deluge sorts into directories based on labels
# this is where they end up
TVSHOWS="/home/user/media/tvshows/"
MOVIES="/home/user/media/movies/"
# path to deluge and rtorrent torrent data directories
# rtorrent is used for long term seeding
# anything seeded by rtorrent isnt sorted
DELUGE="/home/user/deluge_data/"
RTORRENT="/home/user/rtorrent_data/"
# rtorrent watch directory
RWATCH="/home/user/rwatch/"
# deluge state directory
STATE="/home/user/.config/deluge/state/"
# copy sorted deluge torrent data to rtorrent data folder
echo rclone copy -P $TVSHOWS $RTORRENT
rclone copy -P $TVSHOWS $RTORRENT
echo \
echo rclone copy -P $MOVIES $RTORRENT
rclone copy -P $MOVIES $RTORRENT
echo \
# for torrents that dont get sorted
echo rclone copy -P $DELUGE $RTORRENT
rclone copy -P $DELUGE $RTORRENT
echo \
# copy torrent files from deluge state folder
# to rtorrent watch folder
echo rclone copy -P $STATE $RWATCH --include "*.torrent"
rclone copy -P $STATE $RWATCH --include "*.torrent"
echo \
# the below loop is from Vivek Gite @
# https://www.cyberciti.biz/faq/bash-loop-over-file/
# get torrent path and filename
FILES="$STATE*.torrent"
# loop through each file
for f in $FILES
do
# FAILSAFE #
# Check if "$f" FILE exists and is a regular file and then only copy it #
if [ -f "$f" ]
then
filepath="$f"
# reduce torrent file name to torrent hash
filename=$(basename "$filepath")
# echo each torrent hash as deleted
echo "Deleting ${filename%.*}"
# connect to deluge-console and rm torrent and torrent data
deluge-console "connect 127.0.0.1:58846 user pass ; rm '${filename%.*}' --remove_data ; exit"
# if deluge state dir is empty (no torrents)
else
echo "Nothing to copy or remove."
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment