Fix: multi-format ebook downloads import a format the profile has disabled - #55
Merged
robertlordhood merged 2 commits intoAug 17, 2026
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
SelectSingleEbookAlternativereduces the download's formats to one winner usingCompareEbookImportCandidate, which defers toQualityModelComparer. That comparer ranks purely by position in the profile'sItemslist —Allowedis never consulted anywhere in the pick (QualityProfile.GetIndexwalks 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 withExpected: <EPUB> But was: <AZW3>, reproducing the report exactly; passes with the fixshould_fall_back_to_profile_order_when_no_format_is_allowed— pins the fallback behaviourFull MediaFiles suite: 705/705 passing.