mirror of
https://github.com/gedoor/legado.git
synced 2024-07-06 23:47:49 +08:00
优化
This commit is contained in:
parent
ae1558c029
commit
a0bcec6a15
@ -17,10 +17,8 @@ import io.legado.app.model.analyzeRule.AnalyzeRule
|
||||
import io.legado.app.model.analyzeRule.AnalyzeUrl
|
||||
import io.legado.app.utils.isTrue
|
||||
import io.legado.app.utils.mapAsync
|
||||
import kotlinx.coroutines.Dispatchers.IO
|
||||
import kotlinx.coroutines.ensureActive
|
||||
import kotlinx.coroutines.flow.flow
|
||||
import kotlinx.coroutines.withContext
|
||||
import splitties.init.appCtx
|
||||
import kotlin.coroutines.coroutineContext
|
||||
|
||||
@ -88,25 +86,23 @@ object BookChapterList {
|
||||
bookSource.bookSourceUrl,
|
||||
"◇并发解析目录,总页数:${chapterData.second.size}"
|
||||
)
|
||||
withContext(IO) {
|
||||
flow {
|
||||
for (urlStr in chapterData.second) {
|
||||
emit(urlStr)
|
||||
}
|
||||
}.mapAsync(AppConfig.threadCount) { urlStr ->
|
||||
val res = AnalyzeUrl(
|
||||
mUrl = urlStr,
|
||||
source = bookSource,
|
||||
ruleData = book,
|
||||
headerMapF = bookSource.getHeaderMap()
|
||||
).getStrResponseAwait() //控制并发访问
|
||||
analyzeChapterList(
|
||||
book, urlStr, res.url,
|
||||
res.body!!, tocRule, listRule, bookSource, false
|
||||
).first
|
||||
}.collect {
|
||||
chapterList.addAll(it)
|
||||
flow {
|
||||
for (urlStr in chapterData.second) {
|
||||
emit(urlStr)
|
||||
}
|
||||
}.mapAsync(AppConfig.threadCount) { urlStr ->
|
||||
val res = AnalyzeUrl(
|
||||
mUrl = urlStr,
|
||||
source = bookSource,
|
||||
ruleData = book,
|
||||
headerMapF = bookSource.getHeaderMap()
|
||||
).getStrResponseAwait() //控制并发访问
|
||||
analyzeChapterList(
|
||||
book, urlStr, res.url,
|
||||
res.body!!, tocRule, listRule, bookSource, false
|
||||
).first
|
||||
}.collect {
|
||||
chapterList.addAll(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,11 +16,9 @@ import io.legado.app.model.analyzeRule.AnalyzeUrl
|
||||
import io.legado.app.utils.HtmlFormatter
|
||||
import io.legado.app.utils.NetworkUtils
|
||||
import io.legado.app.utils.mapAsync
|
||||
import kotlinx.coroutines.Dispatchers.IO
|
||||
import kotlinx.coroutines.currentCoroutineContext
|
||||
import kotlinx.coroutines.ensureActive
|
||||
import kotlinx.coroutines.flow.flow
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.apache.commons.text.StringEscapeUtils
|
||||
import splitties.init.appCtx
|
||||
import kotlin.coroutines.coroutineContext
|
||||
@ -107,28 +105,26 @@ object BookContent {
|
||||
Debug.log(bookSource.bookSourceUrl, "◇本章总页数:${nextUrlList.size}")
|
||||
} else if (contentData.second.size > 1) {
|
||||
Debug.log(bookSource.bookSourceUrl, "◇并发解析正文,总页数:${contentData.second.size}")
|
||||
withContext(IO) {
|
||||
flow {
|
||||
for (urlStr in contentData.second) {
|
||||
emit(urlStr)
|
||||
}
|
||||
}.mapAsync(AppConfig.threadCount) { urlStr ->
|
||||
val res = AnalyzeUrl(
|
||||
mUrl = urlStr,
|
||||
source = bookSource,
|
||||
ruleData = book,
|
||||
headerMapF = bookSource.getHeaderMap()
|
||||
).getStrResponseAwait() //控制并发访问
|
||||
analyzeContent(
|
||||
book, urlStr, res.url, res.body!!, contentRule,
|
||||
bookChapter, bookSource, mNextChapterUrl,
|
||||
getNextPageUrl = false,
|
||||
printLog = false
|
||||
).first
|
||||
}.collect {
|
||||
currentCoroutineContext().ensureActive()
|
||||
contentList.add(it)
|
||||
flow {
|
||||
for (urlStr in contentData.second) {
|
||||
emit(urlStr)
|
||||
}
|
||||
}.mapAsync(AppConfig.threadCount) { urlStr ->
|
||||
val res = AnalyzeUrl(
|
||||
mUrl = urlStr,
|
||||
source = bookSource,
|
||||
ruleData = book,
|
||||
headerMapF = bookSource.getHeaderMap()
|
||||
).getStrResponseAwait() //控制并发访问
|
||||
analyzeContent(
|
||||
book, urlStr, res.url, res.body!!, contentRule,
|
||||
bookChapter, bookSource, mNextChapterUrl,
|
||||
getNextPageUrl = false,
|
||||
printLog = false
|
||||
).first
|
||||
}.collect {
|
||||
currentCoroutineContext().ensureActive()
|
||||
contentList.add(it)
|
||||
}
|
||||
}
|
||||
var contentStr = contentList.joinToString("\n")
|
||||
|
Loading…
Reference in New Issue
Block a user