Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save pythoninthegrass/554e3c61a8c0dbb20c66d818371f3627 to your computer and use it in GitHub Desktop.
Save pythoninthegrass/554e3c61a8c0dbb20c66d818371f3627 to your computer and use it in GitHub Desktop.
Transmission-Daemon: Remove Completed Torrents
#!/usr/bin/env bash
# SOURCE: https://gist.github.com/ffcruz85/6c9fb792fce4af0c4cb561fd653c86b6
# Script to check for complete torrents in transmission folder, then stop and move them
# either hard-code the MOVEDIR variable here…
MOVEDIR='/data/complete'
# TODO: read $env vars or file
# Creds
USER=""
PASS=""
# use transmission-remote to get torrent list from transmission-remote list
# use sed to delete first / last line of output, and remove leading spaces
# use cut to get first field from each line
torrent_list=$(transmission-remote -n "${USER}":"${PASS}" --list | sed -e '1d;$d;s/^ *//' | cut --only-delimited -d ' ' --fields=1)
# for each torrent in the list
for id in "${torrent_list}"; do
id=$(echo "${id}" | sed 's:*::')
# removes asterisk * from torrent ID# which had error associated with it
echo "* * * * * Operations on torrent ID ${id} starting. * * * * *"
# check if torrent download is completed
dl_completed=$(transmission-remote -n "${USER}":"${PASS}" -t "${id}" -i | grep "Percent Done: 100%")
# check torrent’s current state is "Stopped", "Finished", or "Idle"
state_stopped=$(transmission-remote -n "${USER}":"${PASS}" -t "${id}" -i | grep "State: Stopped\|Finished\|Idle")
# if the torrent is "Stopped", "Finished", or "Idle" after downloading 100%…
if [[ ! -z "${dl_completed}" ]] && [[ ! -z "${state_stopped}" ]]; then
# move the files and remove the torrent from Transmission
echo "Torrent $id is completed."
echo "Moving downloaded files to $MOVEDIR."
transmission-remote -n "${USER}":"${PASS}" -t "${id}" -m ${MOVEDIR}
echo "Removing torrent from list."
transmission-remote -n "${USER}":"${PASS}" -t "${id}" -r
else
echo "Torrent $id is not completed. Ignoring."
fi
echo "* * * * * Operations on torrent ID $id completed. * * * * *"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment