From b51594e418002d1a5f05e0637cb142ce2838aa97 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 3 Sep 2019 10:55:48 +0800 Subject: [PATCH] up --- .../app/model/webbook/BookChapterList.kt | 106 +++++++++--------- 1 file changed, 53 insertions(+), 53 deletions(-) diff --git a/app/src/main/java/io/legado/app/model/webbook/BookChapterList.kt b/app/src/main/java/io/legado/app/model/webbook/BookChapterList.kt index 63be14066..81b09ef96 100644 --- a/app/src/main/java/io/legado/app/model/webbook/BookChapterList.kt +++ b/app/src/main/java/io/legado/app/model/webbook/BookChapterList.kt @@ -17,20 +17,20 @@ import retrofit2.Response object BookChapterList { suspend fun analyzeChapterList( - coroutineScope: CoroutineScope, - book: Book, - response: Response, - bookSource: BookSource, - analyzeUrl: AnalyzeUrl + coroutineScope: CoroutineScope, + book: Book, + response: Response, + bookSource: BookSource, + analyzeUrl: AnalyzeUrl ): List { var chapterList = arrayListOf() val baseUrl: String = NetworkUtils.getUrl(response) val body: String? = response.body() body ?: throw Exception( - App.INSTANCE.getString( - R.string.error_get_web_content, - baseUrl - ) + App.INSTANCE.getString( + R.string.error_get_web_content, + baseUrl + ) ) SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取成功:$baseUrl") val tocRule = bookSource.getTocRule() @@ -45,7 +45,7 @@ object BookChapterList { listRule = listRule.substring(1) } var chapterData = - analyzeChapterList(body, baseUrl, tocRule, listRule, book, bookSource, printLog = true) + analyzeChapterList(body, baseUrl, tocRule, listRule, book, bookSource, printLog = true) chapterData.chapterList?.let { chapterList.addAll(it) } @@ -54,25 +54,25 @@ object BookChapterList { while (nextUrl.isNotEmpty() && !nextUrlList.contains(nextUrl)) { nextUrlList.add(nextUrl) AnalyzeUrl( - ruleUrl = nextUrl, - book = book, - headerMapF = bookSource.getHeaderMap() + ruleUrl = nextUrl, + book = book, + headerMapF = bookSource.getHeaderMap() ).getResponseAsync().await() - .body()?.let { nextBody -> - chapterData = analyzeChapterList( - nextBody, - nextUrl, - tocRule, - listRule, - book, - bookSource - ) - nextUrl = - if (chapterData.nextUrl.isNotEmpty()) chapterData.nextUrl[0] else "" - chapterData.chapterList?.let { - chapterList.addAll(it) + .body()?.let { nextBody -> + chapterData = analyzeChapterList( + nextBody, + nextUrl, + tocRule, + listRule, + book, + bookSource + ) + nextUrl = + if (chapterData.nextUrl.isNotEmpty()) chapterData.nextUrl[0] else "" + chapterData.chapterList?.let { + chapterList.addAll(it) + } } - } } } else if (chapterData.nextUrl.size > 1) { val chapterDataList = arrayListOf>() @@ -83,18 +83,18 @@ object BookChapterList { for (item in chapterDataList) { withContext(coroutineScope.coroutineContext) { val nextResponse = AnalyzeUrl( - ruleUrl = item.nextUrl, - book = book, - headerMapF = bookSource.getHeaderMap() + ruleUrl = item.nextUrl, + book = book, + headerMapF = bookSource.getHeaderMap() ).getResponseAsync().await() val nextChapterData = analyzeChapterList( - nextResponse.body() ?: "", - item.nextUrl, - tocRule, - listRule, - book, - bookSource, - getNextUrl = false + nextResponse.body() ?: "", + item.nextUrl, + tocRule, + listRule, + book, + bookSource, + getNextUrl = false ) item.chapterList = nextChapterData.chapterList } @@ -125,14 +125,14 @@ object BookChapterList { private fun analyzeChapterList( - body: String, - baseUrl: String, - tocRule: TocRule, - listRule: String, - book: Book, - bookSource: BookSource, - getNextUrl: Boolean = true, - printLog: Boolean = false + body: String, + baseUrl: String, + tocRule: TocRule, + listRule: String, + book: Book, + bookSource: BookSource, + getNextUrl: Boolean = true, + printLog: Boolean = false ): ChapterData> { val chapterList = arrayListOf() val nextUrlList = arrayListOf() @@ -148,10 +148,10 @@ object BookChapterList { } } SourceDebug.printLog( - bookSource.bookSourceUrl, - 1, - TextUtils.join(",", nextUrlList), - printLog + bookSource.bookSourceUrl, + 1, + TextUtils.join(",", nextUrlList), + printLog ) } SourceDebug.printLog(bookSource.bookSourceUrl, 1, "解析目录列表", printLog) @@ -173,10 +173,10 @@ object BookChapterList { } } SourceDebug.printLog( - bookSource.bookSourceUrl, - 1, - "${chapterList[0].title}${chapterList[0].url}", - printLog + bookSource.bookSourceUrl, + 1, + "${chapterList[0].title}${chapterList[0].url}", + printLog ) } return ChapterData(chapterList, nextUrlList)