|
|
|
@ -1,5 +1,6 @@ |
|
|
|
|
package io.legado.app.model.webBook |
|
|
|
|
|
|
|
|
|
import io.legado.app.constant.AppLog |
|
|
|
|
import io.legado.app.data.entities.Book |
|
|
|
|
import io.legado.app.data.entities.BookChapter |
|
|
|
|
import io.legado.app.data.entities.BookSource |
|
|
|
@ -9,6 +10,7 @@ import io.legado.app.help.book.getBookType |
|
|
|
|
import io.legado.app.help.coroutine.Coroutine |
|
|
|
|
import io.legado.app.help.http.StrResponse |
|
|
|
|
import io.legado.app.model.Debug |
|
|
|
|
import io.legado.app.model.analyzeRule.AnalyzeRule |
|
|
|
|
import io.legado.app.model.analyzeRule.AnalyzeUrl |
|
|
|
|
import io.legado.app.model.analyzeRule.RuleData |
|
|
|
|
import kotlinx.coroutines.CoroutineScope |
|
|
|
@ -179,19 +181,30 @@ object WebBook { |
|
|
|
|
scope: CoroutineScope, |
|
|
|
|
bookSource: BookSource, |
|
|
|
|
book: Book, |
|
|
|
|
runPerJs: Boolean = false, |
|
|
|
|
context: CoroutineContext = Dispatchers.IO |
|
|
|
|
): Coroutine<List<BookChapter>> { |
|
|
|
|
return Coroutine.async(scope, context) { |
|
|
|
|
getChapterListAwait(bookSource, book).getOrThrow() |
|
|
|
|
getChapterListAwait(bookSource, book, runPerJs).getOrThrow() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
suspend fun getChapterListAwait( |
|
|
|
|
bookSource: BookSource, |
|
|
|
|
book: Book, |
|
|
|
|
runPerJs: Boolean = false |
|
|
|
|
): Result<List<BookChapter>> { |
|
|
|
|
book.type = bookSource.getBookType() |
|
|
|
|
return kotlin.runCatching { |
|
|
|
|
val preUpdateJs = bookSource.ruleToc?.preUpdateJs |
|
|
|
|
if (runPerJs && !preUpdateJs.isNullOrBlank()) { |
|
|
|
|
kotlin.runCatching { |
|
|
|
|
AnalyzeRule(book, bookSource).evalJS(preUpdateJs) |
|
|
|
|
}.onFailure { |
|
|
|
|
AppLog.put("执行preUpdateJs规则失败 书源:${bookSource.bookSourceName}", it) |
|
|
|
|
throw it |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (book.bookUrl == book.tocUrl && !book.tocHtml.isNullOrEmpty()) { |
|
|
|
|
BookChapterList.analyzeChapterList( |
|
|
|
|
bookSource = bookSource, |
|
|
|
|