Skip to content

Commit 39b80ac

Browse files
authored
feat(torrent): add preset support (#6)
* feat(torrent): presets * feat(torrent): add preset support * chore: make lint * fix: preset locations
1 parent 7642731 commit 39b80ac

File tree

11 files changed

+591
-90
lines changed

11 files changed

+591
-90
lines changed

Diff for: README.md

+122-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ mkbrr is a command-line tool to create and inspect torrent files. Fast, single b
2121
- [Create a Torrent](#create-a-torrent)
2222
- [Single Mode](#single-mode)
2323
- [Batch Mode](#batch-mode)
24+
- [Preset Mode](#preset-mode)
2425
- [Create Flags](#create-flags)
2526
- [Batch Configuration Format](#batch-configuration-format)
27+
- [Preset Configuration Format](#preset-configuration-format)
2628
- [Inspect a Torrent](#inspect-a-torrent)
2729
- [Version Information](#version-information)
2830
- [Performance](#performance)
@@ -102,6 +104,8 @@ jobs:
102104
- https://releases.ubuntu.com/22.04/ubuntu-22.04.3-desktop-amd64.iso
103105
comment: "Ubuntu 22.04.3 LTS Desktop AMD64"
104106
private: false
107+
# piece_length is automatically optimized based on file size:
108+
# piece_length: 22 # manual override if needed (2^n: 14-24)
105109

106110
- output: release.torrent
107111
path: /path/to/release
@@ -115,25 +119,80 @@ jobs:
115119
116120
Batch mode will process all jobs in parallel (up to 4 concurrent jobs) and provide a summary of results.
117121
122+
#### Preset Mode
123+
124+
Create torrents using predefined settings from a preset configuration:
125+
126+
```bash
127+
# Use a preset from a config file
128+
mkbrr create -P private path/to/file
129+
130+
# Use a preset from a custom config file
131+
mkbrr create -P emp --preset-file custom-presets.yaml path/to/file
132+
133+
# Override preset settings with command line flags
134+
mkbrr create -P private --source "CUSTOM" path/to/file
135+
```
136+
137+
> [!TIP]
138+
> The preset file is searched for in the following locations (in order):
139+
> 1. File specified by `--preset-file` flag
140+
> 2. `presets.yaml` in the current directory
141+
> 3. `~/.config/mkbrr/presets.yaml` in the user's home directory
142+
> 4. `~/.mkbrr/presets.yaml` in the user's home directory
143+
144+
Example presets.yaml:
145+
146+
```yaml
147+
version: 1
148+
149+
# Defaults that always apply
150+
default:
151+
private: true
152+
no_date: true
153+
154+
presets:
155+
# Empornium preset
156+
emp:
157+
source: "EMP"
158+
trackers:
159+
- "https://tracker.opentrackr.org/announce"
160+
# piece_length is automatically optimized based on file size
161+
# piece_length: 20 # manual override if needed (2^n: 14-24)
162+
163+
# Public tracker preset
164+
public:
165+
private: false # overrides default preset
166+
trackers:
167+
- "udp://tracker.opentrackr.org:1337/announce"
168+
- "udp://open.tracker.cl:1337/announce"
169+
- "udp://9.rarbg.com:2810/announce"
170+
# piece_length is automatically optimized based on file size
171+
# piece_length: 22 # manual override if needed (2^n: 14-24)
172+
```
173+
118174
#### Create Flags
119175

120176
General flags:
121177

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

125183
Single mode flags:
126184

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

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

138197
#### Batch Configuration Format
139198

@@ -149,13 +208,74 @@ jobs: # List of torrent creation jobs
149208
- string
150209
webseeds: # Optional: List of webseed URLs
151210
- string
152-
private: bool # Optional: Make torrent private (default: false)
211+
private: bool # Optional: Make torrent private (default: true)
153212
piece_length: int # Optional: Piece length exponent (14-24)
154213
comment: string # Optional: Torrent comment
155214
source: string # Optional: Source tag
156215
no_date: bool # Optional: Don't write creation date (default: false)
157216
```
158217
218+
#### Preset Configuration Format
219+
220+
The preset configuration file uses YAML format with the following structure:
221+
222+
```yaml
223+
# yaml-language-server: $schema=https://raw.githubusercontent.com/autobrr/mkbrr/main/schema/presets.json
224+
version: 1 # Required, must be 1
225+
226+
# Optional: Default settings that apply to all presets unless overridden
227+
default:
228+
private: true
229+
no_date: true
230+
trackers:
231+
- string
232+
# ... other settings as needed
233+
234+
presets: # Map of preset names to their configurations
235+
preset-name:
236+
trackers: # Optional: List of tracker URLs (overrides default)
237+
- string
238+
webseeds: # Optional: List of webseed URLs (overrides default)
239+
- string
240+
private: bool # Optional: Make torrent private (overrides default)
241+
piece_length: int # Optional: Piece length exponent (14-24)
242+
comment: string # Optional: Torrent comment (overrides default)
243+
source: string # Optional: Source tag (overrides default)
244+
no_date: bool # Optional: Don't write creation date (overrides default)
245+
```
246+
247+
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.
248+
249+
Example presets.yaml:
250+
251+
```yaml
252+
version: 1
253+
254+
# Defaults that always apply
255+
default:
256+
private: true
257+
no_date: true
258+
259+
presets:
260+
# Empornium preset
261+
emp:
262+
source: "EMP"
263+
trackers:
264+
- "https://tracker.opentrackr.org/announce"
265+
# piece_length is automatically optimized based on file size
266+
# piece_length: 20 # manual override if needed (2^n: 14-24)
267+
268+
# Public tracker preset
269+
public:
270+
private: false # overrides default preset
271+
trackers:
272+
- "udp://tracker.opentrackr.org:1337/announce"
273+
- "udp://open.tracker.cl:1337/announce"
274+
- "udp://9.rarbg.com:2810/announce"
275+
# piece_length is automatically optimized based on file size
276+
# piece_length: 22 # manual override if needed (2^n: 14-24)
277+
```
278+
159279
### Inspect a Torrent
160280

161281
```bash

0 commit comments

Comments
 (0)