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 52ee84b0c..5318a812d 100644 --- a/app/src/main/java/io/legado/app/model/WebBook.kt +++ b/app/src/main/java/io/legado/app/model/WebBook.kt @@ -47,7 +47,7 @@ class WebBook(private val bookSource: BookSource) { Coroutine.async { val analyzeUrl = AnalyzeUrl(book = book, ruleUrl = book.tocUrl) val response = analyzeUrl.getResponseAsync().await() - BookChapterList.analyzeChapterList(book, response, bookSource, analyzeUrl, success) + BookChapterList.analyzeChapterList(this, book, response, bookSource, analyzeUrl, success) } } } \ No newline at end of file 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 99d014f79..6eb11c095 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 @@ -9,11 +9,14 @@ import io.legado.app.data.entities.rule.TocRule import io.legado.app.model.analyzeRule.AnalyzeRule import io.legado.app.model.analyzeRule.AnalyzeUrl import io.legado.app.utils.NetworkUtils +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.launch import retrofit2.Response object BookChapterList { fun analyzeChapterList( + coroutineScope: CoroutineScope, book: Book, response: Response, bookSource: BookSource, @@ -35,17 +38,17 @@ object BookChapterList { chapterData.chapterList?.let { chapterList.addAll(it) } - if (chapterData.nextUrlList.size == 1) { - var nextUrl = chapterData.nextUrlList[0] + if (chapterData.nextUrl.size == 1) { + var nextUrl = chapterData.nextUrl[0] while (nextUrl.isNotEmpty() && !nextUrlList.contains(nextUrl)) { nextUrlList.add(nextUrl) AnalyzeUrl(ruleUrl = nextUrl, book = book).getResponse().execute() .body()?.let { nextBody -> chapterData = analyzeChapterList(nextBody, nextUrl, tocRule, book) - nextUrl = if (chapterData.nextUrlList.isEmpty()) { + nextUrl = if (chapterData.nextUrl.isEmpty()) { "" } else { - chapterData.nextUrlList[0] + chapterData.nextUrl[0] } chapterData.chapterList?.let { chapterList.addAll(it) @@ -53,17 +56,24 @@ object BookChapterList { } } success(chapterList) - } else if (chapterData.nextUrlList.size > 1) { + } else if (chapterData.nextUrl.size > 1) { val chapterDataList = arrayListOf>() - for (item in chapterData.nextUrlList) { + for (item in chapterData.nextUrl) { if (!nextUrlList.contains(item)) { - val data = ChapterData(nextUrlList = item) + val data = ChapterData(nextUrl = item) chapterDataList.add(data) } } + var successCount = 0 + for (item in chapterDataList) { + coroutineScope.launch { + AnalyzeUrl(ruleUrl = item.nextUrl, book = book).getResponse().execute().body() + } + } } } + private fun analyzeChapterList( body: String, baseUrl: String, diff --git a/app/src/main/java/io/legado/app/model/webbook/ChapterData.kt b/app/src/main/java/io/legado/app/model/webbook/ChapterData.kt index fa43c1600..bbbf6060b 100644 --- a/app/src/main/java/io/legado/app/model/webbook/ChapterData.kt +++ b/app/src/main/java/io/legado/app/model/webbook/ChapterData.kt @@ -4,5 +4,5 @@ import io.legado.app.data.entities.BookChapter data class ChapterData( var chapterList: List? = null, - var nextUrlList: T + var nextUrl: T ) \ No newline at end of file