Last active
April 6, 2024 13:34
-
-
Save Mihai-P/100f9b15243993471ced16e8e41e4400 to your computer and use it in GitHub Desktop.
Small script to delete any transmission torrents that are complete
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/sh | |
| # based on this gist https://gist.github.com/pawelszydlo/e2e1fc424f2c9d306f3a | |
| # port, username, password | |
| # if using a seedbox the server can have the format http://SEREVR:PORT/PREFIX/transmission | |
| SERVER="$TRANSMISSION_SERVER -n $TRANSMISSION_USER:$TRANSMISSION_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 | |
| TORRENTLIST=`transmission-remote $SERVER --list | sed -e '1d;$d;s/^ *//' | cut --only-delimited --delimiter=" " --fields=1` | |
| transmission-remote $SERVER --list | |
| # for each torrent in the list | |
| for TORRENTID in $TORRENTLIST | |
| do | |
| echo Processing : $TORRENTID | |
| transmission-remote $SERVER --torrent $TORRENTID --info | grep -e Percent -e State -e Seeding -e Name | |
| # check if torrent download is completed | |
| DL_COMPLETED=`transmission-remote $SERVER --torrent $TORRENTID --info | grep -c "Percent Done: 100"` | |
| # check torrents current state is | |
| STATE_STOPPED=`transmission-remote $SERVER --torrent $TORRENTID --info | grep -c "State: Seeding\|Stopped\|Finished"` | |
| SECONDS_SEEDED=`transmission-remote $SERVER --torrent $TORRENTID --info | grep "Seeding Time" | grep -Po "[0-9]* seconds" | grep -o "^\w*\b"` | |
| # if the torrent is "Stopped", "Finished", or "Idle after downloading 100%" | |
| if ([ "$DL_COMPLETED" -gt "0" ] && [ "$STATE_STOPPED" -gt "0" ]); then | |
| # move the files and remove the torrent from Transmission | |
| echo "Torrent #$TORRENTID is completed" | |
| echo "Removing torrent from list" | |
| transmission-remote $SERVER --torrent $TORRENTID --remove-and-delete | |
| elif [ "$SECONDS_SEEDED" -gt "864000" ]; then | |
| echo "Torrent #$TORRENTID has been seeded for more than 10 days" | |
| echo "Removing torrent from list" | |
| transmission-remote $SERVER --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