|
| 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 |
0 commit comments