-
Notifications
You must be signed in to change notification settings - Fork 0
/
transmission-clean.sh
51 lines (40 loc) · 2.18 KB
/
transmission-clean.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash
# Description:
# Checks for complete torrents in transmission, removes them from queue if global
# (or torrent's ratio) reached.
USER="$1"
PASSWORD="$1"
# get default ratio limit value
DEFAULT_RATIOLIMIT=`transmission-remote --auth=$USER:$PASSWORD -si | grep "Default seed ratio limit:" | cut -d \: -f 2 | sed 's/^ *//' | sed 's/[0]*$//g'`
# get torrent list from transmission-remote list
# delete first / last line of output
# remove leading spaces
# get first field from each line
TORRENTLIST=`transmission-remote --auth=$USER:$PASSWORD --list | sed -e '1d;$d;s/^ *//' | cut -s -d " " -f1`
# for each torrent in the list
for TORRENTID in $TORRENTLIST
do
# use torrent own ratio limit, if present
RATIOLIMIT=`transmission-remote --auth=$USER:$PASSWORD --torrent $TORRENTID --info | grep "Ratio Limit:" | cut -d \: -f 2 | sed 's/^ *//' | sed 's/[0]*$//g'`
if [ $RATIOLIMIT = "Default" ]; then
RATIOLIMIT=$DEFAULT_RATIOLIMIT
fi
# check if torrent was started
STARTED=`transmission-remote --auth=$USER:$PASSWORD --torrent $TORRENTID --info | grep "Id: $TORRENTID" | sed 's/^ *//'`
# check if torrent download is completed
COMPLETED=`transmission-remote --auth=$USER:$PASSWORD --torrent $TORRENTID --info | grep "Percent Done: 100%" | sed 's/^ *//'`
# check torrent's current state is "Stopped"
STOPPED=`transmission-remote --auth=$USER:$PASSWORD --torrent $TORRENTID --info | grep "State: Finished" | sed 's/^ *//'`
# check to see if ratio-limit-enabled is true
if [ $RATIOLIMIT != "Unlimited" ]; then
# check if torrent's ratio matches ratio-limit
CAPPED=`transmission-remote --auth=$USER:$PASSWORD --torrent $TORRENTID --info | grep "Ratio: $RATIOLIMIT" | sed 's/^ *//'`
else
CAPPED=""
fi
# if the torrent is "Stopped" after downloading 100% and seeding, move the files and remove the torrent from Transmission
if [ "$STARTED" != "" ] && [ "$COMPLETED" != "" ] && [ "$STOPPED" != "" ] && [ "$CAPPED" != "" ]; then
TR_TORRENT_NAME=`transmission-remote --auth=$USER:$PASSWORD --torrent $TORRENTID --info | grep -oP "(?<=Name: ).+"`
transmission-remote --auth=$USER:$PASSWORD --torrent $TORRENTID --remove
fi
done