pull/32/head
kunfei 5 years ago
parent 221d9db64c
commit 229fb9da7f
  1. 4
      app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt
  2. 55
      app/src/main/java/io/legado/app/model/webbook/BookList.kt

@ -20,8 +20,9 @@ import javax.script.SimpleBindings
@Keep @Keep
class AnalyzeRule(private var book: BaseBook? = null) { class AnalyzeRule(private var book: BaseBook? = null) {
private var content: Any? = null private var content: Any? = null
private var isJSON: Boolean = false
private var baseUrl: String? = null private var baseUrl: String? = null
private var isJSON: Boolean = false
private var isRegex: Boolean = false
private var analyzeByXPath: AnalyzeByXPath? = null private var analyzeByXPath: AnalyzeByXPath? = null
private var analyzeByJSoup: AnalyzeByJSoup? = null private var analyzeByJSoup: AnalyzeByJSoup? = null
@ -161,6 +162,7 @@ class AnalyzeRule(private var book: BaseBook? = null) {
return urlList return urlList
} }
} }
@Suppress("UNCHECKED_CAST")
return result as? List<String> return result as? List<String>
} }

@ -4,7 +4,6 @@ import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.BookSource
import io.legado.app.data.entities.SearchBook 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.AnalyzeRule
import io.legado.app.model.analyzeRule.AnalyzeUrl import io.legado.app.model.analyzeRule.AnalyzeUrl
import io.legado.app.utils.NetworkUtils import io.legado.app.utils.NetworkUtils
@ -28,11 +27,11 @@ object BookList {
baseUrl baseUrl
) )
) )
val analyzer = AnalyzeRule(null) val analyzeRule = AnalyzeRule(null)
analyzer.setContent(body, baseUrl) analyzeRule.setContent(body, baseUrl)
bookSource.bookUrlPattern?.let { bookSource.bookUrlPattern?.let {
if (baseUrl.matches(it.toRegex())) { if (baseUrl.matches(it.toRegex())) {
getInfoItem(analyzer, bookSource, baseUrl)?.let { searchBook -> getInfoItem(analyzeRule, bookSource, baseUrl)?.let { searchBook ->
searchBook.bookInfoHtml = body searchBook.bookInfoHtml = body
bookList.add(searchBook) bookList.add(searchBook)
} }
@ -47,15 +46,34 @@ object BookList {
reverse = true reverse = true
ruleList = ruleList.substring(1) ruleList = ruleList.substring(1)
} }
collections = analyzer.getElements(ruleList) collections = analyzeRule.getElements(ruleList)
if (collections.isEmpty() && bookSource.bookUrlPattern.isNullOrEmpty()) { if (collections.isEmpty() && bookSource.bookUrlPattern.isNullOrEmpty()) {
getInfoItem(analyzer, bookSource, baseUrl)?.let { searchBook -> getInfoItem(analyzeRule, bookSource, baseUrl)?.let { searchBook ->
searchBook.bookInfoHtml = body searchBook.bookInfoHtml = body
bookList.add(searchBook) bookList.add(searchBook)
} }
} else { } 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) { 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) { if (baseUrl == searchBook.bookUrl) {
searchBook.bookInfoHtml = body searchBook.bookInfoHtml = body
} }
@ -97,22 +115,29 @@ object BookList {
private fun getSearchItem( private fun getSearchItem(
item: Any, item: Any,
analyzeRule: AnalyzeRule, analyzeRule: AnalyzeRule,
bookListRule: BookListRule,
bookSource: BookSource, bookSource: BookSource,
baseUrl: String baseUrl: String,
ruleName: List<AnalyzeRule.SourceRule>,
ruleAuthor: List<AnalyzeRule.SourceRule>,
ruleKind: List<AnalyzeRule.SourceRule>,
ruleCoverUrl: List<AnalyzeRule.SourceRule>,
ruleWordCount: List<AnalyzeRule.SourceRule>,
ruleIntro: List<AnalyzeRule.SourceRule>,
ruleLastChapter: List<AnalyzeRule.SourceRule>
): SearchBook? { ): SearchBook? {
val searchBook = SearchBook() val searchBook = SearchBook()
searchBook.origin = bookSource.bookSourceUrl searchBook.origin = bookSource.bookSourceUrl
searchBook.originName = bookSource.bookSourceName searchBook.originName = bookSource.bookSourceName
analyzeRule.setBook(searchBook) analyzeRule.setBook(searchBook)
analyzeRule.setContent(item) analyzeRule.setContent(item)
searchBook.name = analyzeRule.getString(bookListRule.name ?: "") searchBook.name = analyzeRule.getString(ruleName)
searchBook.name?.let { searchBook.name?.let {
searchBook.author = analyzeRule.getString(bookListRule.author ?: "") searchBook.author = analyzeRule.getString(ruleAuthor)
searchBook.kind = analyzeRule.getString(bookListRule.kind ?: "") searchBook.kind = analyzeRule.getString(ruleKind)
searchBook.intro = analyzeRule.getString(bookListRule.intro ?: "") searchBook.intro = analyzeRule.getString(ruleIntro)
searchBook.wordCount = analyzeRule.getString(bookListRule.wordCount ?: "") searchBook.wordCount = analyzeRule.getString(ruleWordCount)
searchBook.coverUrl = analyzeRule.getString(ruleCoverUrl)
searchBook.latestChapterTitle = analyzeRule.getString(ruleLastChapter)
return searchBook return searchBook
} }
return null return null

Loading…
Cancel
Save