From 2bed9af097f8141df027b4c5e5ad3c0e93ef7878 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 26 Oct 2019 20:35:21 +0800 Subject: [PATCH] up --- .../main/java/io/legado/app/model/WebBook.kt | 24 +++++++++++-------- .../legado/app/model/webbook/BookContent.kt | 11 ++++----- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/io/legado/app/model/WebBook.kt b/app/src/main/java/io/legado/app/model/WebBook.kt index e290e555c..3d1053510 100644 --- a/app/src/main/java/io/legado/app/model/WebBook.kt +++ b/app/src/main/java/io/legado/app/model/WebBook.kt @@ -124,21 +124,25 @@ class WebBook(val bookSource: BookSource) { context: CoroutineContext = Dispatchers.IO ): Coroutine { return Coroutine.async(scope, context) { - val analyzeUrl = - AnalyzeUrl( - book = book, - ruleUrl = bookChapter.url, - baseUrl = book.tocUrl, - headerMapF = bookSource.getHeaderMap() - ) - val response = analyzeUrl.getResponseAsync().await() + val body = if (bookChapter.url == book.bookUrl && !book.tocHtml.isNullOrEmpty()) { + book.tocHtml + } else { + val analyzeUrl = + AnalyzeUrl( + book = book, + ruleUrl = bookChapter.url, + baseUrl = book.tocUrl, + headerMapF = bookSource.getHeaderMap() + ) + analyzeUrl.getResponseAsync().await().body() + } BookContent.analyzeContent( this, - response, + body, book, bookChapter, bookSource, - analyzeUrl, + bookChapter.url, nextChapterUrl ) } 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 65384aa77..b6cf23442 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 @@ -12,29 +12,26 @@ import io.legado.app.utils.NetworkUtils import io.legado.app.utils.htmlFormat import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.withContext -import retrofit2.Response object BookContent { @Throws(Exception::class) suspend fun analyzeContent( coroutineScope: CoroutineScope, - response: Response, + body: String?, book: Book, bookChapter: BookChapter, bookSource: BookSource, - analyzeUrl: AnalyzeUrl, + baseUrl: String, nextChapterUrlF: String? = null ): String { - val baseUrl: String = NetworkUtils.getUrl(response) - val body: String? = response.body() body ?: throw Exception( App.INSTANCE.getString( R.string.error_get_web_content, - analyzeUrl.ruleUrl + baseUrl ) ) - SourceDebug.printLog(bookSource.bookSourceUrl, "获取成功:${analyzeUrl.ruleUrl}") + SourceDebug.printLog(bookSource.bookSourceUrl, "获取成功:${baseUrl}") val content = StringBuilder() val nextUrlList = arrayListOf(baseUrl) val contentRule = bookSource.getContentRule()