Skip to content

Instantly share code, notes, and snippets.

@EtienneM
Forked from Adadov/tracker-replace.sh
Last active March 7, 2021 18:05
Show Gist options
  • Save EtienneM/1bf4088934d65a27426fd61f84b70b0a to your computer and use it in GitHub Desktop.
Save EtienneM/1bf4088934d65a27426fd61f84b70b0a to your computer and use it in GitHub Desktop.
t411 mass replace tracker
#!/usr/bin/env bash
set -e
# set -x
# t411 key
t411_key="******"
transmission_host="localhost:9091" # Transmission daemon host
transmission_username=""
transmission_password=""
if [[ -n "${transmission_username}" ]]; then
transmission_opts="${transmission_host} --auth ${transmission_username}:${transmission_password}"
else
transmission_opts="${transmission_host}"
fi
# Tracker to replace
old_tracker="t411.download"
# New tracker URL
new_tracker="http://hostname:port"
# Get all torrent IDs
torrent_ids=$(transmission-remote ${transmission_opts} --list | awk '{print $1}' | grep -E '^[0-9]+' | sed -r -e 's/^([0-9]*).*$/\1/')
max_torrent_id=$(echo "$torrent_ids" | tail -n1)
for id in ${torrent_ids}; do
echo "Torrent $id / $max_torrent_id"
# Get all trackers of the current torrent
trackers=$(transmission-remote ${transmission_opts} --torrent ${id} --info-trackers | grep -E 'Tracker [0-9]+')
# Is there the tracker to replace?
echo "${trackers}" | grep ${old_tracker} > /dev/null && rc=$? || rc=$?
if [[ $rc -ne 0 ]]; then
echo "No old tracker \"$old_tracker\" on torrent $id" >&2
continue
fi
tracker_id=$(echo "${trackers}" | grep ${old_tracker} | sed -r -e 's/Tracker ([0-9]+).*/\1/')
transmission-remote ${transmission_opts} --torrent ${id} --tracker-remove ${tracker_id} > /dev/null
transmission-remote ${transmission_opts} --torrent ${id} --tracker-add "${new_tracker}/${t411_key}/announce" > /dev/null
echo "Replaced tracker \"$old_tracker\" with \"$new_tracker\""
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment