|
|
@ -8,9 +8,11 @@ import io.legado.app.base.BaseService |
|
|
|
import io.legado.app.constant.AppConst |
|
|
|
import io.legado.app.constant.AppConst |
|
|
|
import io.legado.app.constant.EventBus |
|
|
|
import io.legado.app.constant.EventBus |
|
|
|
import io.legado.app.constant.IntentAction |
|
|
|
import io.legado.app.constant.IntentAction |
|
|
|
|
|
|
|
import io.legado.app.data.entities.BookSource |
|
|
|
import io.legado.app.help.AppConfig |
|
|
|
import io.legado.app.help.AppConfig |
|
|
|
import io.legado.app.help.IntentHelp |
|
|
|
import io.legado.app.help.IntentHelp |
|
|
|
import io.legado.app.help.coroutine.CompositeCoroutine |
|
|
|
import io.legado.app.help.coroutine.CompositeCoroutine |
|
|
|
|
|
|
|
import io.legado.app.model.webBook.WebBook |
|
|
|
import io.legado.app.service.help.CheckSource |
|
|
|
import io.legado.app.service.help.CheckSource |
|
|
|
import io.legado.app.ui.book.source.manage.BookSourceActivity |
|
|
|
import io.legado.app.ui.book.source.manage.BookSourceActivity |
|
|
|
import io.legado.app.utils.postEvent |
|
|
|
import io.legado.app.utils.postEvent |
|
|
@ -21,7 +23,7 @@ import kotlin.math.min |
|
|
|
|
|
|
|
|
|
|
|
class CheckSourceService : BaseService() { |
|
|
|
class CheckSourceService : BaseService() { |
|
|
|
private var threadCount = AppConfig.threadCount |
|
|
|
private var threadCount = AppConfig.threadCount |
|
|
|
private var searchPool = Executors.newFixedThreadPool(threadCount).asCoroutineDispatcher() |
|
|
|
private var searchCoroutine = Executors.newFixedThreadPool(threadCount).asCoroutineDispatcher() |
|
|
|
private var tasks = CompositeCoroutine() |
|
|
|
private var tasks = CompositeCoroutine() |
|
|
|
private val allIds = ArrayList<String>() |
|
|
|
private val allIds = ArrayList<String>() |
|
|
|
private val checkedIds = ArrayList<String>() |
|
|
|
private val checkedIds = ArrayList<String>() |
|
|
@ -62,7 +64,7 @@ class CheckSourceService : BaseService() { |
|
|
|
override fun onDestroy() { |
|
|
|
override fun onDestroy() { |
|
|
|
super.onDestroy() |
|
|
|
super.onDestroy() |
|
|
|
tasks.clear() |
|
|
|
tasks.clear() |
|
|
|
searchPool.close() |
|
|
|
searchCoroutine.close() |
|
|
|
postEvent(EventBus.CHECK_SOURCE_DONE, 0) |
|
|
|
postEvent(EventBus.CHECK_SOURCE_DONE, 0) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -96,15 +98,31 @@ class CheckSourceService : BaseService() { |
|
|
|
if (index < allIds.size) { |
|
|
|
if (index < allIds.size) { |
|
|
|
val sourceUrl = allIds[index] |
|
|
|
val sourceUrl = allIds[index] |
|
|
|
App.db.bookSourceDao.getBookSource(sourceUrl)?.let { source -> |
|
|
|
App.db.bookSourceDao.getBookSource(sourceUrl)?.let { source -> |
|
|
|
if (source.searchUrl.isNullOrEmpty()) { |
|
|
|
check(source) |
|
|
|
onNext(sourceUrl, source.bookSourceName) |
|
|
|
} ?: onNext(sourceUrl, "") |
|
|
|
} else { |
|
|
|
|
|
|
|
CheckSource(source).check(this, searchPool) { |
|
|
|
|
|
|
|
onNext(it, source.bookSourceName) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} ?: onNext(sourceUrl, "") |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fun check(source: BookSource) { |
|
|
|
|
|
|
|
execute(context = searchCoroutine) { |
|
|
|
|
|
|
|
val webBook = WebBook(source) |
|
|
|
|
|
|
|
val books = webBook.searchBookAwait(this, CheckSource.keyword) |
|
|
|
|
|
|
|
val book = webBook.getBookInfoAwait(this, books.first().toBook()) |
|
|
|
|
|
|
|
val toc = webBook.getChapterListAwait(this, book) |
|
|
|
|
|
|
|
val content = webBook.getContentAwait(this, book, toc.first()) |
|
|
|
|
|
|
|
if (content.isBlank()) { |
|
|
|
|
|
|
|
throw Exception("正文内容为空") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}.timeout(60000L) |
|
|
|
|
|
|
|
.onError { |
|
|
|
|
|
|
|
source.addGroup("失效") |
|
|
|
|
|
|
|
App.db.bookSourceDao.update(source) |
|
|
|
|
|
|
|
}.onSuccess { |
|
|
|
|
|
|
|
source.removeGroup("失效") |
|
|
|
|
|
|
|
App.db.bookSourceDao.update(source) |
|
|
|
|
|
|
|
}.onFinally { |
|
|
|
|
|
|
|
onNext(source.bookSourceUrl, source.bookSourceName) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|