qBittorrent script that removes torrent+data based on ratio and elapsed completed time
4.8K
This is a python script that deletes the torrent file and data based on ratio and how long the torrent has been completed for. Note: For this script to work you need to enable the Web User Interface (remote control) checkbox, found in the tools > options > WEB UI of the qBittorrent
This script was made to automate the freeing of storage space for all finished (not needed torrents). The script is intended for all users of sonarr/radarr, since they cannot use the settings QbitTorrent > Seeding limits. For all the rest use the built-in settings that qBittorrent offers.
The script will run in predefined time intervals (for example every 5 min) and will check all the COMPLETED torrents for the conditions described below. There are two major conditions to be met in order to delete a torrent+data:
If either of these two conditions get met for any completed torrent, then the torrent+data (meaning the torrent in qBittorrent and the files on the user's disk) will be removed.
The tag latest is multi-arch, so you can use it for any architecture. Use the develop tag to use the unstable version.
docker create \
--name=qbittorrentremover \
-d \
-e QBIT_LOGIN_USER=admin \
-e QBIT_LOGIN_PASS=adminadmin \
-e QBIT_PORT=8080 \
-e QBIT_IP=192.168.1.5 \
-e QBIT_RATIO_TRESHOLD=1.0 #Optional \
-e QBIT_TIME_DELAY=3600 #Optional \
-e QBIT_ABSOLUTE_TIME_DELAY=7200 #Optional \
-e QBIT_TAGS=tag1,tag2 #Optional \
-e QBIT_TRACKERS_WITH_RATIO_TRESHOLD="tracker1#alias1@ratio1;tracker2#alias2@ratio2" #Optional \
-e QBIT_ADD_TRACKERS_IN_TAGS=False #Optional \
-e QBIT_SET_DEFAULT_QBIT_RATIO=True #Optional \
-e DISCORD_WEBHOOK=discordWebhook #Optional \
-e CHECK_INTERVAL=300 #Optional \
--restart unless-stopped \
dokeraj/qbittorrent-remover:latest
| Environment variable | Function |
|---|---|
QBIT_LOGIN_USER | Mandatory. This is your login username - It can be found in the qBittorrent options on the following path: WEB UI > Authentication > Username |
QBIT_LOGIN_PASS | Mandatory. This is your login password - It can be found in the qBittorrent options on the following path: WEB UI > Authentication > Password |
QBIT_PORT | Mandatory. This is the port that the WEB UI is listening on - It can be found in the qBitttorent options on the following path: WEB UI > Port |
QBIT_IP | Mandatory. This is the IP address that the WEB UI is listening on - It can be found in the qBitttorent options on the following path: WEB UI > IP Address. Note: if the qBittorrent is running in another docker, then make sure you create a custom docker network and connect this docker container (qbittorrent-remover) and the qbittorrent container on the same custom network. In this case you will need to specify the name of the qbittorrent container here in this env var |
QBIT_RATIO_TRESHOLD | Optional, but recommended to be explicitly set. This is the ratio (decimal number) that needs to be reached for the COMPLETED torrent to be considered for deletion. This env var if not specified will default to 1.0. Note: this field works in conjunction with the QBIT_TIME_DELAY env var. So these two settings need to be met for the torrent+data to be removed. |
QBIT_TIME_DELAY | Optional, but recommended to be explicitly set. This is the time (in seconds) that must pass after the torrent has COMPLETED to be considered for deletion. This env var if not specified will default to 3600. Note: this field works in conjunction with the QBIT_RATIO_TRESHOLD env var. So these two settings need to be met for the torrent+data to be removed. |
QBIT_ABSOLUTE_TIME_DELAY | Optional, but recommended to be explicitly set. This is the time (in seconds) that must pass after the torrent has been COMPLETED to be removed! This env var if not specified will default to 1209600, which equates to 2 weeks. Note: This env var is not dependent on any other condition. It is used as a failsafe, like the maximum amount of time a torrent is allowed to be alive |
QBIT_TAGS | Optional. You can specify torrent tags which you'd like this script be looking for when considering which torrents to remove. Note: only the torrents with the specified tags will be deleted. If you want all of the torrents to be considered for deletion, then don't specify this env var. |
QBIT_TRACKERS_WITH_RATIO_TRESHOLD | Optional. Apply different MAX share ratios for different trackers, by adding the tracker domain followed by @ sign and adding the ratio you want to be achieved - This will override the QBIT_RATIO_TRESHOLD. To add multiple trackers with their ratio use the ; symbol to separate between each tracker/share ratio. Note: You can also add tracker alias that will be added in the tags, instead of the tracker's domain - for better visibility. To do this just add the symbol # with the alias name for that torrent - in between the tracker's domain and the share ratio. You can find more info in the example below. |
QBIT_ADD_TRACKERS_IN_TAGS | Optional. For better visibility, you can set this env to True and the torrent will have the tracker name applied in it's tags. Note: This only works with the specified trackers in the env var QBIT_TRACKERS_WITH_RATIO_TRESHOLD. |
QBIT_SET_DEFAULT_QBIT_RATIO | Optional. By default this is set to True - the value from the env var QBIT_RATIO_TRESHOLD will be automatically applied to all torrents (This is so that there will be no breaking changes from the previous versions). Basically this will force all torrents to have the QBIT_RATIO_TRESHOLD number set as share ratio - use it ONLY if you are not managing the share ratio in external apps or yourself. |
DISCORD_WEBHOOK | Optional, but VERY useful, in order to have insight. This is the discord webhook url. It will send report to discord every N seconds (see CHECK_INTERVAL env var), ONLY if the conditions previously discussed are met. It will output the total size (MB/GB) that have been freed on disk, as well as the individual torrents that were removed. This env var if not specified will default to xxx, which is nonexistent webhook url. |
CHECK_INTERVAL | Optional. This is the interval of time (in seconds) that the script will be called to check if there are any new torrents that meet the previously discussed criteria for deletion. This env var if not specified will default to 300 (5 minutes). |
docker create --name=qbittorrentremover -d --net=myCustomNet -e QBIT_LOGIN_USER=admin -e QBIT_LOGIN_PASS=adminadmin -e QBIT_PORT=3000 -e QBIT_IP=qbittorrent -e QBIT_RATIO_TRESHOLD=1.0 -e QBIT_TIME_DELAY=3600 -e QBIT_ABSOLUTE_TIME_DELAY=604800 -e QBIT_TRACKERS_WITH_RATIO_TRESHOLD="torrentleech.org#[email protected];[email protected]" -e QBIT_ADD_TRACKERS_IN_TAGS=True -e QBIT_SET_DEFAULT_QBIT_RATIO=True -e DISCORD_WEBHOOK=yourWebhook -e CHECK_INTERVAL=300 dokeraj/qbittorrent-remover:latest
Explanation: Create the container using my previously created custom network mYCustomNet. Use the default login credentials on the port 3000. The IP address is the name of the qBittorrent docker container, in our case the docker container is called qbittorent. Only when the torrent reaches ratio of 1.0 and it has been one hour after the torrent has completed - delete this torrent. If this condition is not met after 1 week, then delete all completed torrents.
QBIT_TRACKERS_WITH_RATIO_TRESHOLD explains that if the torrent in the trackers string has a substring of torrentleech.org the share ratio of 2.0 will be set to this particular torrent (note the @2.0 portion of the QBIT_TRACKERS_WITH_RATIO_TRESHOLD env var). This specific torrent will have to be seeded up to 2.0 ratio in order to be eligible to be deleted. In addition to that, each time the script checks all of the torrents, this specific torrent will be set to MAX share ratio to 2.0. You can notice that there is a semicolon ; symbol that separates the two trackers in QBIT_TRACKERS_WITH_RATIO_TRESHOLD env var. Also you will notice that there is a #TorrentLeech substring in the env var. So this torrent will have the value TorrentLeech in it's tag. The symbol # is a separator between the tracker's url and tracker's alias. Note that this substring #TorrentLeech is optional and it can be ommited. If it is ommited then the tracker's url will be displayed instead in the tags. This value will be added in the tags of the torrent because the QBIT_ADD_TRACKERS_IN_TAGS is set to True.
Also QBIT_SET_DEFAULT_QBIT_RATIO env var on each check for eligible torrents to delete, will set the share ratio 1.0 to ALL torrents (excluding the ones that have the trackers torrentleech and torrent.eu.org - since they are explicitly stated to have different share ratios of 2.0 and 3.8 respectively).
Send report to discord about the total size of disk space was freed as well which torrents are deleted (with each torrent's size). Run the script every 5 minutes to check if there are new candidates and delete them if the conditions are met.
You can find the source at this location
Content type
Image
Digest
sha256:1cf5eac60…
Size
23.2 MB
Last updated
4 months ago
docker pull dokeraj/qbittorrent-remover