AlexKMDev / qbittools

Mirror of https://gitlab.com/AlexKM/qbittools

Home Page:https://gitlab.com/AlexKM/qbittools

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Description

qbittools is a feature rich CLI for the management of torrents in qBittorrent.

Donate

If you're feeling generous, you can support this project and me:

By renting a server with my affiliate link: https://my.hostingby.design/aff.php?aff=1008

USDT TRC20: TUH5ySiTHYpG2vrPYu9uCT7ev6DLHDGzkG

BUSD BEP20: 0xb8Eb3c011fB8549a67e8C2A33F55CEA2a5b152F3

XMR: 44ow4aVdjJK7opDHpRsTiXV6hh5y1T7W81phsasJPBcARox7shnWCemDts6rC3icMA6AuBTV4cWR56dFujcLK7P2TYwBQZv

BTC: bc1q468wxv2uvy65ev5l7qlw5zcd0jd765hpncnayy

BCH: qpfspyeljf4d78jyw8p65jxcnxzmwjkk75kccnhuvf

LTC: ltc1qqtm7ss90t7cuzwrjzfwhjfjzt5rswjzftgz9ja

ETH, USDT/BUSD ERC20: 0xb8Eb3c011fB8549a67e8C2A33F55CEA2a5b152F3

Many thanks!

Table of contents

Requirements

  • Any usable Linux distribution (binary builds are built with musl and fully static starting from 0.4.0)

  • ca-certificates (for connecting to https)

  • binary builds are supported only for: Linux x86_64 (limited by PyOxidizer support)

  • docker builds are supported for: Linux amd64, arm64/v8, 386, arm/v6, arm/v7, ppc64le, s390x, Windows and macOS with corresponding architectures, but which still use virtualization to launch Docker in a Linux VM.

Installation

Binary version (only Linux x86_64)

Install the latest version with the install script to /usr/local/bin/qbittools (root privileges needed)

curl -Ls https://gitlab.com/AlexKM/qbittools/-/raw/master/install.sh | sudo bash

Or at any path you want without any extra privileges, don't forget to add this path to $PATH for convenience:

mkdir -p ~/bin
curl -Ls https://gitlab.com/AlexKM/qbittools/-/raw/master/install.sh | bash -s -- -o ~/bin/qbittools

The script creates a temporary directory, retrieves the latest git tag and downloads it's build artifacts that contains the resulting qbittools binary.

Docker image

Run a container with access to host network:

docker run -it --rm --network host registry.gitlab.com/alexkm/qbittools tagging --unregistered -s 127.0.0.1:8080

Connect to a qBittorrent container in the same Docker network:

docker run -it --rm --network mynetwork registry.gitlab.com/alexkm/qbittools tagging --unregistered -s qbittorrent:8080

Run as a python script

Click to expand
# clone the repository
git clone https://gitlab.com/AlexKM/qbittools.git && cd qbittools
# create and activate virtual environment
virtualenv -p python3 venv
source venv/bin/activate
# install dependencies
pip3 install -r requirements.txt
# use qbittools.py
./qbittools.py tagging --unregistered -s 127.0.0.1:8080

Building

Building binary manually with Docker (optional)

Click to expand
# clone the repository
git clone https://gitlab.com/AlexKM/qbittools.git && cd qbittools
# build the image
docker buildx build --platform=linux/amd64 -t qbittools:latest -f Dockerfile.pyoxidizer --build-arg TARGET=x86_64-unknown-linux-musl --build-arg VERSION=0.0.0 --build-arg CACHE_DIR=linux_amd64 -o out/linux_amd64 .

The resulting binary will be located at out/linux_amd64/qbittools.

Configuration

qBittools doesn't have any configuration files currently. It parses host, port and username from the qBittorrent configuration file located by default at ~/.config/qBittorrent/qBittorrent.conf, you can specify a different qBittorrent config with -C flag.

You also have to specify your password every time with -P flag unless you enable Web UI -> Bypass authentication for clients on localhost in qBittorrent's settings, because there is no way for qBittools to retrieve it in plaintext.

You also can specify host and username manually without a configuration file with -s and -U flags accordingly.

Usage

Help

All commands have extensive help with all available options:

Click to expand
$ qbittools export -h
usage: qbittools export [-h] [-s 127.0.0.1] [-U username] [-P password] [-i ~/.local/share/qBittorrent/BT_backup] -o ~/export [-c mycategory] [-t [mytag ...]]

