pull/1301/head
gedoor 3 years ago
parent d0ce31421f
commit 2310270f2e
  1. 19
      app/src/main/java/io/legado/app/model/CacheBook.kt
  2. 5
      app/src/main/java/io/legado/app/model/Exceptions.kt
  3. 3
      app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt
  4. 6
      app/src/main/java/io/legado/app/model/webBook/BookContent.kt

@ -197,20 +197,15 @@ class CacheBook(var bookSource: BookSource, var book: Book) {
chapter,
context = context
).onSuccess { content ->
if (content.isNotBlank()) {
onSuccess(chapterIndex)
addLog("${book.name}-${chapter.title} getContentSuccess")
downloadFinish(chapter, content.ifBlank { "No content" })
} else {
//出现错误等待1秒后重新加入待下载列表
delay(1000)
onErrorOrCancel(chapterIndex)
addLog("${book.name}-${chapter.title} getContentError 内容为空")
downloadFinish(chapter, "download error 内容为空")
}
downloadFinish(chapter, content)
}.onError {
//出现错误等待1秒后重新加入待下载列表
delay(1000)
//出现错误等待后重新加入待下载列表
when (it) {
is ConcurrentException -> delay(it.waitTime)
else -> delay(1000)
}
onErrorOrCancel(chapterIndex)
print(it.localizedMessage)
addLog("${book.name}-${chapter.title} getContentError${it.localizedMessage}")
@ -238,7 +233,7 @@ class CacheBook(var bookSource: BookSource, var book: Book) {
WebBook.getContent(scope, bookSource, book, chapter)
.onSuccess { content ->
onSuccess(chapter.index)
downloadFinish(chapter, content.ifBlank { "No content" }, resetPageOffset)
downloadFinish(chapter, content, resetPageOffset)
}.onError {
onErrorOrCancel(chapter.index)
downloadFinish(

@ -0,0 +1,5 @@
package io.legado.app.model
class ContentEmptyException(msg: String) : Exception(msg)
class ConcurrentException(msg: String, val waitTime: Long) : Exception(msg)

@ -14,6 +14,7 @@ import io.legado.app.help.AppConfig
import io.legado.app.help.CacheManager
import io.legado.app.help.JsExtensions
import io.legado.app.help.http.*
import io.legado.app.model.ConcurrentException
import io.legado.app.utils.*
import java.net.URLEncoder
import java.util.*
@ -312,7 +313,7 @@ class AnalyzeUrl(
}
}
if (waitTime > 0) {
error("根据并发率还需等待${waitTime}毫秒才可以访问")
throw ConcurrentException("根据并发率还需等待${waitTime}毫秒才可以访问", waitTime = waitTime)
}
}

@ -7,6 +7,7 @@ import io.legado.app.data.entities.BookChapter
import io.legado.app.data.entities.BookSource
import io.legado.app.data.entities.rule.ContentRule
import io.legado.app.help.BookHelp
import io.legado.app.model.ContentEmptyException
import io.legado.app.model.Debug
import io.legado.app.model.analyzeRule.AnalyzeRule
import io.legado.app.model.analyzeRule.AnalyzeUrl
@ -114,9 +115,10 @@ object BookContent {
Debug.log(bookSource.bookSourceUrl, "${bookChapter.title}")
Debug.log(bookSource.bookSourceUrl, "┌获取正文内容")
Debug.log(bookSource.bookSourceUrl, "\n$contentStr")
if (contentStr.isNotBlank()) {
BookHelp.saveContent(bookSource, book, bookChapter, contentStr)
if (contentStr.isBlank()) {
throw ContentEmptyException("${bookChapter.title}内容为空")
}
BookHelp.saveContent(bookSource, book, bookChapter, contentStr)
return contentStr
}

Loading…
Cancel
Save