From 62973277c6fdffa7cc3dcf033aa478f0925111d8 Mon Sep 17 00:00:00 2001 From: Xwite <82232510+Xwite@users.noreply.github.com> Date: Mon, 10 Oct 2022 09:54:57 +0800 Subject: [PATCH] =?UTF-8?q?Epub:=20=E4=BF=AE=E5=A4=8DFragmentId=E7=9B=B8?= =?UTF-8?q?=E5=90=8C=E5=AF=BC=E8=87=B4=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/model/localBook/EpubFile.kt | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/io/legado/app/model/localBook/EpubFile.kt b/app/src/main/java/io/legado/app/model/localBook/EpubFile.kt index 10a387662..75221da15 100644 --- a/app/src/main/java/io/legado/app/model/localBook/EpubFile.kt +++ b/app/src/main/java/io/legado/app/model/localBook/EpubFile.kt @@ -92,7 +92,7 @@ class EpubFile(var book: Book) { cover.compress(Bitmap.CompressFormat.JPEG, 90, out) out.flush() out.close() - } ?: AppLog.put("封面获取为空") + } ?: AppLog.putDebug("Epub: 封面获取为空. path: ${book.BookUrl}") } } } catch (e: Exception) { @@ -140,16 +140,25 @@ class EpubFile(var book: Book) { val isNextChapterResource = res.href == nextUrl?.substringBeforeLast("#") if (isFirstResource) { // add first resource to elements - elements.add(getBody(res, startFragmentId, endFragmentId)) + elements.add( + /* pass endFragmentId if only has one resource */ + getBody(res, startFragmentId, endFragmentId) + ) // check current resource - if (isNextChapterResource) break + if (isNextChapterResource) { + /* FragmentId should not be same in same resource */ + if (!endFragmentId.isNullOrBlank() && endFragmentId == startFragmentId) + AppLog.putDebug("Epub: Resource (${res.href}) has same FragmentId, check the file: ${book.bookUrl}") + break + } hasMoreResources = true } else if (hasMoreResources) { if (isNextChapterResource) { - if (includeNextChapterResource) elements.add(getBody(res, startFragmentId, endFragmentId)) + if (includeNextChapterResource) elements.add(getBody(res, null/* FragmentId may be same in different resources, pass null */, endFragmentId)) break } - elements.add(getBody(res, startFragmentId, endFragmentId)) + // rest resource should not have fragmentId, pass null + elements.add(getBody(res, null, null)) } } //title标签中的内容不需要显示在正文中,去除 @@ -226,7 +235,7 @@ class EpubFile(var book: Book) { epubBook?.let { eBook -> val refs = eBook.tableOfContents.tocReferences if (refs == null || refs.isEmpty()) { - AppLog.put("NCX file parse error, check the epub file") + AppLog.putDebug("Epub: NCX file parse error, check the file: ${book.bookUrl}") val spineReferences = eBook.spine.spineReferences var i = 0 val size = spineReferences.size