Skip to content
Closed
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
84 changes: 39 additions & 45 deletions tracker-add-auto-router.sh
Original file line number Diff line number Diff line change
@@ -1,52 +1,46 @@
#!/bin/sh
# Get transmission credentials and ip or dns address
auth=user:password
auth=
host=localhost

while true ; do
sleep 25
record_file="/tmp/tracker_add.rec"
temp_file="/tmp/tracker_add_id.info"
[[ -f $record_file ]] || touch $record_file
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 "${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"
torrent_hash=$1
id=$2
trackerslist=/tmp/trackers.txt
for base_url in https://raw.githubusercontent.com/ngosang/trackerslist/master/trackers_all.txt ; do
curl -o "$trackerslist" "${base_url}"
echo "URL for ${base_url}"
echo "Adding trackers for $torrent_name..."
for tracker in $(cat $trackerslist) ; do
echo "${tracker}..."
if [ $(transmission-remote "$host" --auth="$auth" --torrent "${torrent_hash}" -td "${tracker}" | grep -c 'success') -eq 0 ]; then
echo ' already added.'
else
echo ' done.'
fi
done
done
}
# Get list of active torrents
ids="$(transmission-remote "$host" --auth="$auth" --list | grep -vE 'Seeding|Stopped|Finished|[[:space:]]100%[[:space:]]' | 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 '%s' -d "$(( `date +%s`+1*60 ))" "+%Y-%m-%d %H:%M")"

if [ ! -f "/tmp/TTAA.$id.lock" ]; then
if [[ "( "$(add_date_t)" == "$(dater)" || "$(add_date_t)" == "$(dateo)" )" ]]; 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-)"
add_trackers "$hash" "$id" &
touch "/tmp/TTAA.$id.lock"
fi
fi
done
while true ; do
sleep 25
# Get list of active torrents
ids="$(transmission-remote "$host" --auth="$auth" --list | grep -vE 'Seeding|Stopped|Finished|[[:space:]]100%[[:space:]]' | grep '^ ' | awk 'BEGIN{IGNORECASE=1} $1 !~ /^id$/ { print $1 }')"
for id in $ids ; do
transmission-remote "$host" --auth="$auth" --torrent "$id" --info > $temp_file
add_date="$(grep '^ Date added: ' $temp_file |cut -c 21-)"
hash="$(grep '^ Hash: ' $temp_file | awk '{ print $2 }')"
torrent_name="$( grep '^ Name: ' $temp_file |cut -c 9-)"

if [ "$(grep -c "$hash $add_date" $record_file)" -eq "0" ]; then
add_trackers "$hash" "$id"
echo "$hash $add_date" >> $record_file
fi
done
# delete removed torrents record from record file
for hash in $(awk '{print $1}' $record_file); do
[[ $(transmission-remote "$host" --auth="$auth" --torrent "${torrent_hash}" --info | wc -l) -eq 0 ]] && sed -in $(grep -n $hash $record_file | head -n 1 | awk -F ':' '{print $1}')'d' $record_file
done
done