去除刷新前重新获取目录url

添加刷新前js,功能更强大
pull/1931/head
kunfei 3 years ago
parent bacfe8f3e2
commit 0121859b1b
  1. 3
      app/src/main/assets/updateLog.md
  2. 23
      app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt
  3. 8
      app/src/main/java/io/legado/app/model/webBook/WebBook.kt

@ -16,8 +16,9 @@
* 更新cronet: 102.0.5005.78 * 更新cronet: 102.0.5005.78
* 缓存导出添加导出图片文件选项 * 缓存导出添加导出图片文件选项
* 其他设置添加图片绘制缓存选项 * 其他设置添加图片绘制缓存选项
* 移除刷新时重新获取目录页链接Url的配置 * 移除书源详情页规则添加刷新时重新获取目录页链接Url
* 添加刷新前Js,功能更强大 * 添加刷新前Js,功能更强大
* 添加java.reGetBook(), 重新获取书籍
**2022/05/27** **2022/05/27**

@ -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调用更新 * 更新tocUrl,有些书源目录url定期更新,可以在js调用更新
*/ */
fun refreshTocUrl() { fun refreshTocUrl() {
runBlocking {
val bookSource = source as? BookSource val bookSource = source as? BookSource
val book = book as? Book val book = book as? Book
if (bookSource == null || book == null) return@runBlocking if (bookSource == null || book == null) return
runBlocking {
WebBook.getBookInfoAwait(this, bookSource, book) WebBook.getBookInfoAwait(this, bookSource, book)
} }
} }

@ -339,20 +339,20 @@ object WebBook {
bookSource: BookSource, bookSource: BookSource,
name: String, name: String,
author: String, author: String,
): Result<Book?> { ): Result<Book> {
return kotlin.runCatching { return kotlin.runCatching {
if (!scope.isActive) return@runCatching null scope.isActive
searchBookAwait(scope, bookSource, name).firstOrNull { searchBookAwait(scope, bookSource, name).firstOrNull {
it.name == name && it.author == author it.name == name && it.author == author
}?.let { searchBook -> }?.let { searchBook ->
if (!scope.isActive) return@runCatching null scope.isActive
var book = searchBook.toBook() var book = searchBook.toBook()
if (book.tocUrl.isBlank()) { if (book.tocUrl.isBlank()) {
book = getBookInfoAwait(scope, bookSource, book) book = getBookInfoAwait(scope, bookSource, book)
} }
return@runCatching book return@runCatching book
} }
return@runCatching null throw NoStackTraceException("未搜索到 $name($author) 书籍")
} }
} }

Loading…
Cancel
Save