Skip to content

Commit f94f8e8

Browse files
authored
Support subdirectories in format string paths (#182)
* Create parent directories for format string paths * Document format string fields and subdirectory support in CLI help * Add format string options documentation
1 parent 202d2c0 commit f94f8e8

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,25 @@ kobodl book get \
165165
--output-dir /path/to/download_directory \
166166
--format-str '{Title}' \
167167
--get-all
168+
169+
# Download books organized into subdirectories by author
170+
kobodl book get \
171+
--output-dir /path/to/library \
172+
--format-str '{Author}/{Title}' \
173+
--get-all
168174
```
169175

176+
### Format string options
177+
178+
The `--format-str` option supports the following fields:
179+
- `{Author}` - Book author(s)
180+
- `{Title}` - Book title
181+
- `{ShortRevisionId}` - First 8 characters of the revision ID (useful for avoiding filename collisions)
182+
183+
You can use `/` in the format string to organize books into subdirectories. For example:
184+
- `'{Author}/{Title}'` creates `Author Name/Book Title.epub`
185+
- `'{Author} - {Title} {ShortRevisionId}'` creates `Author Name - Book Title a1b2c3d4.epub` (default)
186+
170187
Running the web UI
171188

172189
``` bash

kobodl/actions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ def GetBookOrBooks(
266266

267267
try:
268268
click.echo(f'Downloading {currentProductId} to {outputFilePath}', err=True)
269+
os.makedirs(os.path.dirname(outputFilePath), exist_ok=True)
269270
kobo.Download(bookMetadata, book_type == BookType.AUDIOBOOK, outputFilePath)
270271
except Exception as e:
271272
if productId:

kobodl/commands/book.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,12 @@ def book():
4343
'--format-str',
4444
type=click.STRING,
4545
default=r'{Author} - {Title} {ShortRevisionId}',
46-
help=r"default: '{Author} - {Title} {ShortRevisionId}'",
46+
help=(
47+
"Format string for output filename. "
48+
"Available fields: {Author}, {Title}, {ShortRevisionId}. "
49+
"Use '/' to create subdirectories (e.g., '{Author}/{Title}'). "
50+
"Default: '{Author} - {Title} {ShortRevisionId}'"
51+
),
4752
)
4853
@click.argument('product-id', nargs=-1, type=click.STRING)
4954
@click.pass_obj

0 commit comments

Comments
 (0)