gpt写的,使用了发现没什么问题,用shell脚本主打的就是一个轻量化,什么环境都不需要,目前只支持单tracker修改,旧tracker url只写域名的话不会删除老tracker,如果填写完整tracker则会删除旧的保留新的。
记得修改qbit的地址,用户名,密码,旧tracker和新tracker的变量
#!/bin/bash
# qBittorrent credentials and host
QB_HOST="http://localhost:8080"
QB_USER="user"
QB_PASS="password"
# Old and new tracker URLs
OLD_TRACKER_URL="https://old.domain.name/announce.php"
NEW_TRACKER_URL="https://new.domain.name/announce.php?passkey=123"
# Login to qBittorrent Web UI
SID=$(curl -s -X POST --data "username=${QB_USER}&password=${QB_PASS}" "${QB_HOST}/api/v2/auth/login" -c - | grep SID | cut -f7)
# Check if login is successful
if [ -z "$SID" ]; then
echo "Login failed"
exit 1
fi
# Get list of hashes of all torrents
TORRENTS_JSON=$(curl -s -X GET "${QB_HOST}/api/v2/torrents/info" -b "SID=$SID")
# Iterate over each torrent
echo "$TORRENTS_JSON" | jq -c '.[]' | while read -r TORRENT; do
HASH=$(echo "$TORRENT" | jq -r '.hash')
TRACKERS=$(curl -s -X GET "${QB_HOST}/api/v2/torrents/trackers?hash=${HASH}" -b "SID=$SID" | jq -r '.[].url')
# Check if the old tracker is in the torrent's tracker list
if [[ $TRACKERS == *"$OLD_TRACKER_URL"* ]]; then
# Replace old tracker with new tracker
# First, remove the old tracker
curl -s -X POST "${QB_HOST}/api/v2/torrents/removeTrackers" \
-b "SID=$SID" \
--data "hash=${HASH}" \
--data "urls=${OLD_TRACKER_URL}"
# Then, add the new tracker
curl -s -X POST "${QB_HOST}/api/v2/torrents/addTrackers" \
-b "SID=$SID" \
--data "hash=${HASH}" \
--data "urls=${NEW_TRACKER_URL}"
echo "Replaced tracker for torrent: $HASH"
else
echo "tracker not matched"
fi
done
echo "Tracker replacement process completed."
if(window.hljsLoader && !document.currentScr(๐•ᴗ•๐).parentNode.hasAttribute('data-s9e-livepreview-onupdate')) {
window.hljsLoader.highlightBlocks(document.currentScr(๐•ᴗ•๐).parentNode);
}