列表规则可以put变量

pull/298/head
gedoor 4 years ago
parent bdb6f4720d
commit f6dc8bf9fd
  1. 36
      app/src/main/java/io/legado/app/model/webBook/BookList.kt

@ -34,12 +34,14 @@ object BookList {
) )
Debug.log(bookSource.bookSourceUrl, "≡获取成功:${analyzeUrl.ruleUrl}") Debug.log(bookSource.bookSourceUrl, "≡获取成功:${analyzeUrl.ruleUrl}")
if (!scope.isActive) throw CancellationException() if (!scope.isActive) throw CancellationException()
val analyzeRule = AnalyzeRule(null) val variableBook = SearchBook()
val analyzeRule = AnalyzeRule(variableBook)
analyzeRule.setContent(body, baseUrl) analyzeRule.setContent(body, baseUrl)
bookSource.bookUrlPattern?.let { bookSource.bookUrlPattern?.let {
if (baseUrl.matches(it.toRegex())) { if (baseUrl.matches(it.toRegex())) {
Debug.log(bookSource.bookSourceUrl, "≡链接为详情页") Debug.log(bookSource.bookSourceUrl, "≡链接为详情页")
getInfoItem(scope, analyzeRule, bookSource, baseUrl)?.let { searchBook -> getInfoItem(scope, analyzeRule, bookSource, baseUrl, variableBook.variable)
?.let { searchBook ->
searchBook.infoHtml = body searchBook.infoHtml = body
bookList.add(searchBook) bookList.add(searchBook)
} }
@ -65,7 +67,8 @@ object BookList {
collections = analyzeRule.getElements(ruleList) collections = analyzeRule.getElements(ruleList)
if (collections.isEmpty() && bookSource.bookUrlPattern.isNullOrEmpty()) { if (collections.isEmpty() && bookSource.bookUrlPattern.isNullOrEmpty()) {
Debug.log(bookSource.bookSourceUrl, "└列表为空,按详情页解析") Debug.log(bookSource.bookSourceUrl, "└列表为空,按详情页解析")
getInfoItem(scope, analyzeRule, bookSource, baseUrl)?.let { searchBook -> getInfoItem(scope, analyzeRule, bookSource, baseUrl, variableBook.variable)
?.let { searchBook ->
searchBook.infoHtml = body searchBook.infoHtml = body
bookList.add(searchBook) bookList.add(searchBook)
} }
@ -82,10 +85,21 @@ object BookList {
for ((index, item) in collections.withIndex()) { for ((index, item) in collections.withIndex()) {
if (!scope.isActive) throw CancellationException() if (!scope.isActive) throw CancellationException()
getSearchItem( getSearchItem(
scope, item, analyzeRule, bookSource, baseUrl, index == 0, scope,
ruleName = ruleName, ruleBookUrl = ruleBookUrl, ruleAuthor = ruleAuthor, item,
ruleCoverUrl = ruleCoverUrl, ruleIntro = ruleIntro, ruleKind = ruleKind, analyzeRule,
ruleLastChapter = ruleLastChapter, ruleWordCount = ruleWordCount bookSource,
baseUrl,
variableBook.variable,
index == 0,
ruleName = ruleName,
ruleBookUrl = ruleBookUrl,
ruleAuthor = ruleAuthor,
ruleCoverUrl = ruleCoverUrl,
ruleIntro = ruleIntro,
ruleKind = ruleKind,
ruleLastChapter = ruleLastChapter,
ruleWordCount = ruleWordCount
)?.let { searchBook -> )?.let { searchBook ->
if (baseUrl == searchBook.bookUrl) { if (baseUrl == searchBook.bookUrl) {
searchBook.infoHtml = body searchBook.infoHtml = body
@ -105,9 +119,10 @@ object BookList {
scope: CoroutineScope, scope: CoroutineScope,
analyzeRule: AnalyzeRule, analyzeRule: AnalyzeRule,
bookSource: BookSource, bookSource: BookSource,
baseUrl: String baseUrl: String,
variable: String?
): SearchBook? { ): SearchBook? {
val searchBook = SearchBook() val searchBook = SearchBook(variable = variable)
searchBook.bookUrl = baseUrl searchBook.bookUrl = baseUrl
searchBook.origin = bookSource.bookSourceUrl searchBook.origin = bookSource.bookSourceUrl
searchBook.originName = bookSource.bookSourceName searchBook.originName = bookSource.bookSourceName
@ -164,6 +179,7 @@ object BookList {
analyzeRule: AnalyzeRule, analyzeRule: AnalyzeRule,
bookSource: BookSource, bookSource: BookSource,
baseUrl: String, baseUrl: String,
variable: String?,
log: Boolean, log: Boolean,
ruleName: List<AnalyzeRule.SourceRule>, ruleName: List<AnalyzeRule.SourceRule>,
ruleBookUrl: List<AnalyzeRule.SourceRule>, ruleBookUrl: List<AnalyzeRule.SourceRule>,
@ -174,7 +190,7 @@ object BookList {
ruleIntro: List<AnalyzeRule.SourceRule>, ruleIntro: List<AnalyzeRule.SourceRule>,
ruleLastChapter: List<AnalyzeRule.SourceRule> ruleLastChapter: List<AnalyzeRule.SourceRule>
): SearchBook? { ): SearchBook? {
val searchBook = SearchBook() val searchBook = SearchBook(variable = variable)
searchBook.origin = bookSource.bookSourceUrl searchBook.origin = bookSource.bookSourceUrl
searchBook.originName = bookSource.bookSourceName searchBook.originName = bookSource.bookSourceName
searchBook.type = bookSource.bookSourceType searchBook.type = bookSource.bookSourceType

Loading…
Cancel
Save