搜索跳到详情页时写入目录url

pull/873/head
gedoor 4 years ago
parent 54006c3831
commit 42e49452d7
  1. 16
      app/src/main/java/io/legado/app/model/webBook/BookInfo.kt
  2. 64
      app/src/main/java/io/legado/app/model/webBook/BookList.kt

@ -29,10 +29,22 @@ object BookInfo {
appCtx.getString(R.string.error_get_web_content, baseUrl) appCtx.getString(R.string.error_get_web_content, baseUrl)
) )
Debug.log(bookSource.bookSourceUrl, "≡获取成功:${baseUrl}") Debug.log(bookSource.bookSourceUrl, "≡获取成功:${baseUrl}")
val infoRule = bookSource.getBookInfoRule()
val analyzeRule = AnalyzeRule(book) val analyzeRule = AnalyzeRule(book)
analyzeRule.setContent(body).setBaseUrl(baseUrl) analyzeRule.setContent(body).setBaseUrl(baseUrl)
analyzeRule.setRedirectUrl(redirectUrl) analyzeRule.setRedirectUrl(redirectUrl)
analyzeBookInfo(scope, book, analyzeRule, bookSource, baseUrl, redirectUrl, canReName)
}
fun analyzeBookInfo(
scope: CoroutineScope,
book: Book,
analyzeRule: AnalyzeRule,
bookSource: BookSource,
baseUrl: String,
redirectUrl: String,
canReName: Boolean,
) {
val infoRule = bookSource.getBookInfoRule()
infoRule.init?.let { infoRule.init?.let {
if (it.isNotBlank()) { if (it.isNotBlank()) {
scope.ensureActive() scope.ensureActive()
@ -94,7 +106,7 @@ object BookInfo {
book.tocUrl = analyzeRule.getString(infoRule.tocUrl, true) book.tocUrl = analyzeRule.getString(infoRule.tocUrl, true)
if (book.tocUrl.isEmpty()) book.tocUrl = baseUrl if (book.tocUrl.isEmpty()) book.tocUrl = baseUrl
if (book.tocUrl == baseUrl) { if (book.tocUrl == baseUrl) {
book.tocHtml = body book.tocHtml = analyzeRule.content.toString()
} }
Debug.log(bookSource.bookSourceUrl, "${book.tocUrl}") Debug.log(bookSource.bookSourceUrl, "${book.tocUrl}")
} }

@ -1,6 +1,7 @@
package io.legado.app.model.webBook package io.legado.app.model.webBook
import io.legado.app.R import io.legado.app.R
import io.legado.app.data.entities.Book
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.data.entities.rule.BookListRule
@ -124,59 +125,16 @@ object BookList {
baseUrl: String, baseUrl: String,
variable: String? variable: String?
): SearchBook? { ): SearchBook? {
val searchBook = SearchBook(variable = variable) val book = Book(variable = variable)
searchBook.bookUrl = baseUrl book.bookUrl = baseUrl
searchBook.origin = bookSource.bookSourceUrl book.origin = bookSource.bookSourceUrl
searchBook.originName = bookSource.bookSourceName book.originName = bookSource.bookSourceName
searchBook.originOrder = bookSource.customOrder book.originOrder = bookSource.customOrder
searchBook.type = bookSource.bookSourceType book.type = bookSource.bookSourceType
analyzeRule.book = searchBook analyzeRule.book = book
with(bookSource.getBookInfoRule()) { BookInfo.analyzeBookInfo(scope, book, analyzeRule, bookSource, baseUrl, baseUrl, false)
init?.let { if (book.name.isNotBlank()) {
if (it.isNotEmpty()) { return book.toSearchBook()
scope.ensureActive()
Debug.log(bookSource.bookSourceUrl, "≡执行详情页初始化规则")
analyzeRule.setContent(analyzeRule.getElement(it))
}
}
scope.ensureActive()
Debug.log(bookSource.bookSourceUrl, "┌获取书名")
searchBook.name = BookHelp.formatBookName(analyzeRule.getString(name))
Debug.log(bookSource.bookSourceUrl, "${searchBook.name}")
if (searchBook.name.isNotEmpty()) {
scope.ensureActive()
Debug.log(bookSource.bookSourceUrl, "┌获取作者")
searchBook.author = BookHelp.formatBookAuthor(analyzeRule.getString(author))
Debug.log(bookSource.bookSourceUrl, "${searchBook.author}")
scope.ensureActive()
Debug.log(bookSource.bookSourceUrl, "┌获取分类")
searchBook.kind = analyzeRule.getStringList(kind)?.joinToString(",")
Debug.log(bookSource.bookSourceUrl, "${searchBook.kind}")
scope.ensureActive()
Debug.log(bookSource.bookSourceUrl, "┌获取字数")
searchBook.wordCount = wordCountFormat(analyzeRule.getString(wordCount))
Debug.log(bookSource.bookSourceUrl, "${searchBook.wordCount}")
scope.ensureActive()
Debug.log(bookSource.bookSourceUrl, "┌获取最新章节")
searchBook.latestChapterTitle = analyzeRule.getString(lastChapter)
Debug.log(bookSource.bookSourceUrl, "${searchBook.latestChapterTitle}")
scope.ensureActive()
Debug.log(bookSource.bookSourceUrl, "┌获取简介")
searchBook.intro = analyzeRule.getString(intro).htmlFormat()
Debug.log(bookSource.bookSourceUrl, "${searchBook.intro}")
scope.ensureActive()
Debug.log(bookSource.bookSourceUrl, "┌获取封面链接")
searchBook.coverUrl = analyzeRule.getString(coverUrl, true)
Debug.log(bookSource.bookSourceUrl, "${searchBook.coverUrl}")
Debug.log(bookSource.bookSourceUrl, "┌获取目录链接")
searchBook.tocUrl = analyzeRule.getString(tocUrl, true)
if (searchBook.tocUrl.isEmpty()) searchBook.tocUrl = baseUrl
if (searchBook.tocUrl == baseUrl) {
searchBook.tocHtml = analyzeRule.content.toString()
}
Debug.log(bookSource.bookSourceUrl, "${searchBook.tocUrl}")
return searchBook
}
} }
return null return null
} }

Loading…
Cancel
Save