Skip to content

Commit

Permalink
feat: remove commands that are not needed for our use & update docs (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
onedr0p authored Aug 23, 2023
1 parent 2900b0e commit 9c11765
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 567 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
push:
branches:
- master
pull_request:

jobs:
build:
Expand All @@ -20,6 +21,7 @@ jobs:
images: ghcr.io/${{ github.repository }}
tags: |
type=ref,event=branch
type=ref,event=pr
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
Expand Down
247 changes: 30 additions & 217 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Upstream

This is a maintained fork of the upstream project at https://gitlab.com/AlexKM/qbittools.
This is an opinionated fork of the upstream project at https://gitlab.com/AlexKM/qbittools.

## Description

Expand All @@ -11,35 +11,17 @@ qbittools is a feature rich CLI for the management of torrents in qBittorrent.
- [Upstream](#upstream)
- [Description](#description)
- [Table of contents](#table-of-contents)
- [Requirements](#requirements)
- [Installation](#installation)
- [Docker image](#docker-image)
- [Building binary manually with Docker (optional)](#building-binary-manually-with-docker-optional)
- [Run as a script (optional)](#run-as-a-script-optional)
- [Building](#building)
- [Configuration](#configuration)
- [Usage](#usage)
- [Help](#help)
- [Subcommands](#subcommands)
- [Add](#add)
- [Operating system limits](#operating-system-limits)
- [ruTorrent / AutoDL](#rutorrent--autodl)
- [Unpause](#unpause)
- [Automatic unpause in qBittorrent](#automatic-unpause-in-qbittorrent)
- [Tagging](#tagging)
- [Automatic tagging with Cron](#automatic-tagging-with-cron)
- [Reannounce](#reannounce)
- [Reannounce with systemd](#reannounce-with-systemd)
- [Update passkey](#update-passkey)
- [Export](#export)
- [Mover](#mover)
- [Automatic moving with Cron](#automatic-moving-with-cron)
- [Orphaned](#orphaned)

## 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)

## Installation

### Docker image
Expand All @@ -50,9 +32,7 @@ Run a container with access to host network:
docker run -it --rm --network host github.com/buroa/qbittools tagging --unregistered
```

### Building binary manually with Docker (optional)

<details><summary>Click to expand</summary>
### Building

```bash
# clone the repository
Expand All @@ -63,25 +43,6 @@ docker build -t qbittools:latest --pull .
docker run -it --rm --network host qbittools reannounce -p 12345
```

</details>

### Run as a script (optional)

<details><summary>Click to expand</summary>

```bash
# clone the repository
git clone https://github.com/buroa/qbittools.git && cd qbittools
# create and activate virtual environment
virtualenv -p python3 venv
source venv/bin/activate
# install dependencies
install -r requirements.txt
# use qbittools.py instead of the binary
```

</details>

## 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.
Expand All @@ -94,108 +55,29 @@ You also can specify host, port and username manually without a configuration fi

### Help

All commands have extensive help with all available options:

<details><summary>Click to expand</summary>
All commands have extensive help with all available options.

```bash
$ qbittools export -h
usage: qbittools export [-h] -p 12345 [-s 127.0.0.1] [-U username] [-P password] [-i ~/.local/share/qBittorrent/BT_backup] -o ~/export [-c mycategory] [-t [mytag ...]]
usage: qbittools.py reannounce [-h] [--pause-resume] [--process-seeding]
[-C ~/.config/qBittorrent/qBittorrent.conf] [-p 12345] [-s 127.0.0.1] [-U username]
[-P password]

optional arguments:
options:
-h, --help show this help message and exit
--pause-resume Will pause/resume torrents that are invalid.
--process-seeding Will also process seeding torrents for reannouncements.
-C ~/.config/qBittorrent/qBittorrent.conf, --config ~/.config/qBittorrent/qBittorrent.conf
-p 12345, --port 12345
port
-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
```

</details>
### Subcommands

#### Add
<details><summary>Click to expand</summary>
Add a single torrent with custom category
```bash
$ qbittools add /path/to/my.torrent -c mycategory
```
Add a folder of torrents and assign multiple tags
```bash
$ qbittools add /path/to/folder -t mytag1 mytag2
```
Add a torrent in paused state and skip hash checking
```bash
$ 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
```bash
$ 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)
```bash
$ qbittools add /path/to/my.torrent --pause-active --pause-active-upspeed-ignore-limit 10240
```
</details>
##### 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:
```bash
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
```bash
$ 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
Expand All @@ -204,19 +86,9 @@ Create useful tags to group torrents by tracker domains, not working trackers, u
$ 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):
<details><summary>Click to expand</summary>
Automatic reannounce on problematic trackers

```bash
$ qbittools reannounce
Expand All @@ -232,89 +104,30 @@ $ qbittools reannounce
07:41:35 PM [Movie.2020.2160p.WEB-DL.H264-GROUP] is active, progress: 11.1%
```

</details>
##### 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:
<details><summary>Click to expand</summary>
```ini
[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
```
</details>
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 [email protected]` if necessary.
#### Update passkey
Update passkey in all matching torrents (all tracker urls that match `--old` parameter):
```bash
$ 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:
<details><summary>Click to expand</summary>
```bash
$ 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
```

</details>

#### 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`

```bash
$ 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`
#### Orphaned

```bash
$ qbittools mover racing -d lts --completion-threshold 30 --active-threshold 600
```
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 pass the `--confirm` flag.

##### Automatic moving with Cron
This command is very opinionated on a certian directory structure so use with caution and make sure you run it without the `--confirm` flag to make sure it won't delete anything unintentional.

Execute every 10 minutes (`crontab -e` and add this entry)
This is how I have my paths laid out where `/downloads/qbittorrent/complete` is the default save path in qBittorrent and each folder under it is a category. `Default Torrent Management Mode: Automatic`, `When Torrent Category changed: Relocate`, `When Default Save Path changed: Relocate affected torrents` and `When Category Save Path changed: Relocate affected torrents` is also set. Also make sure you use an incomplete directory that is outside the `/downloads/qbittorrent/complete` directory.

```
*/10 * * * * /usr/local/bin/qbittools mover racing -d lts
/downloads/qbittorrent
└── complete
├── cross-seed
├── hit-and-runs
├── lidarr
├── manual
├── myanonamouse
├── overlord
├── prowlarr
├── radarr
├── redacted
├── rifftrax
└── sonarr
```

#### 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._

```bash
$ qbittools orphaned
$ qbittools orphaned --ignore-pattern "*_unpackerred" --ignore-pattern "*/manual/*"
```
Loading

0 comments on commit 9c11765

Please sign in to comment.