Skip to content

Commit 2b972a5

Browse files
committed
Script optimization by @otapi (partially)
1 parent 97a18f2 commit 2b972a5

File tree

2 files changed

+29
-29
lines changed

2 files changed

+29
-29
lines changed

tracker-add-auto-router.sh

100644100755
File mode changed.

tracker-add-auto.sh

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,38 @@
33
auth=user:password
44
host=localhost
55

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 ${trans} --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+
634
trans="$(which transmission-remote) $host --auth=$auth"
735
while true ; do
836
sleep 25
937

10-
add_trackers () {
11-
torrent_hash=$1
12-
id=$2
13-
trackerslist=/tmp/trackers.txt
14-
for base_url in https://raw.githubusercontent.com/ngosang/trackerslist/master/trackers_all.txt ; do
15-
if [ ! -f $trackerslist ]; then
16-
curl -o "$trackerslist" "${base_url}"
17-
fi
18-
Local=$(wc -c < $trackerslist)
19-
Remote=$(curl -sI "${base_url}" | awk '/Content-Length/ {sub("\r",""); print $2}')
20-
if [ "$Local" != "$Remote" ]; then
21-
curl -o "$trackerslist" "${base_url}"
22-
fi
23-
echo "URL for ${base_url}"
24-
echo "Adding trackers for $torrent_name..."
25-
for tracker in $(cat $trackerslist) ; do
26-
echo -n "${tracker}..."
27-
if ${trans} --torrent "${torrent_hash}" -td "${tracker}" | grep -q 'success'; then
28-
echo ' done.'
29-
else
30-
echo ' already added.'
31-
fi
32-
done
33-
done
34-
sleep 3m
35-
rm -f "/tmp/TTAA.$id.lock"
36-
}
37-
3838
# Get list of active torrents
3939
ids="$(${trans} --list | grep -vE 'Seeding|Stopped|Finished|[[:space:]]100%[[:space:]]' | grep '^ ' | awk '{ print $1 }' | grep -vE 'ID')"
4040
for id in $ids ; do
@@ -52,8 +52,8 @@ while true ; do
5252
if [ "$add_date_t" = "$dater" -o "$add_date_t" = "$dateo" ]; then
5353
hash="$(${trans} --torrent "$id" --info | grep '^ Hash: ' | awk '{ print $2 }')"
5454
torrent_name="$(${trans} --torrent "$id" --info | grep '^ Name: ' |cut -c 9-)"
55-
add_trackers "$hash" "$id" &
5655
touch "/tmp/TTAA.$id.lock"
56+
add_trackers "$hash" "$id" &
5757
fi
5858
fi
5959
done

0 commit comments

Comments
 (0)