|
|
@ -10,20 +10,18 @@ import io.legado.app.model.analyzeRule.AnalyzeRule |
|
|
|
import io.legado.app.model.analyzeRule.AnalyzeUrl |
|
|
|
import io.legado.app.model.analyzeRule.AnalyzeUrl |
|
|
|
import io.legado.app.utils.NetworkUtils |
|
|
|
import io.legado.app.utils.NetworkUtils |
|
|
|
import kotlinx.coroutines.CoroutineScope |
|
|
|
import kotlinx.coroutines.CoroutineScope |
|
|
|
import kotlinx.coroutines.launch |
|
|
|
import kotlinx.coroutines.withContext |
|
|
|
import retrofit2.Response |
|
|
|
import retrofit2.Response |
|
|
|
import java.util.concurrent.atomic.AtomicInteger |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
object BookChapterList { |
|
|
|
object BookChapterList { |
|
|
|
|
|
|
|
|
|
|
|
fun analyzeChapterList( |
|
|
|
suspend fun analyzeChapterList( |
|
|
|
coroutineScope: CoroutineScope, |
|
|
|
coroutineScope: CoroutineScope, |
|
|
|
book: Book, |
|
|
|
book: Book, |
|
|
|
response: Response<String>, |
|
|
|
response: Response<String>, |
|
|
|
bookSource: BookSource, |
|
|
|
bookSource: BookSource, |
|
|
|
analyzeUrl: AnalyzeUrl, |
|
|
|
analyzeUrl: AnalyzeUrl |
|
|
|
success: (List<BookChapter>) -> Unit |
|
|
|
): List<BookChapter> { |
|
|
|
) { |
|
|
|
|
|
|
|
val chapterList = arrayListOf<BookChapter>() |
|
|
|
val chapterList = arrayListOf<BookChapter>() |
|
|
|
val baseUrl: String = NetworkUtils.getUrl(response) |
|
|
|
val baseUrl: String = NetworkUtils.getUrl(response) |
|
|
|
val body: String? = response.body() |
|
|
|
val body: String? = response.body() |
|
|
@ -63,35 +61,27 @@ object BookChapterList { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (reverse) chapterList.reverse() |
|
|
|
if (reverse) chapterList.reverse() |
|
|
|
success(chapterList) |
|
|
|
|
|
|
|
} else if (chapterData.nextUrl.size > 1) { |
|
|
|
} else if (chapterData.nextUrl.size > 1) { |
|
|
|
val chapterDataList = arrayListOf<ChapterData<String>>() |
|
|
|
|
|
|
|
for (item in chapterData.nextUrl) { |
|
|
|
for (item in chapterData.nextUrl) { |
|
|
|
if (!nextUrlList.contains(item)) { |
|
|
|
if (!nextUrlList.contains(item)) { |
|
|
|
val data = ChapterData(nextUrl = item) |
|
|
|
withContext(coroutineScope.coroutineContext) { |
|
|
|
chapterDataList.add(data) |
|
|
|
val nextResponse = AnalyzeUrl(ruleUrl = item, book = book).getResponseAsync().await() |
|
|
|
} |
|
|
|
val nextChapterData = analyzeChapterList( |
|
|
|
} |
|
|
|
nextResponse.body() ?: "", |
|
|
|
val successCount = AtomicInteger(0) |
|
|
|
item, |
|
|
|
for (item in chapterDataList) { |
|
|
|
tocRule, |
|
|
|
coroutineScope.launch { |
|
|
|
listRule, |
|
|
|
val nextResponse = AnalyzeUrl(ruleUrl = item.nextUrl, book = book).getResponseAsync().await() |
|
|
|
book |
|
|
|
val nextChapterData = |
|
|
|
) |
|
|
|
analyzeChapterList(nextResponse.body() ?: "", item.nextUrl, tocRule, listRule, book) |
|
|
|
nextChapterData.chapterList?.let { |
|
|
|
item.chapterList = nextChapterData.chapterList |
|
|
|
chapterList.addAll(it) |
|
|
|
val nowCount = successCount.incrementAndGet() |
|
|
|
|
|
|
|
if (nowCount == chapterDataList.size) { |
|
|
|
|
|
|
|
for (newItem in chapterDataList) { |
|
|
|
|
|
|
|
newItem.chapterList?.let { |
|
|
|
|
|
|
|
chapterList.addAll(it) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
if (reverse) chapterList.reverse() |
|
|
|
|
|
|
|
success(chapterList) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (reverse) chapterList.reverse() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return chapterList |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|