From e2ea6bd76615ac6178a4ad7de9dbf6d77f8020d0 Mon Sep 17 00:00:00 2001 From: Horis <821938089@qq.com> Date: Thu, 12 Jan 2023 22:20:06 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/constant/AppPattern.kt | 2 ++ .../main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt | 3 ++- app/src/main/java/io/legado/app/model/localBook/EpubFile.kt | 5 +++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/legado/app/constant/AppPattern.kt b/app/src/main/java/io/legado/app/constant/AppPattern.kt index 78eb47d09..0e999f227 100644 --- a/app/src/main/java/io/legado/app/constant/AppPattern.kt +++ b/app/src/main/java/io/legado/app/constant/AppPattern.kt @@ -39,4 +39,6 @@ object AppPattern { * 不发音段落判断 */ val notReadAloudRegex = Regex("^(\\s|\\p{C}|\\p{P}|\\p{Z}|\\p{S})+$") + + val xmlContentTypeRegex = "(application|text)/\\w*\\+?xml.*".toRegex() } diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt index 18ff3e054..fef2e8c2a 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt @@ -8,6 +8,7 @@ import com.bumptech.glide.load.model.GlideUrl import com.script.SimpleBindings import io.legado.app.constant.AppConst.SCRIPT_ENGINE import io.legado.app.constant.AppConst.UA_NAME +import io.legado.app.constant.AppPattern import io.legado.app.constant.AppPattern.JS_PATTERN import io.legado.app.constant.AppPattern.dataUriRegex import io.legado.app.data.entities.BaseSource @@ -422,7 +423,7 @@ class AnalyzeUrl( } }.let { val isXml = it.raw.body?.contentType()?.toString() - ?.matches("(application|text)/\\w*\\+?xml.*".toRegex()) == true + ?.matches(AppPattern.xmlContentTypeRegex) == true if (isXml && it.body?.trim()?.startsWith("" + it.body) } else it 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 b1a27240b..2e0ef3b01 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 @@ -190,7 +190,8 @@ class EpubFile(var book: Book) { } private fun getBody(res: Resource, startFragmentId: String?, endFragmentId: String?): Element { - val body = Jsoup.parse(String(res.data, mCharset)).body() + val doc = Jsoup.parse(String(res.data, mCharset)) + val body = doc.body() if (!startFragmentId.isNullOrBlank()) { body.getElementById(startFragmentId)?.previousElementSiblings()?.remove() } @@ -215,7 +216,7 @@ class EpubFile(var book: Book) { val children = body.children() children.select("script").remove() children.select("style").remove() - return body + return doc.body() } private fun getImage(href: String): InputStream? {