Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only download list once per run #19

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
42 changes: 28 additions & 14 deletions manual-tracker-add.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,40 @@ fi
host=${TRANSMISSION_HOST:-localhost}
list_url=${TRACKER_URL:-https://raw.githubusercontent.com/ngosang/trackerslist/master/trackers_all.txt}

# Download list(s) of trackers to temporary file
list_file=$(mktemp --tmpdir trackers.XXXXX.txt)
echo -e "\e[1m\e[5m"
echo "Downloading trackers into ${list_file}"
for base_url in ${list_url}; do
echo -e "\e[1m\e[5m"
echo "URL for ${base_url}"
echo -en "\e[0m"
if curl --location -# "${base_url}" >> "${list_file}"; then
echo -e '\e[92m done.'
echo -en "\e[0m"
else
echo -e '\e[91m failed.'
echo -en "\e[0m"
fi
done

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"
for tracker in $(curl --location -# "${base_url}") ; 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
for tracker in $(cat "${list_file}"); 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[91m failed.'
echo -en "\e[0m"
else
echo -e '\e[92m done.'
echo -en "\e[0m"
fi
done
}

# Get list of active torrents
Expand Down
77 changes: 40 additions & 37 deletions tracker-add-auto-router.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,50 +3,53 @@
auth=user:password
host=localhost

while true ; do
sleep 25
list_url="https://raw.githubusercontent.com/ngosang/trackerslist/master/trackers_all.txt"

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
for base_url in ${list_url} ; 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"
}
# Get list of active torrents

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 '{ 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")"
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
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
done
78 changes: 41 additions & 37 deletions tracker-add-auto.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,50 +3,54 @@
auth=user:password
host=localhost

while true ; do
sleep 25
list_url="https://raw.githubusercontent.com/ngosang/trackerslist/master/trackers_all.txt"

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 ' done.'
else
echo ' already added.'
fi
done
done
for base_url in ${list_url} ; 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 ' done.'
else
echo ' already added.'
fi
done
done
sleep 3m
rm -f "/tmp/TTAA.$id.lock"
}
# Get list of active torrents

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 '{ 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")"
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
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
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
done