forked from ryzhovau/tracker-add
-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathmanual-tracker-add.sh
More file actions
executable file
·45 lines (41 loc) · 1.62 KB
/
Copy pathmanual-tracker-add.sh
File metadata and controls
executable file
·45 lines (41 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/bash
# Get transmission credentials, if set
if [[ -n "$TRANSMISSION_USER" && -n "$TRANSMISSION_PASS" ]]; then
auth="${TRANSMISSION_USER:-user}:${TRANSMISSION_PASS:-password}"
else
auth=
fi
host=${TRANSMISSION_HOST:-localhost}
list_url=${TRACKER_URL:-https://raw.githubusercontent.com/ngosang/trackerslist/master/trackers_all.txt}
add_trackers () {
torrent_hash=$1
for base_url in "${list_url}" ; do
echo -e "\e[1m\e[5m"
echo "URL for ${base_url}"
echo -e "Adding trackers for \e[91m$torrent_name..."
echo -en "\e[0m"
echo -e "\e[2m\e[92m"
trackerslist=${TMPDIR:-/tmp}/trackers.$(echo "$base_url" | cksum | cut -d' ' -f1).txt
curl -fsSL -o "$trackerslist" -z "$trackerslist" "${base_url}"
for tracker in $(cat "$trackerslist") ; do
echo -en "\e[0m"
echo -ne "\e[93m*\e[0m ${tracker}..."
if transmission-remote "$host" ${auth:+--auth="$auth"} --torrent "${torrent_hash}" -td "${tracker}" | grep -q 'success'; then
echo -e '\e[92m done.'
echo -en "\e[0m"
else
echo -e '\e[93m already added.'
echo -en "\e[0m"
fi
done
done
}
# Get list of active torrents
ids=${1:-"$(transmission-remote "$host" ${auth:+--auth="$auth"} --list | grep -vE '^[[:space:]]+ID[[:space:]]|Seeding|Stopped|Finished' | grep '^ ' | awk '{ gsub(/[^0-9]/,"",$1); print $1 }')"}
for id in $ids ; do
info="$(transmission-remote "$host" ${auth:+--auth="$auth"} --torrent "$id" --info)"
case "$info" in *"Public torrent: No"*) continue;; esac
hash="$(echo "$info" | grep '^ Hash: ' | awk '{ print $2 }')"
torrent_name="$(echo "$info" | grep '^ Name: ' | cut -c 9-)"
add_trackers "$hash"
done