Skip to content

Commit bbb1261

Browse files
committed
Merge remote-tracking branch 'parent/master'
# Conflicts: # tracker-add-auto.sh
2 parents df9f472 + a764d6e commit bbb1261

File tree

2 files changed

+53
-48
lines changed

2 files changed

+53
-48
lines changed

README.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,11 @@ A: Yes, host=host:port or host=http(s?)://host:port/transmission/
2020

2121
<details>
2222
<summary>Changelog</summary>
23-
23+
2424
```
25+
Mar 10, 2020
26+
avoid add trackers for private torrents
27+
2528
Mar 27, 2019
2629
add tracker-add-auto-router.sh script for routers
2730
now tracker file saved in tmp directory until update web source
@@ -59,9 +62,9 @@ Take image `docker pull andrewmhub/transmission-tracker-add`
5962

6063
```docker run --net=host -d -e HOSTPORT=localhost:9091 -e TR_AUTH=user:password --name=transmission-tracker-add andrewmhub/transmission-tracker-add:latest```
6164

62-
if you need another torrent tracker list then use docker run env
65+
if you need another torrent tracker list then use docker run env
6366

64-
`-e TORRENTLIST=https://raw.githubusercontent.com/user/trackerslist/master/mylist.txt`
67+
`-e TORRENTLIST=https://raw.githubusercontent.com/user/trackerslist/master/mylist.txt`
6568

6669
you have transmission daemon in docker then read [Docker Documentation Network](https://docs.docker.com/network/)
6770

@@ -91,7 +94,7 @@ systemctl status transmission-tracker-add.service
9194
CGroup: /system.slice/transmission-tracker-add.service
9295
├─19102 /bin/bash /opt/bin/add-trackers-auto.sh
9396
└─31204 sleep 5
94-
97+
9598
```
9699

97100

@@ -123,7 +126,7 @@ Requirements: curl, transmission-remote
123126

124127
Download script and make it executable:
125128

126-
Edit settings for transmission set rpc-enabled, rpc-username and rpc-password
129+
Edit settings for transmission set rpc-enabled, rpc-username, rpc-password and your pt trackers
127130

128131
```
129132
wget --no-check-certificate -O tracker-add-auto-router.sh https://raw.githubusercontent.com/AndrewMarchukov/tracker-add/master/tracker-add-auto-router.sh

tracker-add-auto.sh

Lines changed: 45 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2,58 +2,60 @@
22
# Get transmission credentials and ip or dns address
33
auth=user:password
44
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 ${trans} --torrent "${torrent_hash}" -td "${tracker}" | grep -q 'success'; then
24-
echo ' done.'
25-
else
26-
echo ' failed.'
27-
fi
28-
done
29-
done
30-
sleep 180
31-
rm -f "/tmp/TTAA.$id.lock"
32-
}
5+
# set trackers list space separated
6+
trackers=https://raw.githubusercontent.com/ngosang/trackerslist/master/trackers_all.txt
7+
pt_trackers=()
338

349
trans="/usr/local/bin/transmission-remote $host --auth=$auth"
35-
while true ; do
36-
sleep 25
3710

11+
while true; do
12+
sleep 25
13+
add_trackers() {
14+
torrent_hash=$1
15+
id=$2
16+
trackerslist=/tmp/trackers.txt
17+
for base_url in $trackers; do
18+
if [ ! -f $trackerslist ]; then
19+
curl -o "$trackerslist" "${base_url}"
20+
fi
21+
Local=$(wc -c <$trackerslist)
22+
Remote=$(curl -sI "${base_url}" | awk '/Content-Length/ {sub("\r",""); print $2}')
23+
if [ "$Local" != "$Remote" ]; then
24+
curl -o "$trackerslist" "${base_url}"
25+
fi
26+
echo "URL for ${base_url}"
27+
echo "Adding trackers for $torrent_name..."
28+
for tracker in $(cat $trackerslist); do
29+
echo -n "${tracker}..."
30+
if ${trans} --torrent "${torrent_hash}" -td "${tracker}" | grep -q 'success'; then
31+
echo ' done.'
32+
else
33+
echo ' already added.'
34+
fi
35+
done
36+
done
37+
sleep 3m
38+
rm -f "/tmp/TTAA.$id.lock"
39+
}
3840
# Get list of active torrents
39-
ids="$(${trans} --list | grep -vE 'Seeding|Stopped|Finished|[[:space:]]100%[[:space:]]' | grep '^ ' | awk '{ print $1 }' | grep -vE 'ID')"
40-
for id in $ids ; do
41-
add_date="$(${trans} --torrent "$id" --info| grep '^ Date added: ' |cut -c 21-)"
42-
if [ "$(uname)" = "FreeBSD" ]; then
43-
add_date_t="$(date -jf "%+" "$add_date" "+%Y-%m-%d %H:%M")"
44-
dateo="$(date -jv-1M "+%Y-%m-%d %H:%M")"
45-
else
46-
add_date_t="$(date -d "$add_date" "+%Y-%m-%d %H:%M")"
47-
dateo="$(date -d "1 minutes ago" "+%Y-%m-%d %H:%M")"
48-
fi
41+
ids="$(${trans} --list | grep -vE 'Seeding|Stopped|Finished|[[:space:]]100%[[:space:]]' | grep '^ ' | awk '{ print $1 }')"
42+
for id in $ids; do
43+
add_date="$(${trans} --torrent "$id" --info | grep '^ Date added: ' | cut -c 21-)"
44+
add_date_t="$(date -d "$add_date" "+%Y-%m-%d %H:%M")"
4945
dater="$(date "+%Y-%m-%d %H:%M")"
46+
dateo="$(date -d "1 minutes ago" "+%Y-%m-%d %H:%M")"
47+
tracker0="$(${trans} -t "$id" -it | sed -n '2,2p' | awk '{print $3}' | awk -F : '{print $2}' | sed -e 's/\/\///')"
48+
if [[ " ${pt_trackers[@]} " =~ " $tracker0 " ]]; then
49+
echo "skip id=" "$id" "$tracker0"
50+
continue
51+
fi
5052

5153
if [ ! -f "/tmp/TTAA.$id.lock" ]; then
52-
if [ "$add_date_t" = "$dater" -o "$add_date_t" = "$dateo" ]; then
54+
if [[ "( "$add_date_t" == "$dater" || "$add_date_t" == "$dateo" )" ]]; then
5355
hash="$(${trans} --torrent "$id" --info | grep '^ Hash: ' | awk '{ print $2 }')"
54-
torrent_name="$(${trans} --torrent "$id" --info | grep '^ Name: ' |cut -c 9-)"
55-
touch "/tmp/TTAA.$id.lock"
56+
torrent_name="$(${trans} --torrent "$id" --info | grep '^ Name: ' | cut -c 9-)"
5657
add_trackers "$hash" "$id" &
58+
touch "/tmp/TTAA.$id.lock"
5759
fi
5860
fi
5961
done

0 commit comments

Comments
 (0)