pull/967/head
gedoor 4 years ago
parent 7e92c0b2ee
commit 243027f4d5
  1. 39
      app/src/main/java/io/legado/app/model/webBook/BookContent.kt

@ -13,6 +13,8 @@ import io.legado.app.model.analyzeRule.AnalyzeUrl
import io.legado.app.utils.HtmlFormatter import io.legado.app.utils.HtmlFormatter
import io.legado.app.utils.NetworkUtils import io.legado.app.utils.NetworkUtils
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.async
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import splitties.init.appCtx import splitties.init.appCtx
@ -75,29 +77,26 @@ object BookContent {
} }
Debug.log(bookSource.bookSourceUrl, "◇本章总页数:${nextUrlList.size}") Debug.log(bookSource.bookSourceUrl, "◇本章总页数:${nextUrlList.size}")
} else if (contentData.nextUrl.size > 1) { } else if (contentData.nextUrl.size > 1) {
val contentDataList = arrayListOf<ContentData<String>>() Debug.log(bookSource.bookSourceUrl, "◇并发解析目录,总页数:${contentData.nextUrl.size}")
for (item in contentData.nextUrl) { withContext(IO) {
if (!nextUrlList.contains(item)) val asyncArray = Array(contentData.nextUrl.size) {
contentDataList.add(ContentData(nextUrl = item)) async(IO) {
} val urlStr = contentData.nextUrl[it]
for (item in contentDataList) { val analyzeUrl = AnalyzeUrl(
withContext(scope.coroutineContext) { ruleUrl = urlStr,
val res = AnalyzeUrl( book = book,
ruleUrl = item.nextUrl, headerMapF = bookSource.getHeaderMap()
book = book,
headerMapF = bookSource.getHeaderMap()
).getStrResponse(bookSource.bookSourceUrl)
res.body?.let { nextBody ->
contentData = analyzeContent(
book, item.nextUrl, res.url, nextBody, contentRule,
bookChapter, bookSource, mNextChapterUrl, false
) )
item.content = contentData.content val res = analyzeUrl.getStrResponse(bookSource.bookSourceUrl)
analyzeContent(
book, urlStr, res.url, res.body!!, contentRule,
bookChapter, bookSource, mNextChapterUrl, false
).content
} }
} }
} asyncArray.forEach { coroutine ->
for (item in contentDataList) { content.append(coroutine.await()).append("\n")
content.append(item.content).append("\n") }
} }
} }
content.deleteCharAt(content.length - 1) content.deleteCharAt(content.length - 1)

Loading…
Cancel
Save