optional arguments:
  -h, --help            show this help message and exit
  -s 127.0.0.1, --server 127.0.0.1
                        host
  -U username, --username username
  -P password, --password password
  -i ~/.local/share/qBittorrent/BT_backup, --input ~/.local/share/qBittorrent/BT_backup
                        Path to qBittorrent .torrent files
  -o ~/export, --output ~/export
                        Path to where to save exported torrents
  -c mycategory, --category mycategory
                        Filter by category
  -t [mytag ...], --tags [mytag ...]
                        Filter by tags

Self-upgrade

Upgrading to the latest version is available with the upgrade command (use sudo if it's in a system path):

Click to expand
$ qbittools upgrade
07:24:14 PM INFO:Current version: 0.0.0
07:24:14 PM INFO:Latest version: 0.0.1
07:24:14 PM INFO:Update available, this will replace /usr/local/bin/qbittools with a new version.
OK to proceed [Y/N]? y
07:24:16 PM INFO:Downloading https://gitlab.com/AlexKM/qbittools/-/jobs/artifacts/0.0.1/download?job=release to /tmp/tmpapfpoqud/qbittools.zip
100%|██████████████████████████| 23.3M/23.3M [00:00<00:00, 107MiB/s]
07:24:17 PM INFO:Extracted binary to /tmp/tmpapfpoqud/qbittools
07:24:17 PM INFO:Replacing /usr/local/bin/qbittools with /tmp/tmpapfpoqud/qbittools

Subcommands

Add

Click to expand

Add a single torrent with custom category

$ qbittools add /path/to/my.torrent -c mycategory

Add a folder of torrents and assign multiple tags

$ qbittools add /path/to/folder -t mytag1 mytag2

Add a torrent in paused state and skip hash checking

$ qbittools add /path/to/my.torrent --add-paused --skip-checking

Don't add more torrents if there are more than 3 downloads active while ignoring downloads with speed under 1 MiB/s

$ qbittools add /path/to/my.torrent --max-downloads 3 --max-downloads-speed-ignore-limit 1024

Pause all active torrents temporarily and mark them with temp_paused tag while ignoring active uploads with speed under 10 MiB/s (You have to configure unpause command in qBittorrent if you want these torrents to be unpaused automatically)

$ qbittools add /path/to/my.torrent --pause-active --pause-active-upspeed-ignore-limit 10240
Operating system limits

If you encounter too many open files or no file descriptors available errors while adding a lot of torrents, you can try to bypass it with simple shell commands, this will add torrents one by one:

IFS=$'\n' find /path/to/your/torrents/ -maxdepth 1 -type f -name "*.torrent" -exec qbittools add {} --skip-checking \;
ruTorrent / AutoDL

Adding torrents from autodl-irssi to qBittorrent using ruTorrent:

Action = Run Program
Command = /usr/local/bin/qbittools
Arguments = add $(TorrentPathName) -c music

Unpause

Only useful if you pause torrents automatically with --pause-active parameters from add command.

Resume all torrents with temp_paused tag if there are no active downloads while ignoring slow downloads under 10 MiB/s

$ qbittools unpause -d 10240
Automatic unpause in qBittorrent

Check Run external program on torrent completion in the settings and use tool with an absolute path:

/usr/local/bin/qbittools unpause -d 10240

Tagging

Create useful tags to group torrents by tracker domains, not working trackers, unregistered torrents and duplicates

$ qbittools tagging --duplicates --unregistered --not-working --added-on --trackers
Automatic tagging with Cron

Execute every 10 minutes (crontab -e and add this entry)

*/10 * * * * /usr/local/bin/qbittools tagging --duplicates --unregistered --not-working --added-on --trackers

Reannounce

Automatic reannounce on problematic trackers (run in screen/tmux to prevent it from closing when you end a ssh session):

Click to expand
$ qbittools reannounce
07:40:40 PM --------------------------
07:40:40 PM [Movie.2020.2160p.WEB-DL.H264-GROUP] is not working, active for 1s, reannouncing...
07:41:20 PM --------------------------
07:41:20 PM [Movie.2020.2160p.WEB-DL.H264-GROUP] has no seeds, active for 78s, reannouncing...
07:41:25 PM --------------------------
07:41:25 PM [Movie.2020.2160p.WEB-DL.H264-GROUP] is active, progress: 0%
07:41:30 PM --------------------------
07:41:30 PM [Movie.2020.2160p.WEB-DL.H264-GROUP] is active, progress: 5.0%
07:41:35 PM --------------------------
07:41:35 PM [Movie.2020.2160p.WEB-DL.H264-GROUP] is active, progress: 11.1%
Reannounce with systemd

Reannounce can be executed and restarted on problems automatically by systemd. Create a new service at /etc/systemd/system/ with the following contents:

Click to expand
[Unit]
Description=qbittools reannounce
After=qbittorrent@%i.service

[Service]
User=%i
Group=%i
ExecStart=/usr/local/bin/qbittools reannounce

Restart=always
RestartSec=3

[Install]
WantedBy=multi-user.target

Restart the daemon with systemctl daemon-reload and start the service with systemctl start qbittools-reannounce@username by replacing username with the user you want to run it from. Check service logs with journalctl -u qbittools-reannounce@username.service if necessary.

Update passkey

Update passkey in all matching torrents (all tracker urls that match --old parameter):

$ qbittools update_passkey --old 12345 --new v3rrjmnfxwq3gfrgs9m37dvnfkvdbqnqc
2021-01-08 21:38:45,301 INFO:Replaced [https://trackerurl.net/12345/announce] to [https://trackerurl.net/v3rrjmnfxwq3gfrgs9m37dvnfkvdbqnqc/announce] in 10 torrents

Export

Export all matching .torrent files by category or tags:

Click to expand
$ qbittools export -o ./export --category movies --tags tracker.org mytag
01:23:43 PM INFO:Matched 47 torrents
01:23:43 PM INFO:Exported [movies] Fatman.2020.BluRay.1080p.TrueHD.5.1.AVC.REMUX-FraMeSToR [fbef10dc89bf8dff21a401d9304f62b074ffd6af].torrent
01:23:43 PM INFO:Exported [movies] La.Haine.1995.UHD.BluRay.2160p.DTS-HD.MA.5.1.DV.HEVC.REMUX-FraMeSToR [ee5ff82613c7fcd2672e2b60fc64375486f976ba].torrent
01:23:43 PM INFO:Exported [movies] Ip.Man.3.2015.UHD.BluRay.2160p.TrueHD.Atmos.7.1.DV.HEVC.REMUX-FraMeSToR [07da008f9c64fe4927ee18ac5c94292f61098a69].torrent
01:23:43 PM INFO:Exported [movies] Brazil.1985.Director's.Cut.BluRay.1080p.FLAC.2.0.AVC.REMUX-FraMeSToR [988e8749a9d3f07e5d216001efc938b732579c16].torrent

Mover

Useful for those who want to move torrents to different categories over time. Combined with enabled Automatic Torrent Management this will move files from one folder to another.

Move torrents inactive for more than 60 seconds and completed more than 60 minutes ago from categories tracker1 and tracker2 to category lts

$ qbittools mover tracker1 tracker2 -d lts

Move torrents inactive for more than 600 seconds and completed more than 30 minutes ago from category racing to category lts

$ qbittools mover racing -d lts --completion-threshold 30 --active-threshold 600
Automatic moving with Cron

Execute every 10 minutes (crontab -e and add this entry)

*/10 * * * * /usr/local/bin/qbittools mover racing -d lts

Orphaned

Find files no longer associated with any torrent, but still present in download folders (default download folder and folders from all categories). This command will remove orphaned files if you confirm it and also clean up all empty folders. Be careful while removing a lot of files if you use these folders from other torrent client.

$ qbittools orphaned

FlexGet

qbittools can be used together with FlexGet via exec plugin, configuration example:

taskname:
  rss:
    url: https://site/feed.rss
    all_entries: no
  seen:
    local: yes
  accept_all: yes
  download:
    path: ~/torrents/rss/
    overwrite: yes
  exec:
    auto_escape: yes
    fail_entries: yes
    on_output:
      for_accepted:
        - /usr/local/bin/qbittools add "{{location}}" -c books --rename "{{title}}" --content-layout Subfolder

About

Mirror of https://gitlab.com/AlexKM/qbittools

https://gitlab.com/AlexKM/qbittools

License:GNU General Public License v3.0


Languages

Language:Python 68.9%Language:Starlark 27.5%Language:Shell 1.9%Language:Makefile 1.4%Language:Dockerfile 0.3%