Page 1 of 1

Can I make qbittorrent auto start after error ?

Posted: Sat Jan 22, 2022 11:51 pm
by picklerick
Hi, I am experiencing an issue due to unstable connection to my hard drive which is a network drive, that qbittorrent will error out when it loses connection to the network drive where it is trying to store the files being downloaded. But it does not automatically resume when the drive is back online.

It's really annoying, because I can manually just click the play button and then its starts downloading, 5 minutes later it stops, and if I don't sit and monitor it all the time to constantly click play, it will take hours to download.

Would it be possible to auto resume, I would really appreciate this.

Re: Can I make qbittorrent auto start after error ?

Posted: Thu May 02, 2024 5:23 pm
by Gl1tch
Hello, fellow pragmatic solution enjoyer.

IDK if you are still looking for the solution to this, but I figured since I spent so much time to come up with one for myself after not finding one online either, I might as well share it.

There is no way to do this using ONLY qBittorrent, however, there is a way of doing it using https://github.com/fedarovich/qbittorrent-cli, which is an awesome little program that hooks into qBittorrent's web interface to enable you to control it via CMD. You'll also need a few lines of code in some scripting language. In my case (Windows) I did it in PowerShell (mainly to teach myself a little bit about PowerShell).

I have set the --username, --password and --url parameters to the default settings for qBittorrent's web interface, you should either change them according to your configuration, or use qBittorrent CLIs built-in login caching functionality.

Code: Select all

# Get filtered list of downloads
$list_raw = qbt torrent list --username admin --password adminadmin --url http://localhost:8080 --format json --filter errored

# Format as a single string (possibly an external error)
foreach($download_raw in $list_raw){
    $list_string = $list_string + $download_raw
}

# Convert JSON string to PS object
$list_object = ConvertFrom-Json $list_string

# Resume downloads
foreach($download_object in $list_object){
    qbt torrent resume --username admin --password adminadmin --url http://localhost:8080 $download_object.hash
}
The first part is a bit hacky and harder to explain, it basically reformats the response given by qBittorrent CLI into a single String, instead of an array of strings (one for each errored torrent in the result list). This is some PowerShell specific oddity, when running the command using subprocess in Python, the result is already a single String. The string is in JSON format, as specified by the --format parameter.

From there it is very simple, the JSON-String is parsed into an array, which is then iterated over. For each iteration, it gets the hash of the torrent, which is then used to call a resume-command on that torrent. And voila, it should be out of the errored state.

Now you have many options of running the script automatically, I just added it as a Scheduled Task in Windows Task Scheduler to run every 30min indefinitely.

I hope this helps others to also spend less time checking if their clients have accumulated a bunch of errors, just to klick resume on them.