Skip to content

Fix: multi-format ebook downloads import a format the profile has disabled - #55

Merged
robertlordhood merged 2 commits into
Chaptarr:developfrom
sebclark:fix-ebook-format-selection-allowed
Aug 17, 2026
Merged

Fix: multi-format ebook downloads import a format the profile has disabled#55
robertlordhood merged 2 commits into
Chaptarr:developfrom
sebclark:fix-ebook-format-selection-allowed

Conversation

@sebclark

Copy link
Copy Markdown
Contributor

The bug (reported on Discord)

A grabbed release contains several text formats for the same book (e.g. EPUB + AZW3 + MOBI). The quality profile allows only EPUB, with AZW3 disabled but sitting higher in the list. On import, Chaptarr picks and imports the AZW3 and rejects the EPUB as a duplicate format.

Root cause

SelectSingleEbookAlternative reduces the download's formats to one winner using CompareEbookImportCandidate, which defers to QualityModelComparer. That comparer ranks purely by position in the profile's Items list — Allowed is never consulted anywhere in the pick (QualityProfile.GetIndex walks positions only). Disabled therefore means "don't grab" at search time but is invisible at import time, so a disallowed format ranked above the preferred one wins.

This also explains the known workaround (moving EPUB to the top of the list): reordering changes the comparer's ranking even though the checkboxes do nothing.

Fix

Partition the download's candidates into profile-allowed vs disallowed before running the winner aggregation, and pick from the allowed set whenever it is non-empty. List order still breaks ties within the allowed set.

Open question for review: when the download contains no allowed format at all, this PR falls back to the existing ranked pick rather than rejecting everything — importing something seemed better than stranding the download at import-blocked. If you'd rather hard-reject in that case, happy to change it.

Tests

Extended ImportApprovedBooksEbookAlternativeFixture:

  • should_prefer_allowed_format_over_higher_ranked_disallowed_format — written first against the unpatched code, where it fails with Expected: <EPUB> But was: <AZW3>, reproducing the report exactly; passes with the fix
  • should_fall_back_to_profile_order_when_no_format_is_allowed — pins the fallback behaviour
  • Existing all-formats-allowed test unchanged and passing

Full MediaFiles suite: 705/705 passing.

When a completed download contains multiple text formats for one book,
SelectSingleEbookAlternative picks the winner with QualityModelComparer,
which ranks purely by profile Items position and never reads Allowed.
A disallowed format ranked above the preferred one therefore imports
(e.g. profile allows only EPUB, download has EPUB+AZW3+MOBI, AZW3 wins).

Prefer profile-allowed formats when selecting; fall back to the existing
ranked pick only when the download contains no allowed format at all, so
downloads never strand at import.
@robertlordhood
robertlordhood merged commit 5713d83 into Chaptarr:develop Aug 17, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants