From 92be85e69d05cf17a38737ba07f9bc79ff72dbe8 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 2 Feb 2022 10:14:18 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=9B=B4=E6=96=B0bookUrl?= =?UTF-8?q?=E5=92=8C=E6=9B=B4=E6=96=B0tocUrl=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/model/analyzeRule/AnalyzeRule.kt | 38 +++++++++++++++++-- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt index 1e1b87915..e1d098517 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt @@ -4,12 +4,11 @@ import android.text.TextUtils import androidx.annotation.Keep import io.legado.app.constant.AppConst.SCRIPT_ENGINE import io.legado.app.constant.AppPattern.JS_PATTERN -import io.legado.app.data.entities.BaseBook -import io.legado.app.data.entities.BaseSource -import io.legado.app.data.entities.BookChapter +import io.legado.app.data.entities.* import io.legado.app.help.CacheManager import io.legado.app.help.JsExtensions import io.legado.app.help.http.CookieStore +import io.legado.app.model.webBook.WebBook import io.legado.app.utils.* import kotlinx.coroutines.runBlocking import org.jsoup.nodes.Entities @@ -684,6 +683,39 @@ class AnalyzeRule( return s } + /** + * 更新BookUrl,如果搜索结果有tocUrl也会更新,有些书源bookUrl定期更新,可以在js内调用更新 + */ + fun refreshBookUrl() { + runBlocking { + val bookSource = source as? BookSource + val book = book as? Book + if (bookSource == null || book == null) return@runBlocking + val books = WebBook.searchBookAwait(this, bookSource, book.name) + books.forEach { + if (it.name == book.name && it.author == book.author) { + book.bookUrl = it.bookUrl + if (it.tocUrl.isNotBlank()) { + book.tocUrl = it.tocUrl + } + return@runBlocking + } + } + } + } + + /** + * 更新tocUrl,有些书源目录url定期更新,可以在js调用更新 + */ + fun refreshTocUrl() { + runBlocking { + val bookSource = source as? BookSource + val book = book as? Book + if (bookSource == null || book == null) return@runBlocking + WebBook.getBookInfoAwait(this, bookSource, book) + } + } + companion object { private val putPattern = Pattern.compile("@put:(\\{[^}]+?\\})", Pattern.CASE_INSENSITIVE) private val evalPattern =