Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/web/src/api/schema.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 34 additions & 6 deletions apps/web/src/pages/DownloadPreferences.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export default function DownloadPreferences({
{current.isPending && <Loading />}
{current.data && (
<Editor
key={`${scope}:${current.data.revision}`}
key={scope}
admin={admin}
scope={scope}
librariesOnly={librariesOnly}
Expand All @@ -78,7 +78,7 @@ function Editor({
admin,
scope,
librariesOnly,
current,
current: latest,
onSaved,
onEdit,
}: {
Expand All @@ -90,7 +90,18 @@ function Editor({
onEdit: () => void;
}) {
const cache = useQueryClient();
const [overrides, setOverrides] = useState(current.overrides);
const [draft, setDraft] = useState<{
base: Defaults;
overrides: Defaults["overrides"];
} | null>(null);
// A refresh must not replace the draft or authorize saving against a newer revision.
const current = draft?.base ?? latest;
const overrides = draft?.overrides ?? current.overrides;
const setOverrides = (value: Defaults["overrides"]) =>
setDraft((previous) => ({
base: previous?.base ?? latest,
overrides: value,
}));
const [merge, setMerge] = useState<boolean | null>(null);
const showAudiobookImport =
admin && !librariesOnly && scope === "installation";
Expand Down Expand Up @@ -126,11 +137,28 @@ function Editor({
}),
)
: null;
return { preferences, settings };
return {
preferences,
settings,
submittedDraft: draft,
submittedMerge: merge,
};
},
onSuccess: async ({ preferences, settings }) => {
onSuccess: async ({
preferences,
settings,
submittedDraft,
submittedMerge,
}) => {
onSaved();
setMerge(null);
setDraft((next) =>
next === submittedDraft
? null
: next
? { ...next, base: preferences }
: null,
);
setMerge((next) => (next === submittedMerge ? null : next));
cache.setQueryData(["download-defaults", scope], preferences);
if (settings) cache.setQueryData(["organization-settings"], settings);
await Promise.all([
Expand Down
62 changes: 62 additions & 0 deletions apps/web/tests/download-defaults.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,26 +68,85 @@ test("download defaults inherit per field and persist after reload", async ({
await expect(panel.getByRole("status")).toContainText(
"Download defaults saved",
);
let releasePersonal!: () => void;
const personalRefresh = new Promise<void>((resolve) => {
releasePersonal = resolve;
});
await page.route("**/api/acquisition/preferences/personal", async (route) => {
const response = await route.fetch();
await personalRefresh;
await route.fulfill({ response });
});
await panel.getByLabel("Apply to").selectOption("personal");
await panel.getByText("Formats and transfer limits", { exact: true }).click();
const ebooks = panel.getByRole("group", {
name: "Ebook format preference",
exact: true,
});
// A refresh of cached personal defaults must not collapse or discard a draft.
await expect(ebooks).toBeVisible();
await panel.getByLabel("Require standalone copies", { exact: true }).check();
const refreshedPersonal = page.waitForResponse(
"**/api/acquisition/preferences/personal",
);
releasePersonal();
await refreshedPersonal;
await page.unroute("**/api/acquisition/preferences/personal");
await expect(
panel.getByLabel("Require standalone copies", { exact: true }),
).toBeChecked();
await expect(ebooks.getByRole("listitem").first()).toContainText("EPUB");
await panel
.getByRole("button", { name: "Save download defaults", exact: true })
.click();
await expect(panel.getByRole("alert")).toContainText(
"Download defaults changed; reload before saving",
);
await page.reload();
await panel.getByText("Formats and transfer limits", { exact: true }).click();
await expect(ebooks.getByRole("listitem").first()).toContainText("PDF");
await panel
.getByRole("button", {
name: "Reorder epub in Ebook format preference",
exact: true,
})
.press("ArrowUp");
let releaseSave!: () => void;
const pendingSave = new Promise<void>((resolve) => {
releaseSave = resolve;
});
await page.route("**/api/acquisition/preferences/personal", async (route) => {
if (route.request().method() !== "PUT") return route.continue();
const response = await route.fetch();
await pendingSave;
await route.fulfill({ response });
});
await panel
.getByRole("button", { name: "Save download defaults", exact: true })
.click();
// Edits made during a save belong to the next save, not the submitted snapshot.
await panel.getByLabel("Require standalone copies", { exact: true }).check();
releaseSave();
await expect(panel.getByRole("status")).toContainText(
"Download defaults saved",
);
await page.unroute("**/api/acquisition/preferences/personal");
await expect(
panel.getByLabel("Require standalone copies", { exact: true }),
).toBeChecked();
await panel
.getByRole("button", { name: "Save download defaults", exact: true })
.click();
await expect(panel.getByRole("status")).toContainText(
"Download defaults saved",
);
await expect(
panel.getByRole("button", { name: "Save download defaults", exact: true }),
).toBeDisabled();
await page.reload();
await expect(
panel.getByLabel("Require standalone copies", { exact: true }),
).toBeChecked();
await panel.getByText("Formats and transfer limits", { exact: true }).click();
await expect(ebooks.getByRole("listitem").first()).toContainText("EPUB");
await panel
Expand All @@ -97,6 +156,9 @@ test("download defaults inherit per field and persist after reload", async ({
})
.click();
await expect(ebooks.getByRole("listitem").first()).toContainText("PDF");
await panel
.getByRole("button", { name: "Use inherited defaults", exact: true })
.click();
await panel
.getByRole("button", { name: "Save download defaults", exact: true })
.click();
Expand Down
8 changes: 7 additions & 1 deletion docs/AUTOMATIC-BOOK-MATCHING.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ Minor differences between two long descriptive subtitles require a shared editio

Matching revisions include the new rules so cached failures can be reconsidered. Library matches are reconsidered on the next eligible sync; held imports can use **Check again automatically**.

For a single completed download, the saved request and agreeing release metadata may identify otherwise untagged files. Prowlarr releases may supply an exact author/title pair in their name. Series-only credits still need independent embedded evidence. Conflicting file metadata and requests for a specific edition retain stricter review.
For a single completed download, the saved request and agreeing release metadata may identify otherwise untagged files. Prowlarr releases may supply an exact author/title pair in their name. A series-only embedded title also needs agreeing authors, a complete single-book download, and fresh, unique catalog series membership at the same position. Conflicting file metadata and requests for a specific edition retain stricter review.

Release names may place a known series and its position before or after the complete book title. Positions can use digits or canonical Roman numerals, but must agree with the catalog. For example, `Dark Tower II: The Drawing of the Three - Stephen King` can identify that book at position 2. Dotted year, retail, ebook-format and release-group suffixes can follow an exact author/title pair. These labels do not replace inspection of the downloaded files or establish their medium or completeness.

One flat numbered audio sequence (`01.mp3` through `12.mp3`, for example) supplies missing track order and totals when the downloaded manifest is complete. Gaps, duplicate numbers, conflicting tags, incomplete disc sets and partial-release labels still block automatic import. Filename order does not establish book identity on its own. Older inspections can acquire a new proposed order and review revision without rewriting their original evidence or an explicit grouping review.

Expand All @@ -32,3 +34,7 @@ Missing embedded titles or authors do not invalidate a unique edition identifier
Successful automatic imports require no review. A held download can continue automatically with its existing association. When completeness cannot be established, the reviewer confirms the files contain the complete book and adds it to the library; no book or edition picker is shown. Incorrect or ambiguous downloads link to the existing source search for that same book. Correcting catalog metadata uses the existing book metadata page and its Hardcover search.

Downloaded filenames are optional in a small dialog. Naming templates, hashes, grouping identifiers, inspection dumps and the generic catalog picker are absent from linked-download review. The standalone local-folder import tool remains separate. Import retries preserve their frozen plan and request key, and library confirmation is still required before a request becomes satisfied.

EPUBs using standard IDPF font obfuscation can be inspected and imported with their original bytes intact. Other encryption methods, encrypted book content, and invalid font references remain held. The presence of `encryption.xml` alone no longer causes a hold; see the [EPUB font-obfuscation specification](https://www.w3.org/TR/epub-33/#sec-obfuscation-specifying).

After upgrading, open an EPUB held by the old encryption check and choose **Check files again** to rebuild its inspection from the saved download. A source-name hold can be reassessed by searching for the same book and choosing the release again. A continuing hold still needs its stated identity, content, or permission problem resolved; opening the file in another reader does not establish all of those facts.
41 changes: 41 additions & 0 deletions docs/issues/2026-10-15-release-matching.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Release matching and review investigation

Scope: [Dewarr: Release matching and review](https://linear.app/northernlogic/project/dewarr-release-matching-and-review-7dee1b88da14), based on `371ed7c` (2026-10-15). The earlier NOR-87 fix is already merged in #69. This work extends its shared series-label contract and checks its review/import safeguards.

## Confirmed defects and fixes

| Issue | Cause | Result |
| --- | --- | --- |
| [NOR-95 / #62](https://github.com/logabell/dewarr/issues/62) | Series notes removed Arabic digits but left Roman numerals as unmatched text. | Canonical Roman positions match an equal catalog position after recognizing the series name. Wrong positions, malformed numerals and ranges remain rejected. |
| [NOR-97 / #64](https://github.com/logabell/dewarr/issues/64) | The parser recognized series suffixes, but not a series/position prefix before the full book title. The first hyphen could also belong to that prefix. | Both reported title layouts retain the full catalog title and exact author credit, with a known series and matching position required. |
| [NOR-99 / #66](https://github.com/logabell/dewarr/issues/66) | Trailing-label parsing omitted `ebook` and supported only uppercase release groups after audio extensions. | The exact reported dotted retail EPUB release identifies its author/title. Content warnings and actual-file format checks remain separate. |
| [NOR-89 / #56](https://github.com/logabell/dewarr/issues/56), supported EPUB case | Inspection rejected any `META-INF/encryption.xml` before inspecting its algorithm or resources. | Only IDPF font obfuscation of local, declared, non-spine font resources is permitted. Unknown encryption, encrypted chapters, path escapes and ambiguous declarations remain held. |

The reported release names failed a regression check before the parser changes. A synthetic EPUB with standard font-obfuscation metadata likewise failed inspection before the EPUB fix. The synthetic font bytes are a parser fixture, not a test of font rendering or deobfuscation; Dewarr neither renders nor rewrites them.

## Unresolved report details

NOR-89 remains open. Its actual EPUB algorithm/resource list is unavailable, so the supported-font fix is not confirmation of the reporter's file. Adobe/other font-obfuscation algorithms remain unsupported.

The controlled administrator flow withdraws a request, requests it again, completes selection, and records exactly one new download. Existing source and download review screens expose the expected actions in the tested states. This does not reproduce the reporter's missing actions or establish their user role, request history, or deployment version. No blanket approval action or request-state workaround was added. Logan authorized continuing without newer reproduction details.

## Validation

All checks use the repository's serial, bounded `python3 scripts/check.py` runner and synthetic media. API/worker journeys use a disposable PostgreSQL database; external indexer/downloader/library calls use fixtures. No live reporter deployment or external download was exercised.

- 316 focused unit/boundary checks: release names, existing release profiles, series-download identity, automatic eligibility, EPUB encryption, and download inspection.
- 31 API/worker journeys: clicked Prowlarr/SABnzbd release names, withdraw/re-request, original-byte-preserving font-obfuscated EPUB import, series file review/confirmation/replay, and automatic series imports.
- 16 browser checks with fixture API responses: source selection, collection review, download matching, and unreadable-file reinspection. Production frontend build passed.
- 23 further API/worker checks passed after advancing the matching-rule revision: the 21 series-review cases above plus two saved-inspection retry cases. A prior font-encryption hold is re-inspected without submitting another download (33 distinct API/worker cases in total).
- Ruff lint/format and diff whitespace checks pass.

Focused commands:

```sh
python3 scripts/check.py unit tests/unit/test_release_name_identity.py tests/unit/test_release_profiles.py tests/unit/test_series_download_identity.py tests/unit/test_automatic_eligibility.py tests/unit/test_epub_encryption.py tests/unit/test_download_inspection.py
python3 scripts/check.py backend tests/integration/test_sabnzbd.py::test_clicked_usenet_release_with_catalog_labels_reaches_downloader tests/integration/test_quick_add.py::test_withdraw_then_request_again_starts_one_new_download 'tests/integration/test_single_file_acquisition.py::test_single_epub_download_to_confirmed_library_keeps_neighbor_private[automatic-obfuscated-font-]' tests/integration/test_series_file_review.py tests/integration/test_series_file_import.py
python3 scripts/check.py backend tests/integration/test_automatic_imports.py::test_retry_reinspects_unreadable_book_without_redownloading tests/integration/test_series_file_review.py
python3 scripts/check.py ui quick-add-sources.spec.ts download-matching.spec.ts collection-review.spec.ts download-inspection-errors.spec.ts
```

See [automatic book matching](../AUTOMATIC-BOOK-MATCHING.md) for user-facing retry instructions. This change does not mark NOR-89 resolved or repeat NOR-87's already-shipped implementation.
2 changes: 1 addition & 1 deletion docs/openapi.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion services/app/domain/automatic_eligibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
EBOOKS = {"epub", "pdf", "cbz"}
AUDIO = {"m4b", "mp3", "flac", "aac", "ogg", "opus"}
SIDECARS = {"jpg", "jpeg", "png", "webp", "opf", "nfo", "txt", "cue", "m3u"}
PARTIAL = re.compile(r"\b(sample|excerpt|preview|incomplete|truncated)\b", re.I)
PARTIAL = re.compile(r"\b(?:sample|excerpt|preview|incomplete|truncated)\d*\b", re.I)
DISC_FOLDER = re.compile(r"(?:^|[\s_(\[])(?:cd|disc|disk|part)\s*\d+\b", re.I)
PACK = re.compile(
r"\b(collection|pack|omnibus|box[ -]?set|anthology|complete series|"
Expand Down
18 changes: 13 additions & 5 deletions services/app/domain/indexer_labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# Full names avoid mistaking short language codes for initials or title words.
LANGUAGES = {name: code for name, code in LANGUAGE_ALIASES.items() if len(name) > 3}
LANGUAGES["deutsch"] = "de"
MEDIA = frozenset({"audiobook", "abook", "hoerbuch", "hörbuch", "hoerspiel", "hörspiel"})
MEDIA = frozenset({"audiobook", "abook", "hoerbuch", "hörbuch", "hoerspiel", "hörspiel", "ebook"})
FORMATS = frozenset({"m4b", "mp3", "epub", "pdf", "flac", "aac", "ogg", "opus", "azw3", "mobi"})
LABELS = MEDIA | FORMATS | LANGUAGES.keys() | {"unabridged", "ungekuerzt", "ungekürzt", "retail"}
_LABEL = rf"(?:{'|'.join(sorted(LABELS))}|(?:19|20)\d{{2}})"
Expand All @@ -17,7 +17,10 @@
rf"[.\s_]+(?P<bare>{_LABEL}))\s*$",
re.I,
)
_GROUP = re.compile(r"(?i:(?:\.|\s)(?:m4b|mp3|flac|aac|ogg|opus))-(?P<group>[A-Z0-9]{2,16})$")
_GROUP = re.compile(
rf"(?:\.|\s)(?:{'|'.join(sorted(FORMATS))})(?:[.\s]+ebook)?-(?P<group>[a-z0-9]{{2,16}})$",
re.I,
)


def indexer_suffixes(value):
Expand All @@ -29,9 +32,14 @@ def indexer_suffixes(value):
labels = []
yield value, labels
if group := _GROUP.search(value):
# A scene group after an audio extension is metadata. Partial/preview
# markers are content warnings even if they use the same spelling.
if not re.fullmatch(r"SAMPLE|PREVIEW|SUMMARY|PART\d*|CD\d*|DISC\d*", group["group"]):
# A scene group after a media extension is metadata. Partial/preview
# markers, including numbered variants, are content warnings.
if not re.fullmatch(
r"(?:sample|preview|summary|excerpt|incomplete|truncated|collection|pack|omnibus|"
r"anthology|boxset|part|cd|disc)\d*",
group["group"],
re.I,
):
value = value[: group.start("group") - 1]
while match := _SUFFIX.search(value):
prefix = value[: match.start()].rstrip()
Expand Down
19 changes: 14 additions & 5 deletions services/app/domain/release_profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
from app.domain.indexer_labels import indexer_language, indexer_suffixes, label_language
from app.domain.narrators import NarratorNames
from app.domain.request_scope import ScopePreferences
from app.domain.series_identity import position_key, title_outside_series_note
from app.domain.series_identity import (
position_key,
title_outside_series_note,
title_outside_series_prefix,
)
from app.domain.title_matching import compatible_title
from app.importing.naming import fingerprint

Expand Down Expand Up @@ -447,15 +451,20 @@ def indexer_title_authors(release, work):
parts = re.split(r"\s+[-–—]\s*|[-–—]\s+", title, maxsplit=1)
if len(parts) == 2 and (credit := normalized(parts[0])) in authors:
source_title = re.sub(r"\s+[-–—]\s*|[-–—]\s+", ": ", parts[1])
if compatible_title(source_title, work["title"], allow_extra_subtitle=True):
if compatible_title(
source_title, work["title"], allow_extra_subtitle=True
) or title_outside_series_prefix(parts[1], work):
matched.add(authors[credit])
# AudiobookBay names, including Prowlarr's copy of them, are
# "Title - Author, Narrator". The catalog author is the first credit.
if not matched:
head, separator, tail = title.partition(" - ")
if separator:
# The first separator can belong to "Series 2 - Title"; the last
# can belong to a narrator credit. Check both with the exact author.
for head, separator, tail in (title.partition(" - "), title.rpartition(" - ")):
if not separator:
continue
credit = normalized(tail.split(",")[0])
bare = title_outside_series_note(head, work)
bare = title_outside_series_note(head, work) or title_outside_series_prefix(head, work)
full_title = normalized(parse_title_labels(work["title"]).title)
if credit in authors and (
normalized(head) in expected_titles
Expand Down
Loading
Loading