Skip to content

Commit 5d6c8b5

Browse files
authored
Performance tunings
- make a readable layout with indents - moved out the method definition from the while-do cycle (potential memory hog) - raised the sleeping of a cycle to 10 minutes - checks torrents only which are idle or downloading. It ignores paused or finished torrents. - tries to add trackers only when the torrent has less than 10 trackers
1 parent eeb20ec commit 5d6c8b5

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

add-trackers-auto.sh

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/bin/bash
2+
# Get transmission credentials and ip or dns address
3+
auth=user:password
4+
host=localhost
5+
6+
add_trackers () {
7+
torrent_hash=$1
8+
id=$2
9+
trackerslist=/tmp/trackers.txt
10+
for base_url in https://raw.githubusercontent.com/ngosang/trackerslist/master/trackers_all.txt ; do
11+
if [ ! -f $trackerslist ]; then
12+
curl -o "$trackerslist" "${base_url}"
13+
fi
14+
Local=$(wc -c < $trackerslist)
15+
Remote=$(curl -sI "${base_url}" | awk '/Content-Length/ {sub("\r",""); print $2}')
16+
if [ "$Local" != "$Remote" ]; then
17+
curl -o "$trackerslist" "${base_url}"
18+
fi
19+
echo "URL for ${base_url}"
20+
echo "Adding trackers for $torrent_name..."
21+
for tracker in $(cat $trackerslist) ; do
22+
echo -n "${tracker}..."
23+
if transmission-remote "$host" --auth="$auth" --torrent "${torrent_hash}" -td "${tracker}" | grep -q 'success'; then
24+
echo ' failed.'
25+
else
26+
echo ' done.'
27+
fi
28+
done
29+
done
30+
sleep 3m
31+
rm -f "/tmp/TTAA.$id.lock"
32+
}
33+
34+
35+
while true ; do
36+
sleep 10m
37+
# Get list of active torrents
38+
ids="$(transmission-remote "$host" --auth="$auth" --list | grep -E 'Idle|Downloading' | grep '^ ' | awk '{ print $1 }')"
39+
for id in $ids ; do
40+
add_date="$(transmission-remote "$host" --auth="$auth" --torrent "$id" --info| grep '^ Date added: ' |cut -c 21-)"
41+
add_date_t="$(date -d "$add_date" "+%Y-%m-%d %H:%M")"
42+
dater="$(date "+%Y-%m-%d %H:%M")"
43+
dateo="$(date -d "1 minutes ago" "+%Y-%m-%d %H:%M")"
44+
45+
if [ ! -f "/tmp/TTAA.$id.lock" ]; then
46+
if [[ "( "$add_date_t" == "$dater" || "$add_date_t" == "$dateo" )" ]]; then
47+
trackers="$(transmission-remote "$host" --auth="$auth" --torrent "$id" -it | wc -l)"
48+
if [[ $trackers -lt 10 ]]; then
49+
hash="$(transmission-remote "$host" --auth="$auth" --torrent "$id" --info | grep '^ Hash: ' | awk '{ print $2 }')"
50+
torrent_name="$(transmission-remote "$host" --auth="$auth" --torrent "$id" --info | grep '^ Name: ' |cut -c 9-)"
51+
touch "/tmp/TTAA.$id.lock"
52+
add_trackers "$hash" "$id" &
53+
fi
54+
fi
55+
fi
56+
done
57+
done

0 commit comments

Comments
 (0)