From 5a4cbba1d2e241276cb3f1f77490c3cf529c6c03 Mon Sep 17 00:00:00 2001 From: bushixuanqi <2208877960@qq.com> Date: Sun, 18 Jul 2021 00:23:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=93=BE=E6=8E=A5=E5=88=86?= =?UTF-8?q?=E5=89=B2=E8=A7=84=E5=88=99=EF=BC=8C=E9=81=BF=E5=85=8D=E9=99=84?= =?UTF-8?q?=E5=8A=A0=E5=8F=82=E6=95=B0=E4=B8=AD=E5=AD=98=E5=9C=A8=20,{=20?= =?UTF-8?q?=E6=97=B6=E5=AF=BC=E8=87=B4=E8=A7=84=E5=88=99=E5=88=87=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复这种页数列表写法中,js部分内含 < 或 > 会切割错误的问题 格式化图片和匹配图片规则不在使用同一个正则,加快图片处理速度。 优化一下不需要循环执行却被循环执行的操作 --- .../legado/app/data/entities/BookChapter.kt | 2 +- .../main/java/io/legado/app/model/Debug.kt | 2 +- .../app/model/analyzeRule/AnalyzeRule.kt | 47 ++++++++++--------- .../app/model/analyzeRule/AnalyzeUrl.kt | 2 +- .../read/page/provider/ChapterProvider.kt | 2 +- 5 files changed, 28 insertions(+), 27 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/entities/BookChapter.kt b/app/src/main/java/io/legado/app/data/entities/BookChapter.kt index 77811cba7..c6b4cb9fb 100644 --- a/app/src/main/java/io/legado/app/data/entities/BookChapter.kt +++ b/app/src/main/java/io/legado/app/data/entities/BookChapter.kt @@ -62,7 +62,7 @@ data class BookChapter( } fun getAbsoluteURL():String{ - val urlBefore = url.substringBefore(",{") + val urlBefore = url.substringBefore(',') val urlAbsoluteBefore = NetworkUtils.getAbsoluteURL(baseUrl,urlBefore) return if(urlBefore.length == url.length) urlAbsoluteBefore else urlAbsoluteBefore + url.substring(urlBefore.length) } diff --git a/app/src/main/java/io/legado/app/model/Debug.kt b/app/src/main/java/io/legado/app/model/Debug.kt index dc6259cc4..9908e9dc8 100644 --- a/app/src/main/java/io/legado/app/model/Debug.kt +++ b/app/src/main/java/io/legado/app/model/Debug.kt @@ -120,7 +120,7 @@ object Debug { infoDebug(scope, webBook, book) } key.contains("::") -> { - val url = key.substring(key.indexOf("::") + 2) + val url = key.substringAfter("::") log(webBook.sourceUrl, "⇒开始访问发现页:$url") exploreDebug(scope, webBook, url) } diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt index 225be549c..11f967773 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt @@ -26,7 +26,7 @@ import kotlin.collections.HashMap @Suppress("unused", "RegExpRedundantEscape") class AnalyzeRule(val ruleData: RuleDataInterface) : JsExtensions { - var book: BaseBook? = if (ruleData is BaseBook) ruleData else null + var book = if (ruleData is BaseBook) ruleData else null var chapter: BookChapter? = null var nextChapterUrl: String? = null @@ -65,7 +65,7 @@ class AnalyzeRule(val ruleData: RuleDataInterface) : JsExtensions { fun setRedirectUrl(url: String): URL? { kotlin.runCatching { - redirectUrl = URL(url.substringBefore(",{")) + redirectUrl = URL(url.substringBefore(',')) } return redirectUrl } @@ -192,9 +192,9 @@ class AnalyzeRule(val ruleData: RuleDataInterface) : JsExtensions { @JvmOverloads fun getString( - ruleList: List, - isUrl: Boolean = false, - value: String? = null + ruleList: List, + isUrl: Boolean = false, + value: String? = null ): String { var result: Any? = value val content = this.content @@ -258,8 +258,8 @@ class AnalyzeRule(val ruleData: RuleDataInterface) : JsExtensions { result?.let { result = when (sourceRule.mode) { Mode.Regex -> AnalyzeByRegex.getElement( - result.toString(), - sourceRule.rule.splitNotBlank("&&") + result.toString(), + sourceRule.rule.splitNotBlank("&&") ) Mode.Js -> evalJS(sourceRule.rule, it) Mode.Json -> getAnalyzeByJSonPath(it).getObject(sourceRule.rule) @@ -289,8 +289,8 @@ class AnalyzeRule(val ruleData: RuleDataInterface) : JsExtensions { result?.let { result = when (sourceRule.mode) { Mode.Regex -> AnalyzeByRegex.getElements( - result.toString(), - sourceRule.rule.splitNotBlank("&&") + result.toString(), + sourceRule.rule.splitNotBlank("&&") ) Mode.Js -> evalJS(sourceRule.rule, result) Mode.Json -> getAnalyzeByJSonPath(it).getList(sourceRule.rule) @@ -378,11 +378,6 @@ class AnalyzeRule(val ruleData: RuleDataInterface) : JsExtensions { mMode = Mode.Json ruleStr0.substring(6) } - ruleStr0.startsWith(":") -> { //:与伪类选择器冲突,建议改成?更合理 - mMode = Mode.Regex - isRegex = true - ruleStr0.substring(1) - } ( ruleStr0[1] == '.' || ruleStr0[1] == '[') && ruleStr0[0] == '$' || isJSON -> { mMode = Mode.Json ruleStr0 @@ -393,8 +388,14 @@ class AnalyzeRule(val ruleData: RuleDataInterface) : JsExtensions { } } //拆分为规则列表 - var start = 0 + var start = if(ruleStr.startsWith(":")){ //仅首字符为:时为AllInOne,其实:与伪类选择器冲突,建议改成?更合理 + mMode = Mode.Regex + isRegex = true + 1 + }else 0 var tmp: String + + val jsMatcher = JS_PATTERN.matcher(ruleStr) while (jsMatcher.find()){ @@ -566,8 +567,8 @@ class AnalyzeRule(val ruleData: RuleDataInterface) : JsExtensions { jsEval == null -> Unit jsEval is String -> infoVal.insert(0, jsEval) jsEval is Double && jsEval % 1.0 == 0.0 -> infoVal.insert( - 0, - String.format("%.0f", jsEval) + 0, + String.format("%.0f", jsEval) ) else -> infoVal.insert(0, jsEval.toString()) } @@ -609,8 +610,8 @@ class AnalyzeRule(val ruleData: RuleDataInterface) : JsExtensions { fun put(key: String, value: String): String { chapter?.putVariable(key, value) - ?: book?.putVariable(key, value) - ?: ruleData.putVariable(key, value) + ?: book?.putVariable(key, value) + ?: ruleData.putVariable(key, value) return value } @@ -624,9 +625,9 @@ class AnalyzeRule(val ruleData: RuleDataInterface) : JsExtensions { } } return chapter?.variableMap?.get(key) - ?: book?.variableMap?.get(key) - ?: ruleData.variableMap[key] - ?: "" + ?: book?.variableMap?.get(key) + ?: ruleData.variableMap[key] + ?: "" } /** @@ -678,7 +679,7 @@ class AnalyzeRule(val ruleData: RuleDataInterface) : JsExtensions { companion object { private val putPattern = Pattern.compile("@put:(\\{[^}]+?\\})", Pattern.CASE_INSENSITIVE) private val evalPattern = - Pattern.compile("@get:\\{[^}]+?\\}|\\{\\{[\\w\\W]*?\\}\\}", Pattern.CASE_INSENSITIVE) + Pattern.compile("@get:\\{[^}]+?\\}|\\{\\{[\\w\\W]*?\\}\\}", Pattern.CASE_INSENSITIVE) private val regexPattern = Pattern.compile("\\$\\d{1,2}") private val titleNumPattern = Pattern.compile("(第)(.+?)(章)") } 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 1ed802c6f..9dc1fcc72 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 @@ -55,7 +55,7 @@ class AnalyzeUrl( private var retry: Int = 0 init { - baseUrl = baseUrl.substringBefore(",{") + baseUrl = baseUrl.substringBefore(',') headerMapF?.let { headerMap.putAll(it) if (it.containsKey("proxy")) { diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt index 494f628a4..c58c38b9f 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt @@ -147,7 +147,7 @@ object ChapterProvider { return TextChapter( bookChapter.index, bookChapter.title, - bookChapter.getAbsoluteURL().substringBefore(",{"), + bookChapter.getAbsoluteURL().substringBefore(','), textPages, chapterSize ) }