Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions add-trackers-auto.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/bin/bash
# Get transmission credentials and ip or dns address
auth=user:password
host=localhost

add_trackers () {
torrent_hash=$1
id=$2
trackerslist=/tmp/trackers.txt
for base_url in https://raw.githubusercontent.com/ngosang/trackerslist/master/trackers_all.txt ; do
if [ ! -f $trackerslist ]; then
curl -o "$trackerslist" "${base_url}"
fi
Local=$(wc -c < $trackerslist)
Remote=$(curl -sI "${base_url}" | awk '/Content-Length/ {sub("\r",""); print $2}')
if [ "$Local" != "$Remote" ]; then
curl -o "$trackerslist" "${base_url}"
fi
echo "URL for ${base_url}"
echo "Adding trackers for $torrent_name..."
for tracker in $(cat $trackerslist) ; do
echo -n "${tracker}..."
if transmission-remote "$host" --auth="$auth" --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
sleep 10m
# Get list of active torrents
ids="$(transmission-remote "$host" --auth="$auth" --list | grep -E 'Idle|Downloading' | grep '^ ' | awk '{ print $1 }')"
for id in $ids ; do
add_date="$(transmission-remote "$host" --auth="$auth" --torrent "$id" --info| grep '^ Date added: ' |cut -c 21-)"
add_date_t="$(date -d "$add_date" "+%Y-%m-%d %H:%M")"
dater="$(date "+%Y-%m-%d %H:%M")"
dateo="$(date -d "1 minutes ago" "+%Y-%m-%d %H:%M")"

if [ ! -f "/tmp/TTAA.$id.lock" ]; then
if [[ "( "$add_date_t" == "$dater" || "$add_date_t" == "$dateo" )" ]]; then
trackers="$(transmission-remote "$host" --auth="$auth" --torrent "$id" -it | wc -l)"
if [[ $trackers -lt 10 ]]; then
hash="$(transmission-remote "$host" --auth="$auth" --torrent "$id" --info | grep '^ Hash: ' | awk '{ print $2 }')"
torrent_name="$(transmission-remote "$host" --auth="$auth" --torrent "$id" --info | grep '^ Name: ' |cut -c 9-)"
touch "/tmp/TTAA.$id.lock"
add_trackers "$hash" "$id" &
fi
fi
fi
done
done