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 61afa35c1..e965b9460 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 @@ -62,23 +62,33 @@ object BookChapterList { } if (reverse) chapterList.reverse() } else if (chapterData.nextUrl.size > 1) { + val chapterDataList = arrayListOf>() for (item in chapterData.nextUrl) { if (!nextUrlList.contains(item)) { + val data = ChapterData(nextUrl = item) + chapterDataList.add(data) + } + } + for (item in chapterDataList) { + if (!nextUrlList.contains(item.nextUrl)) { withContext(coroutineScope.coroutineContext) { - val nextResponse = AnalyzeUrl(ruleUrl = item, book = book).getResponseAsync().await() + val nextResponse = AnalyzeUrl(ruleUrl = item.nextUrl, book = book).getResponseAsync().await() val nextChapterData = analyzeChapterList( nextResponse.body() ?: "", - item, + item.nextUrl, tocRule, listRule, book ) - nextChapterData.chapterList?.let { - chapterList.addAll(it) - } + item.chapterList = nextChapterData.chapterList } } } + for (item in chapterDataList) { + item.chapterList?.let { + chapterList.addAll(it) + } + } if (reverse) chapterList.reverse() } return chapterList @@ -99,7 +109,7 @@ object BookChapterList { analyzeRule.getStringList(tocRule.nextTocUrl ?: "", true)?.let { nextUrlList.addAll(it) } - val elements = analyzeRule.getElements(tocRule.chapterList ?: "") + val elements = analyzeRule.getElements(listRule) if (elements.isNotEmpty()) { val nameRule = analyzeRule.splitSourceRule(tocRule.chapterName ?: "") val urlRule = analyzeRule.splitSourceRule(tocRule.chapterUrl ?: "")