59 lines
1.7 KiB
Bash
59 lines
1.7 KiB
Bash
#!/bin/bash
|
|
|
|
add_trackers() {
|
|
torrent_hash=$1
|
|
torrent_name=$2
|
|
id=$3
|
|
for base_url in "$TORRENTLIST"; do
|
|
if [ ! -f /tmp/trackers.txt ]; then
|
|
curl -o "/tmp/trackers.txt" "${base_url}"
|
|
|
|
if [ -f /opt/trackers.txt ]; then
|
|
cat /opt/trackers.txt >>/tmp/trackers.txt
|
|
fi
|
|
fi
|
|
|
|
local=$(wc -c </tmp/trackers.txt)
|
|
remote=$(curl -sI "${base_url}" | awk '/Content-Length/ {sub("\r",""); print $2}')
|
|
|
|
if [ "$local" != "$remote" ]; then
|
|
curl -o "/tmp/trackers.txt" "${base_url}"
|
|
|
|
if [ -f /opt/trackers.txt ]; then
|
|
cat /opt/trackers.txt >>/tmp/trackers.txt
|
|
fi
|
|
fi
|
|
|
|
echo "URL for ${base_url}"
|
|
echo "Adding trackers for $torrent_name ($torrent_hash)"
|
|
|
|
for tracker in $(cat /tmp/trackers.txt); do
|
|
echo -n "${tracker}..."
|
|
if transmission-remote "$HOSTPORT" --authenv --torrent "${torrent_hash}" -td "${tracker}" | grep -q 'success'; then
|
|
echo ' failed.'
|
|
else
|
|
echo ' done.'
|
|
fi
|
|
done
|
|
done
|
|
|
|
sleep 3m
|
|
rm -f /tmp/TTAA.$id.lock
|
|
}
|
|
|
|
while true; do
|
|
# Get list of active torrents
|
|
ids="$(transmission-remote "$HOSTPORT" --authenv --list | grep -vE 'Seeding|Stopped|Finished|[[:space:]]100%[[:space:]]' | grep '^ ' | awk '{ print $1 }')"
|
|
for id in $ids; do
|
|
echo Processing $id
|
|
|
|
if [ ! -f /tmp/TTAA.$id.lock ]; then
|
|
hash="$(transmission-remote "$HOSTPORT" --authenv --torrent "$id" --info | grep '^ Hash: ' | awk '{ print $2 }')"
|
|
torrent_name="$(transmission-remote "$HOSTPORT" --authenv --torrent "$id" --info | grep '^ Name: ' | cut -c 9-)"
|
|
add_trackers "$hash" "$torrent_name" "$id" &
|
|
touch /tmp/TTAA.$id.lock
|
|
fi
|
|
done
|
|
|
|
sleep ${INTERVAL:-25}
|
|
done
|