Forked from pawelszydlo/transmission_remove_finished.sh
Last active
June 17, 2022 12:37
-
-
Save rostislavzz/5a2567bb343fc0e6c65e83ee52e95b6e to your computer and use it in GitHub Desktop.
Script to clear completed torrents from Transmission by location and ratio to use with Docker container https://hub.docker.com/r/linuxserver/transmission/. Place "remove-completed-torrent.sh" to "/config", and "add-cron-job.sh" to "/config/custom-cont-init.d".
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [ -z "$(crontab -l | grep 'remove-completed-torrent.sh')" ]; then | |
crontab -l | { cat; echo "0 3 * * * /config/remove-completed-torrent.sh 2>&1"; } | crontab - | |
fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/with-contenv bash | |
LOCATION="/downloads/movies" | |
MAX_RATIO=5 | |
# use transmission-remote to get torrent list | |
TORRENTLIST=`transmission-remote --auth $USER:$PASS --list | sed -e '1d' -e '$d' | awk '{print $1}' | sed -e 's/[^0-9]*//g'` | |
# for each torrent in the list | |
for TORRENTID in $TORRENTLIST | |
do | |
INFO=$(transmission-remote --auth $USER:$PASS --torrent $TORRENTID --info) | |
IS_MOVIE=`echo $INFO | grep "Location: $LOCATION"` | |
if [ -z "$IS_MOVIE" ]; then | |
continue | |
fi | |
echo -e "Processing #$TORRENTID - $(echo $INFO | sed -e 's/.*Name: \(.*\) Hash.*/\1/')" | |
# get torrent ratio | |
RATIO=`echo $INFO | grep -Eo "Ratio: \d+" | cut -d: -f2 | tr -d [:space:]` | |
# check if torrent download is completed | |
DL_COMPLETED=`echo $INFO | grep "Done: 100%"` | |
# check torrents current state is | |
STATE_STOPPED=`echo $INFO | grep "State: Seeding\|State: Stopped\|State: Finished\|State: Idle"` | |
# if the torrent is "Stopped", "Finished", or "Idle after downloading 100%" | |
if [ "$RATIO" -gt "$MAX_RATIO" ] && [ "$DL_COMPLETED" ] && [ "$STATE_STOPPED" ]; then | |
echo "Torrent #$TORRENTID is completed. Removing torrent and delete local data." | |
transmission-remote --auth $USER:$PASS --torrent $TORRENTID --remove-and-delete | |
else | |
echo "Torrent #$TORRENTID is not completed. Ignoring." | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment