Files
shelfmark/tests/prowlarr/test_download_dir_resolution.py
T
amura11andClaude Sonnet 5.5 ceb23dda7c feat(clients): separate audiobook download directory for torrent clients (#1500)
## Summary

Related to #1048 (covers the "separate book and audiobook locations"
request, not per-category routing).

Every download client already had a separate audiobook label/category,
but the four torrent clients only had a single save directory, so books
and audiobooks ended up mixed in the client's download folder.

Each torrent client (qBittorrent, Transmission, Deluge, rTorrent) gets
an opt-in **Separate Book and Audiobook Directories** toggle
(`<CLIENT>_SEPARATE_DOWNLOAD_DIRS`, default off):

- **Off (default):** unchanged. The single `<CLIENT>_DOWNLOAD_DIR` is
used for everything, so existing setups behave exactly as before.
- **On:** `<CLIENT>_DOWNLOAD_DIR_BOOK` and
`<CLIENT>_DOWNLOAD_DIR_AUDIOBOOK` replace the shared field. A directory
left empty means the client's own default; it never falls back to the
shared directory or another Shelfmark setting.

The content type was already passed to each client's `add_download`, so
a small shared helper (`resolve_download_dir`) does the selection.

Usenet clients are unchanged: their save location comes from the
category configured in the client, and a separate audiobook category is
already sent.

## Screenshots

Default Setting
<img width="817" height="271" alt="Screenshot 2026-10-20 at 14-54-26
Shelfmark"
src="https://github.com/user-attachments/assets/29941f83-9034-4ea5-bcb2-8e91ce77e63a"
/>

Separate Locations
<img width="817" height="425" alt="Screenshot 2026-10-20 at 14-54-58
Shelfmark"
src="https://github.com/user-attachments/assets/772b7194-a072-4945-bac5-b6959550fd75"
/>


## Not included

Routing to many folders by document type (the main request in #1048)
still only exists for Direct download via Content-Type Routing.
Extending it to torrent and usenet sources needs a decision on what to
route by.

## Testing

- `pytest tests --ignore=tests/e2e` passes (3561 passed); ruff clean.
The `tests/e2e/platform` suite needs a running cluster and was not run.
- New unit tests for the helper (including no fallback to the shared
directory) and a qBittorrent add test covering book vs audiobook
directories.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-21 10:23:14 -04:00

45 lines
1.2 KiB
Python

"""Tests for per-content-type torrent client download directories."""
import pytest
from shelfmark.download.clients._coercion import resolve_download_dir
@pytest.mark.parametrize(
("separate", "content_type", "expected"),
[
(False, "audiobook", "/shared"),
(False, "ebook", "/shared"),
(False, None, "/shared"),
(True, "audiobook", "/audio"),
(True, "ebook", "/books"),
(True, None, "/books"),
],
)
def test_resolve_download_dir(separate, content_type, expected):
assert (
resolve_download_dir(
separate=separate,
shared_dir="/shared",
book_dir="/books",
audiobook_dir="/audio",
content_type=content_type,
)
== expected
)
def test_separate_dirs_do_not_fall_back_to_shared_dir():
"""Empty per-type directories mean the client default, never the shared directory."""
for content_type in ("audiobook", "ebook"):
assert (
resolve_download_dir(
separate=True,
shared_dir="/shared",
book_dir="",
audiobook_dir="",
content_type=content_type,
)
== ""
)