From 0121859b1bef46ec705099fd6e96246262a74a96 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 30 May 2022 20:43:36 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8E=BB=E9=99=A4=E5=88=B7=E6=96=B0=E5=89=8D?= =?UTF-8?q?=E9=87=8D=E6=96=B0=E8=8E=B7=E5=8F=96=E7=9B=AE=E5=BD=95url=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=88=B7=E6=96=B0=E5=89=8Djs,=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E6=9B=B4=E5=BC=BA=E5=A4=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/assets/updateLog.md | 3 ++- .../app/model/analyzeRule/AnalyzeRule.kt | 25 ++++++++++++++++--- .../io/legado/app/model/webBook/WebBook.kt | 8 +++--- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index a2bb3bab8..74d5f3b79 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -16,8 +16,9 @@ * 更新cronet: 102.0.5005.78 * 缓存导出添加导出图片文件选项 * 其他设置添加图片绘制缓存选项 -* 移除刷新时重新获取目录页链接Url的配置 +* 移除书源详情页规则添加刷新时重新获取目录页链接Url * 添加刷新前Js,功能更强大 +* 添加java.reGetBook(), 重新获取书籍 **2022/05/27** 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 32f9ab482..4d38cdef0 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 @@ -704,14 +704,33 @@ class AnalyzeRule( } } + /** + * 重新获取book + */ + fun reGetBook() { + val bookSource = source as? BookSource + val book = book as? Book + if (bookSource == null || book == null) return + runBlocking { + WebBook.preciseSearchAwait(this, bookSource, book.name, book.author) + .getOrThrow().let { + book.bookUrl = it.bookUrl + it.variableMap.forEach { entry -> + book.putVariable(entry.key, entry.value) + } + } + WebBook.getBookInfoAwait(this, bookSource, book, false) + } + } + /** * 更新tocUrl,有些书源目录url定期更新,可以在js调用更新 */ fun refreshTocUrl() { + val bookSource = source as? BookSource + val book = book as? Book + if (bookSource == null || book == null) return runBlocking { - val bookSource = source as? BookSource - val book = book as? Book - if (bookSource == null || book == null) return@runBlocking WebBook.getBookInfoAwait(this, bookSource, book) } } diff --git a/app/src/main/java/io/legado/app/model/webBook/WebBook.kt b/app/src/main/java/io/legado/app/model/webBook/WebBook.kt index 805a33281..cd6f77cba 100644 --- a/app/src/main/java/io/legado/app/model/webBook/WebBook.kt +++ b/app/src/main/java/io/legado/app/model/webBook/WebBook.kt @@ -339,20 +339,20 @@ object WebBook { bookSource: BookSource, name: String, author: String, - ): Result { + ): Result { return kotlin.runCatching { - if (!scope.isActive) return@runCatching null + scope.isActive searchBookAwait(scope, bookSource, name).firstOrNull { it.name == name && it.author == author }?.let { searchBook -> - if (!scope.isActive) return@runCatching null + scope.isActive var book = searchBook.toBook() if (book.tocUrl.isBlank()) { book = getBookInfoAwait(scope, bookSource, book) } return@runCatching book } - return@runCatching null + throw NoStackTraceException("未搜索到 $name($author) 书籍") } }