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 7924e4eed..cfb01612b 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 @@ -20,8 +20,9 @@ import javax.script.SimpleBindings @Keep class AnalyzeRule(private var book: BaseBook? = null) { private var content: Any? = null - private var isJSON: Boolean = false private var baseUrl: String? = null + private var isJSON: Boolean = false + private var isRegex: Boolean = false private var analyzeByXPath: AnalyzeByXPath? = null private var analyzeByJSoup: AnalyzeByJSoup? = null @@ -161,6 +162,7 @@ class AnalyzeRule(private var book: BaseBook? = null) { return urlList } } + @Suppress("UNCHECKED_CAST") return result as? List } 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 031062044..27749f4f9 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 @@ -4,7 +4,6 @@ import io.legado.app.App import io.legado.app.R import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.SearchBook -import io.legado.app.data.entities.rule.BookListRule import io.legado.app.model.analyzeRule.AnalyzeRule import io.legado.app.model.analyzeRule.AnalyzeUrl import io.legado.app.utils.NetworkUtils @@ -28,11 +27,11 @@ object BookList { baseUrl ) ) - val analyzer = AnalyzeRule(null) - analyzer.setContent(body, baseUrl) + val analyzeRule = AnalyzeRule(null) + analyzeRule.setContent(body, baseUrl) bookSource.bookUrlPattern?.let { if (baseUrl.matches(it.toRegex())) { - getInfoItem(analyzer, bookSource, baseUrl)?.let { searchBook -> + getInfoItem(analyzeRule, bookSource, baseUrl)?.let { searchBook -> searchBook.bookInfoHtml = body bookList.add(searchBook) } @@ -47,15 +46,34 @@ object BookList { reverse = true ruleList = ruleList.substring(1) } - collections = analyzer.getElements(ruleList) + collections = analyzeRule.getElements(ruleList) if (collections.isEmpty() && bookSource.bookUrlPattern.isNullOrEmpty()) { - getInfoItem(analyzer, bookSource, baseUrl)?.let { searchBook -> + getInfoItem(analyzeRule, bookSource, baseUrl)?.let { searchBook -> searchBook.bookInfoHtml = body bookList.add(searchBook) } } else { + val ruleName = analyzeRule.splitSourceRule(bookListRule.name ?: "") + val ruleAuthor = analyzeRule.splitSourceRule(bookListRule.author ?: "") + val ruleCoverUrl = analyzeRule.splitSourceRule(bookListRule.coverUrl ?: "") + val ruleIntro = analyzeRule.splitSourceRule(bookListRule.intro ?: "") + val ruleKind = analyzeRule.splitSourceRule(bookListRule.kind ?: "") + val ruleLastChapter = analyzeRule.splitSourceRule(bookListRule.lastChapter ?: "") + val ruleWordCount = analyzeRule.splitSourceRule(bookListRule.wordCount ?: "") for (item in collections) { - getSearchItem(item, analyzer, bookListRule, bookSource, baseUrl)?.let { searchBook -> + getSearchItem( + item, + analyzeRule, + bookSource, + baseUrl, + ruleName = ruleName, + ruleAuthor = ruleAuthor, + ruleCoverUrl = ruleCoverUrl, + ruleIntro = ruleIntro, + ruleKind = ruleKind, + ruleLastChapter = ruleLastChapter, + ruleWordCount = ruleWordCount + )?.let { searchBook -> if (baseUrl == searchBook.bookUrl) { searchBook.bookInfoHtml = body } @@ -97,22 +115,29 @@ object BookList { private fun getSearchItem( item: Any, analyzeRule: AnalyzeRule, - bookListRule: BookListRule, bookSource: BookSource, - baseUrl: String + baseUrl: String, + ruleName: List, + ruleAuthor: List, + ruleKind: List, + ruleCoverUrl: List, + ruleWordCount: List, + ruleIntro: List, + ruleLastChapter: List ): SearchBook? { val searchBook = SearchBook() searchBook.origin = bookSource.bookSourceUrl searchBook.originName = bookSource.bookSourceName analyzeRule.setBook(searchBook) analyzeRule.setContent(item) - searchBook.name = analyzeRule.getString(bookListRule.name ?: "") + searchBook.name = analyzeRule.getString(ruleName) searchBook.name?.let { - searchBook.author = analyzeRule.getString(bookListRule.author ?: "") - searchBook.kind = analyzeRule.getString(bookListRule.kind ?: "") - searchBook.intro = analyzeRule.getString(bookListRule.intro ?: "") - searchBook.wordCount = analyzeRule.getString(bookListRule.wordCount ?: "") - + searchBook.author = analyzeRule.getString(ruleAuthor) + searchBook.kind = analyzeRule.getString(ruleKind) + searchBook.intro = analyzeRule.getString(ruleIntro) + searchBook.wordCount = analyzeRule.getString(ruleWordCount) + searchBook.coverUrl = analyzeRule.getString(ruleCoverUrl) + searchBook.latestChapterTitle = analyzeRule.getString(ruleLastChapter) return searchBook } return null