From f6dc8bf9fd6291af5683aaaa7838036a725ef025 Mon Sep 17 00:00:00 2001 From: gedoor Date: Fri, 7 Aug 2020 11:53:01 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=97=E8=A1=A8=E8=A7=84=E5=88=99=E5=8F=AF?= =?UTF-8?q?=E4=BB=A5put=E5=8F=98=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/model/webBook/BookList.kt | 48 ++++++++++++------- 1 file changed, 32 insertions(+), 16 deletions(-) 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 162db6dd0..8c988f081 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 @@ -34,15 +34,17 @@ object BookList { ) Debug.log(bookSource.bookSourceUrl, "≡获取成功:${analyzeUrl.ruleUrl}") if (!scope.isActive) throw CancellationException() - val analyzeRule = AnalyzeRule(null) + val variableBook = SearchBook() + val analyzeRule = AnalyzeRule(variableBook) analyzeRule.setContent(body, baseUrl) bookSource.bookUrlPattern?.let { if (baseUrl.matches(it.toRegex())) { Debug.log(bookSource.bookSourceUrl, "≡链接为详情页") - getInfoItem(scope, analyzeRule, bookSource, baseUrl)?.let { searchBook -> - searchBook.infoHtml = body - bookList.add(searchBook) - } + getInfoItem(scope, analyzeRule, bookSource, baseUrl, variableBook.variable) + ?.let { searchBook -> + searchBook.infoHtml = body + bookList.add(searchBook) + } return bookList } } @@ -65,10 +67,11 @@ object BookList { collections = analyzeRule.getElements(ruleList) if (collections.isEmpty() && bookSource.bookUrlPattern.isNullOrEmpty()) { Debug.log(bookSource.bookSourceUrl, "└列表为空,按详情页解析") - getInfoItem(scope, analyzeRule, bookSource, baseUrl)?.let { searchBook -> - searchBook.infoHtml = body - bookList.add(searchBook) - } + getInfoItem(scope, analyzeRule, bookSource, baseUrl, variableBook.variable) + ?.let { searchBook -> + searchBook.infoHtml = body + bookList.add(searchBook) + } } else { val ruleName = analyzeRule.splitSourceRule(bookListRule.name) val ruleBookUrl = analyzeRule.splitSourceRule(bookListRule.bookUrl) @@ -82,10 +85,21 @@ object BookList { for ((index, item) in collections.withIndex()) { if (!scope.isActive) throw CancellationException() getSearchItem( - scope, item, analyzeRule, bookSource, baseUrl, index == 0, - ruleName = ruleName, ruleBookUrl = ruleBookUrl, ruleAuthor = ruleAuthor, - ruleCoverUrl = ruleCoverUrl, ruleIntro = ruleIntro, ruleKind = ruleKind, - ruleLastChapter = ruleLastChapter, ruleWordCount = ruleWordCount + scope, + item, + analyzeRule, + bookSource, + baseUrl, + variableBook.variable, + index == 0, + ruleName = ruleName, + ruleBookUrl = ruleBookUrl, + ruleAuthor = ruleAuthor, + ruleCoverUrl = ruleCoverUrl, + ruleIntro = ruleIntro, + ruleKind = ruleKind, + ruleLastChapter = ruleLastChapter, + ruleWordCount = ruleWordCount )?.let { searchBook -> if (baseUrl == searchBook.bookUrl) { searchBook.infoHtml = body @@ -105,9 +119,10 @@ object BookList { scope: CoroutineScope, analyzeRule: AnalyzeRule, bookSource: BookSource, - baseUrl: String + baseUrl: String, + variable: String? ): SearchBook? { - val searchBook = SearchBook() + val searchBook = SearchBook(variable = variable) searchBook.bookUrl = baseUrl searchBook.origin = bookSource.bookSourceUrl searchBook.originName = bookSource.bookSourceName @@ -164,6 +179,7 @@ object BookList { analyzeRule: AnalyzeRule, bookSource: BookSource, baseUrl: String, + variable: String?, log: Boolean, ruleName: List, ruleBookUrl: List, @@ -174,7 +190,7 @@ object BookList { ruleIntro: List, ruleLastChapter: List ): SearchBook? { - val searchBook = SearchBook() + val searchBook = SearchBook(variable = variable) searchBook.origin = bookSource.bookSourceUrl searchBook.originName = bookSource.bookSourceName searchBook.type = bookSource.bookSourceType