pull/38/head
kunfei 5 years ago
parent 8ab80800cb
commit ff5db43db4
  1. 58
      app/src/main/java/io/legado/app/model/webbook/BookList.kt

@ -4,10 +4,12 @@ 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.help.BookHelp
import io.legado.app.model.analyzeRule.AnalyzeRule
import io.legado.app.model.analyzeRule.AnalyzeUrl
import io.legado.app.utils.NetworkUtils
import org.mozilla.javascript.NativeObject
import retrofit2.Response
object BookList {
@ -75,6 +77,15 @@ object BookList {
val ruleWordCount = analyzeRule.splitSourceRule(bookListRule.wordCount ?: "")
SourceDebug.printLog(bookSource.bookSourceUrl, "列表数为${collections.size}")
for ((index, item) in collections.withIndex()) {
if (item is NativeObject) {
getSearchItemAllInOne(
item,
bookSource,
bookListRule,
baseUrl,
index == 0
)
} else {
getSearchItem(
item,
analyzeRule,
@ -89,7 +100,8 @@ object BookList {
ruleKind = ruleKind,
ruleLastChapter = ruleLastChapter,
ruleWordCount = ruleWordCount
)?.let { searchBook ->
)
}?.let { searchBook ->
if (baseUrl == searchBook.bookUrl) {
searchBook.infoHtml = body
}
@ -202,4 +214,48 @@ object BookList {
}
return null
}
private fun getSearchItemAllInOne(
item: NativeObject,
bookSource: BookSource,
bookListRule: BookListRule,
baseUrl: String,
printLog: Boolean
): SearchBook? {
val searchBook = SearchBook()
searchBook.origin = bookSource.bookSourceUrl
searchBook.originName = bookSource.bookSourceName
searchBook.originOrder = bookSource.customOrder
SourceDebug.printLog(bookSource.bookSourceUrl, "获取书名", printLog)
searchBook.name = item[bookListRule.name]?.toString() ?: ""
SourceDebug.printLog(bookSource.bookSourceUrl, searchBook.name, printLog)
if (searchBook.name.isNotEmpty()) {
SourceDebug.printLog(bookSource.bookSourceUrl, "获取书籍Url", printLog)
searchBook.bookUrl = item[bookListRule.bookUrl]?.toString() ?: ""
if (searchBook.bookUrl.isEmpty()) {
searchBook.bookUrl = baseUrl
}
SourceDebug.printLog(bookSource.bookSourceUrl, searchBook.bookUrl, printLog)
SourceDebug.printLog(bookSource.bookSourceUrl, "获取作者", printLog)
searchBook.author = BookHelp.formatAuthor(item[bookListRule.author]?.toString() ?: "")
SourceDebug.printLog(bookSource.bookSourceUrl, searchBook.author, printLog)
SourceDebug.printLog(bookSource.bookSourceUrl, "获取分类", printLog)
searchBook.kind = item[bookListRule.kind]?.toString() ?: ""
SourceDebug.printLog(bookSource.bookSourceUrl, searchBook.kind, printLog)
SourceDebug.printLog(bookSource.bookSourceUrl, "获取简介", printLog)
searchBook.intro = item[bookListRule.intro]?.toString() ?: ""
SourceDebug.printLog(bookSource.bookSourceUrl, searchBook.intro, printLog, true)
SourceDebug.printLog(bookSource.bookSourceUrl, "获取字数", printLog)
searchBook.wordCount = item[bookListRule.wordCount]?.toString() ?: ""
SourceDebug.printLog(bookSource.bookSourceUrl, searchBook.wordCount, printLog)
SourceDebug.printLog(bookSource.bookSourceUrl, "获取封面Url", printLog)
searchBook.coverUrl = item[bookListRule.coverUrl]?.toString() ?: ""
SourceDebug.printLog(bookSource.bookSourceUrl, searchBook.coverUrl, printLog)
SourceDebug.printLog(bookSource.bookSourceUrl, "获取最新章节", printLog)
searchBook.latestChapterTitle = item[bookListRule.lastChapter]?.toString() ?: ""
SourceDebug.printLog(bookSource.bookSourceUrl, searchBook.latestChapterTitle, printLog)
return searchBook
}
return null
}
}
Loading…
Cancel
Save