校验和调试时不保存正文

pull/1500/head
gedoor 3 years ago
parent ee3b9e3bf7
commit e3c1a7c527
  1. 21
      app/src/main/java/io/legado/app/model/Debug.kt
  2. 7
      app/src/main/java/io/legado/app/model/webBook/BookContent.kt
  3. 120
      app/src/main/java/io/legado/app/model/webBook/WebBook.kt
  4. 13
      app/src/main/java/io/legado/app/service/CheckSourceService.kt

@ -94,7 +94,7 @@ object Debug {
fun updateFinalMessage(sourceUrl: String, state: String) {
if (debugTimeMap[sourceUrl] != null && debugMessageMap[sourceUrl] != null) {
val spendingTime = System.currentTimeMillis() - debugTimeMap[sourceUrl]!!
debugTimeMap[sourceUrl] = if(state == "成功") spendingTime else 180000L
debugTimeMap[sourceUrl] = if (state == "成功") spendingTime else 180000L
val printTime = debugTimeFormat.format(Date(spendingTime))
val originalMessage = debugMessageMap[sourceUrl]!!.substringAfter("] ")
debugMessageMap[sourceUrl] = "$printTime $originalMessage $state"
@ -270,13 +270,18 @@ object Debug {
nextChapterUrl: String?
) {
log(debugSource, "︾开始解析正文页")
val content = WebBook.getContent(scope, bookSource, book, bookChapter, nextChapterUrl)
.onSuccess {
log(debugSource, "︽正文页解析完成", state = 1000)
}
.onError {
log(debugSource, it.msg, state = -1)
}
val content = WebBook.getContent(
scope = scope,
bookSource = bookSource,
book = book,
bookChapter = bookChapter,
nextChapterUrl = nextChapterUrl,
needSave = false
).onSuccess {
log(debugSource, "︽正文页解析完成", state = 1000)
}.onError {
log(debugSource, it.msg, state = -1)
}
tasks.add(content)
}

@ -35,7 +35,8 @@ object BookContent {
redirectUrl: String,
baseUrl: String,
body: String?,
nextChapterUrl: String? = null
nextChapterUrl: String? = null,
needSave: Boolean = true
): String {
body ?: throw NoStackTraceException(
appCtx.getString(R.string.error_get_web_content, baseUrl)
@ -121,7 +122,9 @@ object BookContent {
if (contentStr.isBlank()) {
throw ContentEmptyException("内容为空")
}
BookHelp.saveContent(scope, bookSource, book, bookChapter, contentStr)
if (needSave) {
BookHelp.saveContent(scope, bookSource, book, bookChapter, contentStr)
}
return contentStr
}

@ -57,13 +57,13 @@ object WebBook {
}
}
return BookList.analyzeBookList(
scope,
bookSource,
variableBook,
analyzeUrl,
res.url,
res.body,
true
scope = scope,
bookSource = bookSource,
variableBook = variableBook,
analyzeUrl = analyzeUrl,
baseUrl = res.url,
body = res.body,
isSearch = true
)
}
return arrayListOf()
@ -107,13 +107,13 @@ object WebBook {
}
}
return BookList.analyzeBookList(
scope,
bookSource,
variableBook,
analyzeUrl,
res.url,
res.body,
false
scope = scope,
bookSource = bookSource,
variableBook = variableBook,
analyzeUrl = analyzeUrl,
baseUrl = res.url,
body = res.body,
isSearch = false
)
}
@ -141,13 +141,13 @@ object WebBook {
book.type = bookSource.bookSourceType
if (!book.infoHtml.isNullOrEmpty()) {
BookInfo.analyzeBookInfo(
scope,
bookSource,
book,
book.bookUrl,
book.bookUrl,
book.infoHtml,
canReName
scope = scope,
bookSource = bookSource,
book = book,
redirectUrl = book.bookUrl,
baseUrl = book.bookUrl,
body = book.infoHtml,
canReName = canReName
)
} else {
val analyzeUrl = AnalyzeUrl(
@ -165,13 +165,13 @@ object WebBook {
}
}
BookInfo.analyzeBookInfo(
scope,
bookSource,
book,
book.bookUrl,
res.url,
res.body,
canReName
scope = scope,
bookSource = bookSource,
book = book,
redirectUrl = book.bookUrl,
baseUrl = res.url,
body = res.body,
canReName = canReName
)
}
return book
@ -199,12 +199,12 @@ object WebBook {
book.type = bookSource.bookSourceType
return if (book.bookUrl == book.tocUrl && !book.tocHtml.isNullOrEmpty()) {
BookChapterList.analyzeChapterList(
scope,
bookSource,
book,
book.tocUrl,
book.tocUrl,
book.tocHtml
scope = scope,
bookSource = bookSource,
book = book,
redirectUrl = book.tocUrl,
baseUrl = book.tocUrl,
body = book.tocHtml
)
} else {
val analyzeUrl = AnalyzeUrl(
@ -222,12 +222,12 @@ object WebBook {
}
}
BookChapterList.analyzeChapterList(
scope,
bookSource,
book,
book.tocUrl,
res.url,
res.body
scope = scope,
bookSource = bookSource,
book = book,
redirectUrl = book.tocUrl,
baseUrl = res.url,
body = res.body
)
}
}
@ -241,10 +241,11 @@ object WebBook {
book: Book,
bookChapter: BookChapter,
nextChapterUrl: String? = null,
needSave: Boolean = true,
context: CoroutineContext = Dispatchers.IO
): Coroutine<String> {
return Coroutine.async(scope, context) {
getContentAwait(scope, bookSource, book, bookChapter, nextChapterUrl)
getContentAwait(scope, bookSource, book, bookChapter, nextChapterUrl, needSave)
}
}
@ -253,7 +254,8 @@ object WebBook {
bookSource: BookSource,
book: Book,
bookChapter: BookChapter,
nextChapterUrl: String? = null
nextChapterUrl: String? = null,
needSave: Boolean = true
): String {
if (bookSource.getContentRule().content.isNullOrEmpty()) {
Debug.log(bookSource.bookSourceUrl, "⇒正文规则为空,使用章节链接:${bookChapter.url}")
@ -261,14 +263,15 @@ object WebBook {
}
return if (bookChapter.url == book.bookUrl && !book.tocHtml.isNullOrEmpty()) {
BookContent.analyzeContent(
scope,
bookSource,
book,
bookChapter,
bookChapter.getAbsoluteURL(),
bookChapter.getAbsoluteURL(),
book.tocHtml,
nextChapterUrl
scope = scope,
bookSource = bookSource,
book = book,
bookChapter = bookChapter,
redirectUrl = bookChapter.getAbsoluteURL(),
baseUrl = bookChapter.getAbsoluteURL(),
body = book.tocHtml,
nextChapterUrl = nextChapterUrl,
needSave = needSave
)
} else {
val analyzeUrl = AnalyzeUrl(
@ -290,14 +293,15 @@ object WebBook {
}
}
BookContent.analyzeContent(
scope,
bookSource,
book,
bookChapter,
bookChapter.getAbsoluteURL(),
res.url,
res.body,
nextChapterUrl
scope = scope,
bookSource = bookSource,
book = book,
bookChapter = bookChapter,
redirectUrl = bookChapter.getAbsoluteURL(),
baseUrl = res.url,
body = res.body,
nextChapterUrl = nextChapterUrl,
needSave = needSave
)
}
}

@ -135,8 +135,14 @@ class CheckSourceService : BaseService() {
}
val book = WebBook.getBookInfoAwait(this, source, books.first().toBook())
val toc = WebBook.getChapterListAwait(this, source, book)
val content =
WebBook.getContentAwait(this, source, book, toc.first(), toc.getOrNull(1)?.url)
val content = WebBook.getContentAwait(
this,
bookSource = source,
book = book,
bookChapter = toc.first(),
nextChapterUrl = toc.getOrNull(1)?.url,
needSave = false
)
if (content.isBlank()) {
throw NoStackTraceException("正文内容为空")
}
@ -144,7 +150,8 @@ class CheckSourceService : BaseService() {
.onError(searchCoroutine) {
source.addGroup("失效")
if (source.bookSourceComment?.contains("Error: ") == false) {
source.bookSourceComment = "Error: ${it.localizedMessage} \n\n" + "${source.bookSourceComment}"
source.bookSourceComment =
"Error: ${it.localizedMessage} \n\n" + "${source.bookSourceComment}"
}
Debug.updateFinalMessage(source.bookSourceUrl, "失败:${it.localizedMessage}")
source.respondTime = Debug.getRespondTime(source.bookSourceUrl)

Loading…
Cancel
Save