qBittorrent
                                
                                 qBittorrent copied to clipboard
                                
                                    qBittorrent copied to clipboard
                            
                            
                            
                        WebUI: Add way to mass update announce url
Has been implemented in Application but not WebUi. Can that please be updated?
https://github.com/qbittorrent/qBittorrent/blob/master/Changelog
Tue Dec 03 2019 - sledgehammer999 <[email protected]> - v4.2.0 - FEATURE: Add "Tracker entries" dialog (Chocobo1)Commit : 9e7f505
https://github.com/qbittorrent/qBittorrent/issues/2428#issuecomment-573396594
I believe this is available in the web API. I was able to do this via a python script when I had to change my token on a tracker.
As a workaround, I wrote this Fish shell snippet to update all torrents with an up-to-date tracker list:
set trackers (curl --silent --stderr -- "https://newtrackon.com/api/stable")
for hash in (qbt torrent list --url "$url" --username "$username" --password "$password" -F json | jq ".[].hash" -r)
    echo "Processing $hash"
    qbt torrent tracker add --url "$url" --username "$username"--password "$password" "$hash" "$trackers"
end
It requires qbittorrent-cli and jq.
As a workaround, I wrote this Fish shell snippet to update all torrents with an up-to-date tracker list:
set trackers (curl --silent --stderr -- "https://newtrackon.com/api/stable") for hash in (qbt torrent list --url "$url" --username "$username" --password "$password" -F json | jq ".[].hash" -r) echo "Processing $hash" qbt torrent tracker add --url "$url" --username "$username"--password "$password" "$hash" "$trackers" endIt requires qbittorrent-cli and jq.
I also basically did the same thing on 1000 mixed torrents to update just some trackers from http to https.
- Got a list of the hashes with qbt torrent list -F json | jq ".[].hash" -r >> hash_list
- Iterated through all the hashes with a shell script
#! /bin/bash
for x in $(cat hash_list); do
 trackerurl=$(qbt torrent tracker list $x -F json | jq '.[]."Url"')
 if [[ $trackerurl == *http://oldtracker.com* ]]; then
  echo "Updating $x for https"
  qbt torrent tracker add $x "https://newtracker.com/announce"
  qbt torrent tracker delete $x "http://oldtracker.com/announce"
 else
  echo "$x has tracker $trackerurl"
 fi;
done;
Would still love to see this functionality in the WebUI. Although the time it took to loop through and change all of these via API might not work well in the WebUI.
As a workaround, I wrote this Fish shell snippet to update all torrents with an up-to-date tracker list:
set trackers (curl --silent --stderr -- "https://newtrackon.com/api/stable") for hash in (qbt torrent list --url "$url" --username "$username" --password "$password" -F json | jq ".[].hash" -r) echo "Processing $hash" qbt torrent tracker add --url "$url" --username "$username"--password "$password" "$hash" "$trackers" endIt requires qbittorrent-cli and jq.
I also basically did the same thing on 1000 mixed torrents to update just some trackers from http to https.
- Got a list of the hashes with
qbt torrent list -F json | jq ".[].hash" -r >> hash_list- Iterated through all the hashes with a shell script
#! /bin/bash for x in $(cat hash_list); do trackerurl=$(qbt torrent tracker list $x -F json | jq '.[]."Url"') if [[ $trackerurl == *http://oldtracker.com* ]]; then echo "Updating $x for https" qbt torrent tracker add $x "https://newtracker.com/announce" qbt torrent tracker delete $x "http://oldtracker.com/announce" else echo "$x has tracker $trackerurl" fi; done;Would still love to see this functionality in the WebUI. Although the time it took to loop through and change all of these via API might not work well in the WebUI.
Need a JavaScript version to run on the browser console:

I did use the following code from the browser console.
let qbit_url=window.location.href
let old_url='https://oldurl.com'
let new_url='https://newurl.xyz'
// Calls https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#edit-trackers
var change_url = (torrent) => fetch(qbit_url + 'api/v2/torrents/editTracker?' + new URLSearchParams({
   hash: torrent.hash,
   origUrl: torrent.tracker,
   newUrl: torrent.tracker.replace(old_url, new_url)
}))
// Calls https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#get-torrent-list
fetch(qbit_url + 'api/v2/torrents/info')
   .then(response => response.json())
   // Filter torrents with your url
   .then(torrents => torrents.filter(({tracker}) => tracker.startsWith(old_url)))
   // request change for each torrent
   .then(torrents => torrents.map(change_url))
In case the tracker url no longer works (tracker status 'Not Working') by qBittorrent: This version is probably slower, but I added some feddback to the console.
⚠️ The API torrent/removeTrackers doesn't work properly on 4.5 and will return ok (200) even when it didn't removed a tracker. This script is not safe if you have trackers from a different domain on qB 4.5
var PID = 'myPID'
var old_url = 'https://olddomain/announce/' + PID
var new_url = 'https://newdomain/announce/' + PID
var qbit_url = window.location.href
var recreate_tracker = (torrent) => fetch(qbit_url + 'api/v2/torrents/removeTrackers?' + new URLSearchParams({
    hash: torrent.hash,
    urls: old_url,
})).then((response) => response.status == 200 ? fetch(qbit_url + 'api/v2/torrents/addTrackers?', {
    "body": new URLSearchParams({
        hash: torrent.hash,
        urls: new_url,
    }),
    "method": "POST"
}).then(response.status == 200 ? console.log(`✔️ ${torrent.name}`) : console.log(`❌ ERROR: ${torrent.name}`)
) : console.log(`❗️ NOT MODIFIED: ${torrent.name}`))
// optionally, use tags to filter
// var tag = 'script'
// fetch(qbit_url + 'api/v2/torrents/info?tag=' + tag)
fetch(qbit_url + 'api/v2/torrents/info')
    .then(response => response.json())
    .then(torrents => torrents.map(recreate_tracker))
I did use the following code from the browser console.
let qbit_url=window.location.href let old_url='https://oldurl.com' let new_url='https://newurl.xyz' // Calls https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#edit-trackers var change_url = (torrent) => fetch(qbit_url + 'api/v2/torrents/editTracker?' + new URLSearchParams({ hash: torrent.hash, origUrl: torrent.tracker, newUrl: torrent.tracker.replace(old_url, new_url) })) // Calls https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#get-torrent-list fetch(qbit_url + 'api/v2/torrents/info') .then(response => response.json()) // Filter torrents with your url .then(torrents => torrents.filter(({tracker}) => tracker.startsWith(old_url))) // request change for each torrent .then(torrents => torrents.map(change_url))
I see that you are a victim of Redbits domain change. Working perfectly. Thank you so much @Ameb .
If the tracker url no longer works, qbittorrent doesn't return it on the torrents/info endpoint so i had to made a different script. Edited my previous message
The simple way
var editTracker = (torrent) => fetch(
	'http://qbittorrent.example:8080/api/v2/torrents/editTracker',
	{
		body: new URLSearchParams({
			hash: torrent.hash,
			origUrl: 'http://old.tracker.example/xxxxx/announce',
			newUrl: 'http://new.tracker.example/xxxxx/announce'
		}),
		method: 'POST'
	}
)
fetch('http://qbittorrent.example:8080/api/v2/torrents/info')
	.then(response => response.json())
	.then(torrents => torrents.map(editTracker))
On v4.5.0, it works when the old tracker is offline, and it does not change other trackers
works well ! thank you both @jcassette and @Ameb.
We really need a WebUI implementation. Hopeful that someone build that feature one day
+1
I did use the following code from the browser console.
let qbit_url=window.location.href let old_url='https://oldurl.com' let new_url='https://newurl.xyz' // Calls https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#edit-trackers var change_url = (torrent) => fetch(qbit_url + 'api/v2/torrents/editTracker?' + new URLSearchParams({ hash: torrent.hash, origUrl: torrent.tracker, newUrl: torrent.tracker.replace(old_url, new_url) })) // Calls https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#get-torrent-list fetch(qbit_url + 'api/v2/torrents/info') .then(response => response.json()) // Filter torrents with your url .then(torrents => torrents.filter(({tracker}) => tracker.startsWith(old_url))) // request change for each torrent .then(torrents => torrents.map(change_url))
If your qb version ≥ 4.4.4,POST method should be used.
let url_qbit = location.protocol + '//' + location.host;
let url_base = 'https://basedomain.com';
let str_old = 'wwww';
let str_new = 'mmmm';
// Calls https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#edit-trackers
var change_url = (torrent) => fetch(url_qbit + '/api/v2/torrents/editTracker', {
  // POST must be used in ≥ v4.4.4 https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#general-information
  method: "POST",
  headers: {
    "Content-Type": "application/x-www-form-urlencoded;charset=utf-8;"
  },
  body: new URLSearchParams({
    hash: torrent.hash,
    origUrl: torrent.tracker,
    newUrl: torrent.tracker.replace(str_old, str_new)
  })
}).then(function(r) {
  console.log(torrent.hash + ': ' + r.status)
});
// Calls https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#get-torrent-list
fetch(url_qbit + '/api/v2/torrents/info')
  .then(response => response.json())
  // Filter torrents with your url
  .then(torrents => torrents.filter(({tracker}) => tracker.startsWith(url_base)))
  // request change for each torrent
  .then(torrents => torrents.map(change_url))