Skip to content

Commit

Permalink
feat(torrent): add preset support (#6)
Browse files Browse the repository at this point in the history
* feat(torrent): presets

* feat(torrent): add preset support

* chore: make lint

* fix: preset locations
  • Loading branch information
s0up4200 authored Jan 23, 2025
1 parent 7642731 commit 39b80ac
Show file tree
Hide file tree
Showing 11 changed files with 591 additions and 90 deletions.
124 changes: 122 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ mkbrr is a command-line tool to create and inspect torrent files. Fast, single b
- [Create a Torrent](#create-a-torrent)
- [Single Mode](#single-mode)
- [Batch Mode](#batch-mode)
- [Preset Mode](#preset-mode)
- [Create Flags](#create-flags)
- [Batch Configuration Format](#batch-configuration-format)
- [Preset Configuration Format](#preset-configuration-format)
- [Inspect a Torrent](#inspect-a-torrent)
- [Version Information](#version-information)
- [Performance](#performance)
Expand Down Expand Up @@ -102,6 +104,8 @@ jobs:
- https://releases.ubuntu.com/22.04/ubuntu-22.04.3-desktop-amd64.iso
comment: "Ubuntu 22.04.3 LTS Desktop AMD64"
private: false
# piece_length is automatically optimized based on file size:
# piece_length: 22 # manual override if needed (2^n: 14-24)

- output: release.torrent
path: /path/to/release
Expand All @@ -115,25 +119,80 @@ jobs:
Batch mode will process all jobs in parallel (up to 4 concurrent jobs) and provide a summary of results.
#### Preset Mode
Create torrents using predefined settings from a preset configuration:
```bash
# Use a preset from a config file
mkbrr create -P private path/to/file

# Use a preset from a custom config file
mkbrr create -P emp --preset-file custom-presets.yaml path/to/file

# Override preset settings with command line flags
mkbrr create -P private --source "CUSTOM" path/to/file
```

> [!TIP]
> The preset file is searched for in the following locations (in order):
> 1. File specified by `--preset-file` flag
> 2. `presets.yaml` in the current directory
> 3. `~/.config/mkbrr/presets.yaml` in the user's home directory
> 4. `~/.mkbrr/presets.yaml` in the user's home directory
Example presets.yaml:

```yaml
version: 1

# Defaults that always apply
default:
private: true
no_date: true

presets:
# Empornium preset
emp:
source: "EMP"
trackers:
- "https://tracker.opentrackr.org/announce"
# piece_length is automatically optimized based on file size
# piece_length: 20 # manual override if needed (2^n: 14-24)

# Public tracker preset
public:
private: false # overrides default preset
trackers:
- "udp://tracker.opentrackr.org:1337/announce"
- "udp://open.tracker.cl:1337/announce"
- "udp://9.rarbg.com:2810/announce"
# piece_length is automatically optimized based on file size
# piece_length: 22 # manual override if needed (2^n: 14-24)
```

#### Create Flags

General flags:

- `-b, --batch <file>`: Use batch configuration file (YAML)
- `-P, --preset <name>`: Use preset from config
- `--preset-file <file>`: Preset config file (default: ~/.config/mkbrr/presets.yaml)
- `-v, --verbose`: Be verbose

Single mode flags:

- `-t, --tracker <url>`: Tracker URL
- `-w, --web-seed <url>`: Add web seed URLs (can be specified multiple times)
- `-p, --private`: Make torrent private
- `-p, --private`: Make torrent private (default: true)
- `-c, --comment <text>`: Add comment
- `-l, --piece-length <n>`: Set piece length to 2^n bytes (14-24, automatic if not specified)
- `-o, --output <path>`: Set output path (default: <name>.torrent)
- `-s, --source <text>`: Add source string
- `-d, --no-date`: Don't write creation date

Note: When using batch mode (-b), torrent settings are specified in the YAML configuration file instead of command line flags.
When using preset mode (-P), command line flags will override the preset settings.

#### Batch Configuration Format

Expand All @@ -149,13 +208,74 @@ jobs: # List of torrent creation jobs
- string
webseeds: # Optional: List of webseed URLs
- string
private: bool # Optional: Make torrent private (default: false)
private: bool # Optional: Make torrent private (default: true)
piece_length: int # Optional: Piece length exponent (14-24)
comment: string # Optional: Torrent comment
source: string # Optional: Source tag
no_date: bool # Optional: Don't write creation date (default: false)
```
#### Preset Configuration Format
The preset configuration file uses YAML format with the following structure:
```yaml
# yaml-language-server: $schema=https://raw.githubusercontent.com/autobrr/mkbrr/main/schema/presets.json
version: 1 # Required, must be 1

# Optional: Default settings that apply to all presets unless overridden
default:
private: true
no_date: true
trackers:
- string
# ... other settings as needed

presets: # Map of preset names to their configurations
preset-name:
trackers: # Optional: List of tracker URLs (overrides default)
- string
webseeds: # Optional: List of webseed URLs (overrides default)
- string
private: bool # Optional: Make torrent private (overrides default)
piece_length: int # Optional: Piece length exponent (14-24)
comment: string # Optional: Torrent comment (overrides default)
source: string # Optional: Source tag (overrides default)
no_date: bool # Optional: Don't write creation date (overrides default)
```
Any settings specified in a preset will override the corresponding default settings. This allows you to set common values in the `default` section and only specify differences in individual presets.

Example presets.yaml:

```yaml
version: 1
# Defaults that always apply
default:
private: true
no_date: true
presets:
# Empornium preset
emp:
source: "EMP"
trackers:
- "https://tracker.opentrackr.org/announce"
# piece_length is automatically optimized based on file size
# piece_length: 20 # manual override if needed (2^n: 14-24)
# Public tracker preset
public:
private: false # overrides default preset
trackers:
- "udp://tracker.opentrackr.org:1337/announce"
- "udp://open.tracker.cl:1337/announce"
- "udp://9.rarbg.com:2810/announce"
# piece_length is automatically optimized based on file size
# piece_length: 22 # manual override if needed (2^n: 14-24)
```

### Inspect a Torrent

```bash
Expand Down
Loading

0 comments on commit 39b80ac

Please sign in to comment.