This commit is contained in:
Horis
2024-09-20 18:07:52 +08:00
parent 7dba21affc
commit 38cecec4ad
3 changed files with 12 additions and 4 deletions

View File

@@ -154,7 +154,8 @@ object BookHelp {
bookSource: BookSource,
book: Book,
bookChapter: BookChapter,
content: String
content: String,
concurrency: Int = AppConfig.threadCount
) = coroutineScope {
flow {
val matcher = AppPattern.imgPattern.matcher(content)
@@ -163,7 +164,7 @@ object BookHelp {
val mSrc = NetworkUtils.getAbsoluteURL(bookChapter.url, src)
emit(mSrc)
}
}.onEachParallel(AppConfig.threadCount) { mSrc ->
}.onEachParallel(concurrency) { mSrc ->
saveImage(bookSource, book, mSrc, bookChapter)
}.collect()
}

View File

@@ -269,7 +269,7 @@ object CacheBook {
if (BookHelp.hasContent(book, chapter)) {
Coroutine.async(executeContext = context) {
BookHelp.getContent(book, chapter)?.let {
BookHelp.saveImages(bookSource, book, chapter, it)
BookHelp.saveImages(bookSource, book, chapter, it, 1)
}
}.onSuccess {
onSuccess(chapter)

View File

@@ -27,6 +27,8 @@ import io.legado.app.utils.fastSum
import io.legado.app.utils.splitNotBlank
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.CoroutineStart
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.ensureActive
import kotlinx.coroutines.launch
@@ -83,7 +85,11 @@ class TextChapterLayout(
var channel = Channel<TextPage>(Int.MAX_VALUE)
init {
job = Coroutine.async(scope) {
job = Coroutine.async(
scope,
start = CoroutineStart.LAZY,
executeContext = IO
) {
launch {
val bookSource = book.getBookSource() ?: return@launch
BookHelp.saveImages(bookSource, book, bookChapter, bookContent.toString())
@@ -95,6 +101,7 @@ class TextChapterLayout(
}.onFinally {
isCompleted = true
}
job.start()
}
fun setProgressListener(l: LayoutProgressListener?) {