Skip to content

Commit 16b326f

Browse files
committed
Only fetch each tracker list URL once; Fix 'ID' treated as torrent id
1 parent a764d6e commit 16b326f

File tree

1 file changed

+24
-21
lines changed

1 file changed

+24
-21
lines changed

manual-tracker-add.sh

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,39 @@ if [[ -n "$TRANSMISSION_USER" && -n "$TRANSMISSION_PASS" ]]; then
55
else
66
auth=
77
fi
8-
host=${TRANSMISSION_HOST:-localhost}
9-
list_url=${TRACKER_URL:-https://raw.githubusercontent.com/ngosang/trackerslist/master/trackers_all.txt}
8+
host=${TRANSMISSION_HOST:-192.168.1.168}
9+
list_url=${TRACKER_URL:-https://gitee.com/harvey520/www.yaozuopan.top/raw/master/blacklist.txt}
1010

1111
add_trackers () {
1212
torrent_hash=$1
13-
for base_url in "${list_url}" ; do
14-
echo -e "\e[1m\e[5m"
15-
echo "URL for ${base_url}"
13+
tracker_list=$2
1614
echo -e "Adding trackers for \e[91m$torrent_name..."
17-
echo -en "\e[0m"
18-
echo -e "\e[2m\e[92m"
19-
for tracker in $(curl --location -# "${base_url}") ; do
20-
echo -en "\e[0m"
21-
echo -ne "\e[93m*\e[0m ${tracker}..."
22-
if transmission-remote "$host" ${auth:+--auth="$auth"} --torrent "${torrent_hash}" -td "${tracker}" | grep -q 'success'; then
23-
echo -e '\e[92m done.'
24-
echo -en "\e[0m"
25-
else
26-
echo -e '\e[93m already added.'
27-
echo -en "\e[0m"
28-
fi
29-
done
30-
done
15+
for tracker in $tracker_list ; do
16+
echo -ne "\e[93m*\e[0m ${tracker}..."
17+
if transmission-remote "$host" ${auth:+--auth="$auth"} --torrent "${torrent_hash}" -td "${tracker}" | grep -q 'success'; then
18+
echo -e '\e[92m done.'
19+
echo -en "\e[0m"
20+
else
21+
echo -e '\e[93m already added.'
22+
echo -en "\e[0m"
23+
fi
24+
done
3125
}
3226

3327
# Get list of active torrents
34-
ids=${1:-"$(transmission-remote "$host" ${auth:+--auth="$auth"} --list | grep -vE 'Seeding|Stopped|Finished' | grep '^ ' | awk '{ print $1 }')"}
28+
ids=${1:-"$(transmission-remote "$host" ${auth:+--auth="$auth"} --list | tail -n +2 | grep -vE 'Seeding|Stopped|Finished' | grep '^ ' | awk '{ print $1 }')"}
29+
# Get list of trackers
30+
trackers=""
31+
newline=$'\n'
32+
for base_url in "${list_url}" ; do
33+
trackers="$trackers$newline$(curl -sL "${base_url}")"
34+
done
35+
36+
# Remove empty lines
37+
trackers=$(echo "$trackers" | grep -vE '^$')
3538

3639
for id in $ids ; do
3740
hash="$(transmission-remote "$host" ${auth:+--auth="$auth"} --torrent "$id" --info | grep '^ Hash: ' | awk '{ print $2 }')"
3841
torrent_name="$(transmission-remote "$host" ${auth:+--auth="$auth"} --torrent "$id" --info | grep '^ Name: ' |cut -c 9-)"
39-
add_trackers "$hash"
42+
add_trackers "$hash" "$trackers"
4043
done

0 commit comments

Comments
 (0)