|
@@ -19,7 +19,7 @@ import io.legado.app.model.analyzeRule.RuleData
|
|
|
import kotlinx.coroutines.CoroutineScope
|
|
import kotlinx.coroutines.CoroutineScope
|
|
|
import kotlinx.coroutines.CoroutineStart
|
|
import kotlinx.coroutines.CoroutineStart
|
|
|
import kotlinx.coroutines.Dispatchers
|
|
import kotlinx.coroutines.Dispatchers
|
|
|
-import kotlinx.coroutines.isActive
|
|
|
|
|
|
|
+import kotlinx.coroutines.ensureActive
|
|
|
import kotlinx.coroutines.sync.Semaphore
|
|
import kotlinx.coroutines.sync.Semaphore
|
|
|
import kotlinx.coroutines.sync.withPermit
|
|
import kotlinx.coroutines.sync.withPermit
|
|
|
import kotlin.coroutines.CoroutineContext
|
|
import kotlin.coroutines.CoroutineContext
|
|
@@ -363,7 +363,7 @@ object WebBook {
|
|
|
return Coroutine.async(scope, context) {
|
|
return Coroutine.async(scope, context) {
|
|
|
for (s in bookSourceParts) {
|
|
for (s in bookSourceParts) {
|
|
|
val source = s.getBookSource() ?: continue
|
|
val source = s.getBookSource() ?: continue
|
|
|
- val book = preciseSearchAwait(scope, source, name, author).getOrNull()
|
|
|
|
|
|
|
+ val book = preciseSearchAwait(source, name, author).getOrNull()
|
|
|
if (book != null) {
|
|
if (book != null) {
|
|
|
return@async Pair(book, source)
|
|
return@async Pair(book, source)
|
|
|
}
|
|
}
|
|
@@ -373,24 +373,19 @@ object WebBook {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
suspend fun preciseSearchAwait(
|
|
suspend fun preciseSearchAwait(
|
|
|
- scope: CoroutineScope,
|
|
|
|
|
bookSource: BookSource,
|
|
bookSource: BookSource,
|
|
|
name: String,
|
|
name: String,
|
|
|
author: String,
|
|
author: String,
|
|
|
): Result<Book> {
|
|
): Result<Book> {
|
|
|
return kotlin.runCatching {
|
|
return kotlin.runCatching {
|
|
|
- scope.isActive
|
|
|
|
|
|
|
+ coroutineContext.ensureActive()
|
|
|
searchBookAwait(
|
|
searchBookAwait(
|
|
|
bookSource, name,
|
|
bookSource, name,
|
|
|
filter = { fName, fAuthor -> fName == name && fAuthor == author },
|
|
filter = { fName, fAuthor -> fName == name && fAuthor == author },
|
|
|
shouldBreak = { it > 0 }
|
|
shouldBreak = { it > 0 }
|
|
|
).firstOrNull()?.let { searchBook ->
|
|
).firstOrNull()?.let { searchBook ->
|
|
|
- scope.isActive
|
|
|
|
|
- var book = searchBook.toBook()
|
|
|
|
|
- if (book.tocUrl.isBlank()) {
|
|
|
|
|
- book = getBookInfoAwait(bookSource, book)
|
|
|
|
|
- }
|
|
|
|
|
- return@runCatching book
|
|
|
|
|
|
|
+ coroutineContext.ensureActive()
|
|
|
|
|
+ return@runCatching searchBook.toBook()
|
|
|
}
|
|
}
|
|
|
throw NoStackTraceException("未搜索到 $name($author) 书籍")
|
|
throw NoStackTraceException("未搜索到 $name($author) 书籍")
|
|
|
}
|
|
}
|