Skip to content

Commit 3230216

Browse files
committed
Merge branch 'AndrewMarchukov:master' into master
2 parents 618054d + a764d6e commit 3230216

File tree

5 files changed

+225
-58
lines changed

5 files changed

+225
-58
lines changed

README.md

Lines changed: 102 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,86 @@
1-
# Get more trackers
1+
# Get more trackers, get more seeders, get more peers transmission [![](https://images.microbadger.com/badges/version/andrewmhub/transmission-tracker-add.svg)](https://microbadger.com/images/andrewmhub/transmission-tracker-add) ![Docker Pulls](https://img.shields.io/docker/pulls/andrewmhub/transmission-tracker-add.svg) ![GitHub top language](https://img.shields.io/github/languages/top/AndrewMarchukov/tracker-add.svg)
2+
See no peers,seeds for some torrent(s)? Add more tracker(s) for Transmission
23

3-
See no peers for some torrent(s)? Add more tracker(s) from Transmission
4+
This script automatically checks new torrents and adds trackers
5+
6+
<details>
7+
<summary>FAQ:</summary>
8+
9+
```
10+
Q: Requirements?
11+
A: curl, transmission-remote or\and transmission-cli
12+
13+
Q: How often does this check for updates for new trackers?
14+
A: Only when adding new torrent in transmission and only active torrents and gap 25 seconds
15+
16+
Q: Can I add tracker to a remote server?
17+
A: Yes, host=host:port or host=http(s?)://host:port/transmission/
18+
```
19+
</details>
20+
21+
<details>
22+
<summary>Changelog</summary>
23+
24+
```
25+
Mar 10, 2020
26+
avoid add trackers for private torrents
27+
28+
Mar 27, 2019
29+
add tracker-add-auto-router.sh script for routers
30+
now tracker file saved in tmp directory until update web source
31+
new exception in "Get list of active torrents", helps to avoid fully loaded torrents
32+
cosmetic fixes
33+
34+
Feb 22, 2019
35+
add feature connection to host
36+
37+
May 27, 2018
38+
wait new torrents 25 sec
39+
40+
May 26, 2018
41+
Change systemd policy
42+
CPUSchedulingPolicy=idle
43+
Nice=19
44+
```
45+
</details>
46+
47+
#### Choose your destiny:
48+
49+
[Docker way](https://github.com/AndrewMarchukov/tracker-add#-docker-way)
50+
51+
[Systemd way](https://github.com/AndrewMarchukov/tracker-add#-systemd-way)
52+
53+
[Simple way (for routers)](https://github.com/AndrewMarchukov/tracker-add#-simple-way-for-routers)
54+
55+
## Installation and usage
56+
57+
#### * Docker way
58+
59+
Take image `docker pull andrewmhub/transmission-tracker-add`
60+
61+
```docker run --net=host -d -e HOSTPORT=localhost:9091 -e TR_AUTH=user:password --name=transmission-tracker-add andrewmhub/transmission-tracker-add:latest```
62+
63+
if you need another torrent tracker list then use docker run env
64+
65+
`-e TORRENTLIST=https://raw.githubusercontent.com/user/trackerslist/master/mylist.txt`
66+
67+
you have transmission daemon in docker then read [Docker Documentation Network](https://docs.docker.com/network/)
68+
69+
70+
#### * Systemd way
71+
72+
Download script and make it executable:
73+
74+
Edit settings.json for transmission set rpc-enabled, rpc-username and rpc-password
475

5-
## Installation
6-
* Download script and make it executable:
7-
Edit settings for transmission set rpc-enabled, rpc-username and rpc-password
876
```
977
wget --no-check-certificate -O /opt/bin/add-trackers-auto.sh https://raw.githubusercontent.com/zcq100/tracker-add/master/tracker-add-auto.sh
1078
wget --no-check-certificate -O /etc/systemd/system/transmission-tracker-add.service https://raw.githubusercontent.com/zcq100/tracker-add/master/transmission-tracker-add.service
1179
chmod +x /opt/bin/add-trackers-auto.sh
12-
Set user and password in add-trackers-auto.sh
13-
systemctl daemon-reload
1480
```
15-
## Usage
16-
Automatically checks new torrents and adds trackers:
81+
Set user and password in add-trackers-auto.sh
1782
```
83+
systemctl daemon-reload
1884
systemctl enable transmission-tracker-add.service
1985
systemctl start transmission-tracker-add.service
2086
@@ -26,13 +92,38 @@ systemctl status transmission-tracker-add.service
2692
CGroup: /system.slice/transmission-tracker-add.service
2793
├─19102 /bin/bash /opt/bin/add-trackers-auto.sh
2894
└─31204 sleep 5
29-
95+
3096
```
3197

98+
#### * Simple way (for routers)
99+
100+
Requirements: curl, transmission-remote
101+
102+
Download script and make it executable:
103+
104+
Edit settings for transmission set rpc-enabled, rpc-username, rpc-password and your pt trackers
105+
106+
```
107+
wget --no-check-certificate -O tracker-add-auto-router.sh https://raw.githubusercontent.com/AndrewMarchukov/tracker-add/master/tracker-add-auto-router.sh
108+
chmod +x tracker-add-auto-router.sh
109+
```
110+
Set user and password in tracker-add-auto-router.sh
111+
112+
```
113+
./tracker-add-auto-router.sh &
114+
```
115+
or
116+
```
117+
nohup ./tracker-add-auto-router.sh </dev/null >/var/log/tracker-add-auto.log 2>&1 &
118+
```
119+
or
120+
```
121+
screen -d -m -S tracker-add-auto path/to/tracker-add-auto-router.sh
122+
```
32123

33124

34125

35-
## Extra manual script if you need
126+
### Extra manual script if you need
36127
Set user and password in manual-tracker-add.sh
37128

38129
Run manual script to add some more trackers for active torrents:

manual-tracker-add.sh

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,40 @@
11
#!/bin/bash
2-
# Get transmission credentials
3-
auth=user:password
4-
host=localhost
2+
# Get transmission credentials, if set
3+
if [[ -n "$TRANSMISSION_USER" && -n "$TRANSMISSION_PASS" ]]; then
4+
auth="${TRANSMISSION_USER:-user}:${TRANSMISSION_PASS:-password}"
5+
else
6+
auth=
7+
fi
8+
host=${TRANSMISSION_HOST:-localhost}
9+
list_url=${TRACKER_URL:-https://raw.githubusercontent.com/ngosang/trackerslist/master/trackers_all.txt}
510

611
add_trackers () {
712
torrent_hash=$1
8-
for base_url in https://raw.githubusercontent.com/ngosang/trackerslist/master/trackers_all.txt ; do
13+
for base_url in "${list_url}" ; do
914
echo -e "\e[1m\e[5m"
1015
echo "URL for ${base_url}"
1116
echo -e "Adding trackers for \e[91m$torrent_name..."
1217
echo -en "\e[0m"
1318
echo -e "\e[2m\e[92m"
14-
for tracker in $(curl -# "${base_url}") ; do
19+
for tracker in $(curl --location -# "${base_url}") ; do
1520
echo -en "\e[0m"
1621
echo -ne "\e[93m*\e[0m ${tracker}..."
17-
if transmission-remote "$host" --auth="$auth" --torrent "${torrent_hash}" -td "${tracker}" | grep -q 'success'; then
18-
echo -e '\e[91m failed.'
22+
if transmission-remote "$host" ${auth:+--auth="$auth"} --torrent "${torrent_hash}" -td "${tracker}" | grep -q 'success'; then
23+
echo -e '\e[92m done.'
1924
echo -en "\e[0m"
2025
else
21-
echo -e '\e[92m done.'
26+
echo -e '\e[93m already added.'
2227
echo -en "\e[0m"
2328
fi
2429
done
2530
done
2631
}
2732

2833
# Get list of active torrents
29-
ids="$(transmission-remote "$host" --auth="$auth" --list | grep -vE 'Seeding|Stopped|Finished' | grep '^ ' | awk '{ print $1 }')"
34+
ids=${1:-"$(transmission-remote "$host" ${auth:+--auth="$auth"} --list | grep -vE 'Seeding|Stopped|Finished' | grep '^ ' | awk '{ print $1 }')"}
3035

3136
for id in $ids ; do
32-
hash="$(transmission-remote "$host" --auth="$auth" --torrent "$id" --info | grep '^ Hash: ' | awk '{ print $2 }')"
33-
torrent_name="$(transmission-remote "$host" --auth="$auth" --torrent "$id" --info | grep '^ Name: ' |cut -c 9-)"
37+
hash="$(transmission-remote "$host" ${auth:+--auth="$auth"} --torrent "$id" --info | grep '^ Hash: ' | awk '{ print $2 }')"
38+
torrent_name="$(transmission-remote "$host" ${auth:+--auth="$auth"} --torrent "$id" --info | grep '^ Name: ' |cut -c 9-)"
3439
add_trackers "$hash"
3540
done

tracker-add-auto-router.sh

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

tracker-add-auto.sh

Lines changed: 53 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,59 @@
22
# Get transmission credentials and ip or dns address
33
auth=user:password
44
host=localhost
5+
# set trackers list space separated
6+
trackers=https://raw.githubusercontent.com/ngosang/trackerslist/master/trackers_all.txt
7+
pt_trackers=()
58

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

34-
if [ ! -f /tmp/TTAA.$id.lock ]; then
35-
if [[ ( "$add_date_t" == "$dater" || "$add_date_t" == "$dateo" ) ]]; then
36-
hash="$(transmission-remote "$host" --auth="$auth" --torrent "$id" --info | grep '^ Hash: ' | awk '{ print $2 }')"
37-
torrent_name="$(transmission-remote "$host" --auth="$auth" --torrent "$id" --info | grep '^ Name: ' |cut -c 9-)"
38-
add_trackers "$hash" "$id" &
39-
touch /tmp/TTAA.$id.lock
40-
fi
41-
fi
42-
done
51+
if [ ! -f "/tmp/TTAA.$id.lock" ]; then
52+
if [[ "( "$add_date_t" == "$dater" || "$add_date_t" == "$dateo" )" ]]; then
53+
hash="$(transmission-remote "$host" --auth="$auth" --torrent "$id" --info | grep '^ Hash: ' | awk '{ print $2 }')"
54+
torrent_name="$(transmission-remote "$host" --auth="$auth" --torrent "$id" --info | grep '^ Name: ' | cut -c 9-)"
55+
add_trackers "$hash" "$id" &
56+
touch "/tmp/TTAA.$id.lock"
57+
fi
58+
fi
59+
done
4360
done

transmission-tracker-add.service

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ Description=transmission tracker add
33
Requires=network.target
44

55
[Service]
6+
### use non root user example below:
7+
#User=debian-transmission
68
Type=simple
79
ExecStart=/docker/transmission/tracker-add/tracker-add-auto.sh
810
ExecStop=/bin/kill -s TERM $MAINPID

0 commit comments

Comments
 (0)