pull/32/head
kunfei 5 years ago
parent 5696e8cbe9
commit 3aa6c3f945
  1. 6
      app/src/main/java/io/legado/app/model/webbook/BookChapterList.kt
  2. 12
      app/src/main/java/io/legado/app/model/webbook/BookContent.kt

@ -50,11 +50,7 @@ object BookChapterList {
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)
nextUrl = if (chapterData.nextUrl.isEmpty()) { nextUrl = if (chapterData.nextUrl.isNotEmpty()) chapterData.nextUrl[0] else ""
""
} else {
chapterData.nextUrl[0]
}
chapterData.chapterList?.let { chapterData.chapterList?.let {
chapterList.addAll(it) chapterList.addAll(it)
} }

@ -31,27 +31,29 @@ object BookContent {
baseUrl baseUrl
) )
) )
val content = StringBuilder()
val nextUrlList = arrayListOf(baseUrl) val nextUrlList = arrayListOf(baseUrl)
val contentRule = bookSource.getContentRule() val contentRule = bookSource.getContentRule()
var contentData = analyzeContent(body, contentRule, book, baseUrl) var contentData = analyzeContent(body, contentRule, book, baseUrl)
var content = contentData.content content.append(contentData.content)
if (contentData.nextUrl.size == 1) { if (contentData.nextUrl.size == 1) {
var nextUrl = contentData.nextUrl[0] var nextUrl = contentData.nextUrl[0]
while (nextUrl.isNotEmpty() && !nextUrlList.contains(nextUrl)) { while (nextUrl.isNotEmpty() && !nextUrlList.contains(nextUrl)) {
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 ->
analyzeContent(nextBody, contentRule, book, baseUrl) contentData = analyzeContent(nextBody, contentRule, book, baseUrl)
nextUrl = if (contentData.nextUrl.isNotEmpty()) contentData.nextUrl[0] else ""
content.append(contentData.content)
} }
} }
} else if (contentData.nextUrl.size > 1) { } else if (contentData.nextUrl.size > 1) {
} }
return content return content.toString()
} }
fun analyzeContent( private fun analyzeContent(
body: String, body: String,
contentRule: ContentRule, contentRule: ContentRule,
book: Book, book: Book,

Loading…
Cancel
Save