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, chapter,
context = context context = context
).onSuccess { content -> ).onSuccess { content ->
if (content.isNotBlank()) {
onSuccess(chapterIndex) onSuccess(chapterIndex)
addLog("${book.name}-${chapter.title} getContentSuccess") addLog("${book.name}-${chapter.title} getContentSuccess")
downloadFinish(chapter, content.ifBlank { "No content" }) downloadFinish(chapter, content)
} else {
//出现错误等待1秒后重新加入待下载列表
delay(1000)
onErrorOrCancel(chapterIndex)
addLog("${book.name}-${chapter.title} getContentError 内容为空")
downloadFinish(chapter, "download error 内容为空")
}
}.onError { }.onError {
//出现错误等待1秒后重新加入待下载列表 //出现错误等待后重新加入待下载列表
delay(1000) when (it) {
is ConcurrentException -> delay(it.waitTime)
else -> delay(1000)
}
onErrorOrCancel(chapterIndex) onErrorOrCancel(chapterIndex)
print(it.localizedMessage) print(it.localizedMessage)
addLog("${book.name}-${chapter.title} getContentError${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) WebBook.getContent(scope, bookSource, book, chapter)
.onSuccess { content -> .onSuccess { content ->
onSuccess(chapter.index) onSuccess(chapter.index)
downloadFinish(chapter, content.ifBlank { "No content" }, resetPageOffset) downloadFinish(chapter, content, resetPageOffset)
}.onError { }.onError {
onErrorOrCancel(chapter.index) onErrorOrCancel(chapter.index)
downloadFinish( 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.CacheManager
import io.legado.app.help.JsExtensions import io.legado.app.help.JsExtensions
import io.legado.app.help.http.* import io.legado.app.help.http.*
import io.legado.app.model.ConcurrentException
import io.legado.app.utils.* import io.legado.app.utils.*
import java.net.URLEncoder import java.net.URLEncoder
import java.util.* import java.util.*
@ -312,7 +313,7 @@ class AnalyzeUrl(
} }
} }
if (waitTime > 0) { 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.BookSource
import io.legado.app.data.entities.rule.ContentRule import io.legado.app.data.entities.rule.ContentRule
import io.legado.app.help.BookHelp import io.legado.app.help.BookHelp
import io.legado.app.model.ContentEmptyException
import io.legado.app.model.Debug import io.legado.app.model.Debug
import io.legado.app.model.analyzeRule.AnalyzeRule import io.legado.app.model.analyzeRule.AnalyzeRule
import io.legado.app.model.analyzeRule.AnalyzeUrl import io.legado.app.model.analyzeRule.AnalyzeUrl
@ -114,9 +115,10 @@ object BookContent {
Debug.log(bookSource.bookSourceUrl, "${bookChapter.title}") Debug.log(bookSource.bookSourceUrl, "${bookChapter.title}")
Debug.log(bookSource.bookSourceUrl, "┌获取正文内容") Debug.log(bookSource.bookSourceUrl, "┌获取正文内容")
Debug.log(bookSource.bookSourceUrl, "\n$contentStr") Debug.log(bookSource.bookSourceUrl, "\n$contentStr")
if (contentStr.isNotBlank()) { if (contentStr.isBlank()) {
BookHelp.saveContent(bookSource, book, bookChapter, contentStr) throw ContentEmptyException("${bookChapter.title}内容为空")
} }
BookHelp.saveContent(bookSource, book, bookChapter, contentStr)
return contentStr return contentStr
} }

Loading…
Cancel
Save