From e3c1a7c527f175be50bd77a5b85515e3746b2c77 Mon Sep 17 00:00:00 2001 From: gedoor Date: Wed, 5 Jan 2022 09:32:28 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=A1=E9=AA=8C=E5=92=8C=E8=B0=83=E8=AF=95?= =?UTF-8?q?=E6=97=B6=E4=B8=8D=E4=BF=9D=E5=AD=98=E6=AD=A3=E6=96=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/legado/app/model/Debug.kt | 21 +-- .../legado/app/model/webBook/BookContent.kt | 7 +- .../io/legado/app/model/webBook/WebBook.kt | 120 +++++++++--------- .../legado/app/service/CheckSourceService.kt | 13 +- 4 files changed, 90 insertions(+), 71 deletions(-) diff --git a/app/src/main/java/io/legado/app/model/Debug.kt b/app/src/main/java/io/legado/app/model/Debug.kt index cc39171c0..e5225fc99 100644 --- a/app/src/main/java/io/legado/app/model/Debug.kt +++ b/app/src/main/java/io/legado/app/model/Debug.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) } diff --git a/app/src/main/java/io/legado/app/model/webBook/BookContent.kt b/app/src/main/java/io/legado/app/model/webBook/BookContent.kt index d7b3116c6..754cbc133 100644 --- a/app/src/main/java/io/legado/app/model/webBook/BookContent.kt +++ b/app/src/main/java/io/legado/app/model/webBook/BookContent.kt @@ -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 } diff --git a/app/src/main/java/io/legado/app/model/webBook/WebBook.kt b/app/src/main/java/io/legado/app/model/webBook/WebBook.kt index 373014f91..708e18b52 100644 --- a/app/src/main/java/io/legado/app/model/webBook/WebBook.kt +++ b/app/src/main/java/io/legado/app/model/webBook/WebBook.kt @@ -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 { 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 ) } } diff --git a/app/src/main/java/io/legado/app/service/CheckSourceService.kt b/app/src/main/java/io/legado/app/service/CheckSourceService.kt index 916a4f283..d1aa3da97 100644 --- a/app/src/main/java/io/legado/app/service/CheckSourceService.kt +++ b/app/src/main/java/io/legado/app/service/CheckSourceService.kt @@ -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)