校验和调试时不保存正文

pull/1500/head
gedoor 3 years ago
parent ee3b9e3bf7
commit e3c1a7c527
  1. 15
      app/src/main/java/io/legado/app/model/Debug.kt
  2. 5
      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) { fun updateFinalMessage(sourceUrl: String, state: String) {
if (debugTimeMap[sourceUrl] != null && debugMessageMap[sourceUrl] != null) { if (debugTimeMap[sourceUrl] != null && debugMessageMap[sourceUrl] != null) {
val spendingTime = System.currentTimeMillis() - debugTimeMap[sourceUrl]!! 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 printTime = debugTimeFormat.format(Date(spendingTime))
val originalMessage = debugMessageMap[sourceUrl]!!.substringAfter("] ") val originalMessage = debugMessageMap[sourceUrl]!!.substringAfter("] ")
debugMessageMap[sourceUrl] = "$printTime $originalMessage $state" debugMessageMap[sourceUrl] = "$printTime $originalMessage $state"
@ -270,11 +270,16 @@ object Debug {
nextChapterUrl: String? nextChapterUrl: String?
) { ) {
log(debugSource, "︾开始解析正文页") log(debugSource, "︾开始解析正文页")
val content = WebBook.getContent(scope, bookSource, book, bookChapter, nextChapterUrl) val content = WebBook.getContent(
.onSuccess { scope = scope,
bookSource = bookSource,
book = book,
bookChapter = bookChapter,
nextChapterUrl = nextChapterUrl,
needSave = false
).onSuccess {
log(debugSource, "︽正文页解析完成", state = 1000) log(debugSource, "︽正文页解析完成", state = 1000)
} }.onError {
.onError {
log(debugSource, it.msg, state = -1) log(debugSource, it.msg, state = -1)
} }
tasks.add(content) tasks.add(content)

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

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

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

Loading…
Cancel
Save