From 48eed794e128695dba5ac06bb79cb3617ff737dc Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 26 Oct 2021 11:11:33 +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/model/analyzeRule/AnalyzeRule.kt | 28 +++++++++++-------- .../legado/app/model/rss/RssParserByRule.kt | 2 +- .../app/model/webBook/BookChapterList.kt | 2 +- .../legado/app/model/webBook/BookContent.kt | 4 +-- .../io/legado/app/model/webBook/BookInfo.kt | 2 +- .../io/legado/app/model/webBook/BookList.kt | 2 +- 6 files changed, 22 insertions(+), 18 deletions(-) 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 4837ffe7d..bf685944e 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 @@ -129,16 +129,20 @@ class AnalyzeRule( * 获取文本列表 */ @JvmOverloads - fun getStringList(rule: String?, isUrl: Boolean = false): List? { + fun getStringList(rule: String?, mContent: Any? = null, isUrl: Boolean = false): List? { if (rule.isNullOrEmpty()) return null val ruleList = splitSourceRule(rule, false) - return getStringList(ruleList, isUrl) + return getStringList(ruleList, mContent, isUrl) } @JvmOverloads - fun getStringList(ruleList: List, isUrl: Boolean = false): List? { + fun getStringList( + ruleList: List, + mContent: Any? = null, + isUrl: Boolean = false + ): List? { var result: Any? = null - val content = this.content + val content = mContent ?: this.content if (content != null && ruleList.isNotEmpty()) { result = content if (content is NativeObject) { @@ -194,22 +198,22 @@ class AnalyzeRule( * 获取文本 */ @JvmOverloads - fun getString(ruleStr: String?, isUrl: Boolean = false, value: String? = null): String { + fun getString(ruleStr: String?, mContent: Any? = null, isUrl: Boolean = false): String { if (TextUtils.isEmpty(ruleStr)) return "" val ruleList = splitSourceRule(ruleStr) - return getString(ruleList, isUrl, value) + return getString(ruleList, mContent, isUrl) } @JvmOverloads fun getString( ruleList: List, - isUrl: Boolean = false, - value: String? = null + mContent: Any? = null, + isUrl: Boolean = false ): String { - var result: Any? = value - val content = this.content - if ((content != null || result != null) && ruleList.isNotEmpty()) { - if (result == null) result = content + var result: Any? = null + val content = mContent ?: this.content + if (content != null && ruleList.isNotEmpty()) { + result = content if (result is NativeObject) { result = result[ruleList[0].rule]?.toString() } else { diff --git a/app/src/main/java/io/legado/app/model/rss/RssParserByRule.kt b/app/src/main/java/io/legado/app/model/rss/RssParserByRule.kt index 501d5007d..aabe26f98 100644 --- a/app/src/main/java/io/legado/app/model/rss/RssParserByRule.kt +++ b/app/src/main/java/io/legado/app/model/rss/RssParserByRule.kt @@ -112,7 +112,7 @@ object RssParserByRule { Debug.log(sourceUrl, "└${rssArticle.description}", log) } Debug.log(sourceUrl, "┌获取图片url", log) - rssArticle.image = analyzeRule.getString(ruleImage, true) + rssArticle.image = analyzeRule.getString(ruleImage, isUrl = true) Debug.log(sourceUrl, "└${rssArticle.image}", log) Debug.log(sourceUrl, "┌获取文章链接", log) rssArticle.link = NetworkUtils.getAbsoluteURL(sourceUrl, analyzeRule.getString(ruleLink)) diff --git a/app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt b/app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt index ee74215e6..db8a7c775 100644 --- a/app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt +++ b/app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt @@ -156,7 +156,7 @@ object BookChapterList { val nextTocRule = tocRule.nextTocUrl if (getNextUrl && !nextTocRule.isNullOrEmpty()) { Debug.log(bookSource.bookSourceUrl, "┌获取目录下一页列表", log) - analyzeRule.getStringList(nextTocRule, true)?.let { + analyzeRule.getStringList(nextTocRule, isUrl = true)?.let { for (item in it) { if (item != baseUrl) { nextUrlList.add(item) diff --git a/app/src/main/java/io/legado/app/model/webBook/BookContent.kt b/app/src/main/java/io/legado/app/model/webBook/BookContent.kt index e3ed695f0..c51a4e44e 100644 --- a/app/src/main/java/io/legado/app/model/webBook/BookContent.kt +++ b/app/src/main/java/io/legado/app/model/webBook/BookContent.kt @@ -112,7 +112,7 @@ object BookContent { var contentStr = content.toString() val replaceRegex = contentRule.replaceRegex if (!replaceRegex.isNullOrEmpty()) { - contentStr = analyzeRule.getString(replaceRegex, value = contentStr) + contentStr = analyzeRule.getString(replaceRegex, contentStr) } Debug.log(bookSource.bookSourceUrl, "┌获取章节名称") Debug.log(bookSource.bookSourceUrl, "└${bookChapter.title}") @@ -150,7 +150,7 @@ object BookContent { val nextUrlRule = contentRule.nextContentUrl if (!nextUrlRule.isNullOrEmpty()) { Debug.log(bookSource.bookSourceUrl, "┌获取正文下一页链接", printLog) - analyzeRule.getStringList(nextUrlRule, true)?.let { + analyzeRule.getStringList(nextUrlRule, isUrl = true)?.let { nextUrlList.addAll(it) } Debug.log(bookSource.bookSourceUrl, "└" + nextUrlList.joinToString(","), printLog) diff --git a/app/src/main/java/io/legado/app/model/webBook/BookInfo.kt b/app/src/main/java/io/legado/app/model/webBook/BookInfo.kt index 193a12339..ceb1b3b75 100644 --- a/app/src/main/java/io/legado/app/model/webBook/BookInfo.kt +++ b/app/src/main/java/io/legado/app/model/webBook/BookInfo.kt @@ -129,7 +129,7 @@ object BookInfo { } scope.ensureActive() Debug.log(bookSource.bookSourceUrl, "┌获取目录链接") - book.tocUrl = analyzeRule.getString(infoRule.tocUrl, true) + book.tocUrl = analyzeRule.getString(infoRule.tocUrl, isUrl = true) if (book.tocUrl.isEmpty()) book.tocUrl = redirectUrl if (book.tocUrl == redirectUrl) { book.tocHtml = body diff --git a/app/src/main/java/io/legado/app/model/webBook/BookList.kt b/app/src/main/java/io/legado/app/model/webBook/BookList.kt index e40501576..8bc9dacad 100644 --- a/app/src/main/java/io/legado/app/model/webBook/BookList.kt +++ b/app/src/main/java/io/legado/app/model/webBook/BookList.kt @@ -231,7 +231,7 @@ object BookList { } scope.ensureActive() Debug.log(bookSource.bookSourceUrl, "┌获取详情页链接", log) - searchBook.bookUrl = analyzeRule.getString(ruleBookUrl, true) + searchBook.bookUrl = analyzeRule.getString(ruleBookUrl, isUrl = true) if (searchBook.bookUrl.isEmpty()) { searchBook.bookUrl = baseUrl }