PT 账号被封,重新注册后,新用户的 KEY 与老用户的 KEY 不一致,一个一个手动更新替换很麻烦,于是写了一个简单的脚本来批量更新 qBittorrent 中老种子的 KEY,通过一个简单 NodeJS 脚本实现对 qBittorrent 中正在做种的种子,修改 Tracker 中的用户识别 KEY
保存为任意单文件如:1.js
import fetch from "node-fetch"
// 新老 KEY 填写
const oldKey = "b1111111111111111111111111111115"
const newKey = "b2222222222222222222222222222225"
/ qBittorrent 服务器地址
const apiURL = "http://192.168.1.220:8080"
const commonHeaders = {
// 修改为你的 COOKIE
Cookie:""
}
async function editTracker(hash){
const response1 = await fetch(`${apiURL}/api/v2/torrents/trackers?hash=${hash}`,{headers:commonHeaders})
const trackerList = await response1.json()
for(let key in trackerList){
const trackerItem = trackerList[key]
if(trackerItem.url.indexOf(oldKey) > -1){
const newUrl = trackerItem.url.replace(oldKey,newKey)
const formData = new URLSearchParams();
formData.append('hash', hash);
formData.append('origUrl', trackerItem.url);
formData.append('newUrl', newUrl);
const response = await fetch(`${apiURL}/api/v2/torrents/editTracker`,{
method:"POST",
headers:commonHeaders,
body:formData
})
// console.log(`edit Tracker: ${hash}, response.status = ${response.status}`)
return response.status
}
}
return -1
}
async function replaceList()
{
const response = await fetch(`${apiURL}/api/v2/sync/maindata?rid=0`,{
headers:commonHeaders
})
// console.log(await response.text())
const result = await response.json()
// console.log(' result.torrents = ', result.torrents.length)
for(let i in result.torrents){
const value = result.torrents[i]
const code = await editTracker(value.infohash_v1)
if (code>-1){
console.log(`edit Tracker: ${value.infohash_v1}, response.status = ${code}, name = ${value.name}`)
}
}
}
replaceList()
修改完主要的参数后,在文件所在目录执行安装 NPM 依赖
npm i
然后执行脚本开始修改
node 1.js
如果最终输出类似的日志,就没问题了
edit Tracker: 003209e93aad776d3d39ef19bc11a536bbce82fe, response.status = 200
edit Tracker: 0099ee3c7757a1a50dbeb744d025bcda6cb12d7f, response.status = 200
edit Tracker: 02dbf8ef70fa6b3a1c3e93ef7928d6e003769262, response.status = 200
edit Tracker: 035c3d30668ec8670eff3076a146f457e044d652, response.status = 200
Comments