From 4f94365735d9e21fe9fcf6d37178be8342a1ec03 Mon Sep 17 00:00:00 2001 From: Gauthier Roebroeck Date: Thu, 29 Jan 2026 10:36:28 +0800 Subject: [PATCH] fix(epub): more lenient fixed-layout detection --- .../kotlin/org/gotson/komga/domain/service/BookAnalyzer.kt | 5 +++-- .../infrastructure/mediacontainer/epub/EpubExtractor.kt | 6 ------ .../org/gotson/komga/domain/service/BookAnalyzerTest.kt | 3 +-- 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/komga/src/main/kotlin/org/gotson/komga/domain/service/BookAnalyzer.kt b/komga/src/main/kotlin/org/gotson/komga/domain/service/BookAnalyzer.kt index 6a812501..bfffb679 100644 --- a/komga/src/main/kotlin/org/gotson/komga/domain/service/BookAnalyzer.kt +++ b/komga/src/main/kotlin/org/gotson/komga/domain/service/BookAnalyzer.kt @@ -146,7 +146,6 @@ class BookAnalyzer( ): Media { book.path.epub { epub -> val (resources, missingResources) = epubExtractor.getResources(epub).partition { it.fileSize != null } - val isFixedLayout = epubExtractor.isFixedLayout(epub) val isKepub = epubExtractor.isKepub(epub, resources) val errors = mutableListOf() @@ -180,13 +179,15 @@ class BookAnalyzer( val divinaPages = try { - epubExtractor.getDivinaPages(epub, isFixedLayout, analyzeDimensions) + epubExtractor.getDivinaPages(epub, analyzeDimensions) } catch (e: Exception) { logger.error(e) { "Error while getting EPUB Divina pages" } errors.add("ERR_1038") emptyList() } + val isFixedLayout = divinaPages.isNotEmpty() || epubExtractor.isFixedLayout(epub) + val positions = try { epubExtractor.computePositions(epub, book.path, resources, isFixedLayout, isKepub) diff --git a/komga/src/main/kotlin/org/gotson/komga/infrastructure/mediacontainer/epub/EpubExtractor.kt b/komga/src/main/kotlin/org/gotson/komga/infrastructure/mediacontainer/epub/EpubExtractor.kt index 2fe2cd8b..8c04981e 100644 --- a/komga/src/main/kotlin/org/gotson/komga/infrastructure/mediacontainer/epub/EpubExtractor.kt +++ b/komga/src/main/kotlin/org/gotson/komga/infrastructure/mediacontainer/epub/EpubExtractor.kt @@ -114,14 +114,8 @@ class EpubExtractor( fun getDivinaPages( epub: EpubPackage, - isFixedLayout: Boolean, analyzeDimensions: Boolean, ): List { - if (!isFixedLayout) { - logger.info { "Epub Divina detection failed: book is not fixed layout" } - return emptyList() - } - val pageCount = run { val spine = diff --git a/komga/src/test/kotlin/org/gotson/komga/domain/service/BookAnalyzerTest.kt b/komga/src/test/kotlin/org/gotson/komga/domain/service/BookAnalyzerTest.kt index 30be3955..24981f94 100644 --- a/komga/src/test/kotlin/org/gotson/komga/domain/service/BookAnalyzerTest.kt +++ b/komga/src/test/kotlin/org/gotson/komga/domain/service/BookAnalyzerTest.kt @@ -144,7 +144,6 @@ class BookAnalyzerTest( assertThat(media.mediaType).isEqualTo("application/epub+zip") assertThat(media.status).isEqualTo(Media.Status.READY) - assertThat(media.pages).hasSize(0) } } @@ -230,7 +229,7 @@ class BookAnalyzerTest( val file = ClassPathResource("epub/The Incomplete Theft - Ralph Burke.epub") val book = Book("book", file.url, LocalDateTime.now()) - every { epubExtractor.getDivinaPages(any(), any(), any()) } throws Exception("mock exception") + every { epubExtractor.getDivinaPages(any(), any()) } throws Exception("mock exception") val media = bookAnalyzer.analyze(book, false)