pull/32/head
kunfei 5 years ago
parent 3328980791
commit d6a09e04da
  1. 26
      app/src/main/java/io/legado/app/model/webbook/BookChapterList.kt

@ -1,5 +1,6 @@
package io.legado.app.model.webbook package io.legado.app.model.webbook
import android.text.TextUtils
import io.legado.app.App import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.data.entities.Book import io.legado.app.data.entities.Book
@ -40,7 +41,7 @@ object BookChapterList {
reverse = true reverse = true
listRule = listRule.substring(1) listRule = listRule.substring(1)
} }
var chapterData = analyzeChapterList(body, baseUrl, tocRule, listRule, book) var chapterData = analyzeChapterList(body, baseUrl, tocRule, listRule, book, bookSource, printLog = true)
chapterData.chapterList?.let { chapterData.chapterList?.let {
chapterList.addAll(it) chapterList.addAll(it)
} }
@ -50,7 +51,7 @@ object BookChapterList {
nextUrlList.add(nextUrl) nextUrlList.add(nextUrl)
AnalyzeUrl(ruleUrl = nextUrl, book = book).getResponse().execute() AnalyzeUrl(ruleUrl = nextUrl, book = book).getResponse().execute()
.body()?.let { nextBody -> .body()?.let { nextBody ->
chapterData = analyzeChapterList(nextBody, nextUrl, tocRule, listRule, book) chapterData = analyzeChapterList(nextBody, nextUrl, tocRule, listRule, book, bookSource)
nextUrl = if (chapterData.nextUrl.isNotEmpty()) chapterData.nextUrl[0] else "" nextUrl = if (chapterData.nextUrl.isNotEmpty()) chapterData.nextUrl[0] else ""
chapterData.chapterList?.let { chapterData.chapterList?.let {
chapterList.addAll(it) chapterList.addAll(it)
@ -72,7 +73,9 @@ object BookChapterList {
item.nextUrl, item.nextUrl,
tocRule, tocRule,
listRule, listRule,
book book,
bookSource,
getNextUrl = false
) )
item.chapterList = nextChapterData.chapterList item.chapterList = nextChapterData.chapterList
} }
@ -93,14 +96,25 @@ object BookChapterList {
baseUrl: String, baseUrl: String,
tocRule: TocRule, tocRule: TocRule,
listRule: String, listRule: String,
book: Book book: Book,
bookSource: BookSource,
getNextUrl: Boolean = true,
printLog: Boolean = false
): ChapterData<List<String>> { ): ChapterData<List<String>> {
val chapterList = arrayListOf<BookChapter>() val chapterList = arrayListOf<BookChapter>()
val nextUrlList = arrayListOf<String>() val nextUrlList = arrayListOf<String>()
val analyzeRule = AnalyzeRule(book) val analyzeRule = AnalyzeRule(book)
analyzeRule.setContent(body, baseUrl) analyzeRule.setContent(body, baseUrl)
analyzeRule.getStringList(tocRule.nextTocUrl ?: "", true)?.let { if (getNextUrl) {
nextUrlList.addAll(it) SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取目录下一页列表", printLog)
analyzeRule.getStringList(tocRule.nextTocUrl ?: "", true)?.let {
for (item in it) {
if (item != baseUrl) {
nextUrlList.add(item)
}
}
}
SourceDebug.printLog(bookSource.bookSourceUrl, 1, TextUtils.join(",", nextUrlList), printLog)
} }
val elements = analyzeRule.getElements(listRule) val elements = analyzeRule.getElements(listRule)
if (elements.isNotEmpty()) { if (elements.isNotEmpty()) {

Loading…
Cancel
Save