pull/32/head
kunfei 5 years ago
parent fecd36ac65
commit 84fa535ec8
  1. 2
      app/src/main/java/io/legado/app/model/WebBook.kt
  2. 24
      app/src/main/java/io/legado/app/model/webbook/BookChapterList.kt
  3. 2
      app/src/main/java/io/legado/app/model/webbook/ChapterData.kt

@ -47,7 +47,7 @@ class WebBook(private val bookSource: BookSource) {
Coroutine.async { Coroutine.async {
val analyzeUrl = AnalyzeUrl(book = book, ruleUrl = book.tocUrl) val analyzeUrl = AnalyzeUrl(book = book, ruleUrl = book.tocUrl)
val response = analyzeUrl.getResponseAsync().await() val response = analyzeUrl.getResponseAsync().await()
BookChapterList.analyzeChapterList(book, response, bookSource, analyzeUrl, success) BookChapterList.analyzeChapterList(this, book, response, bookSource, analyzeUrl, success)
} }
} }
} }

@ -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.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.launch
import retrofit2.Response import retrofit2.Response
object BookChapterList { object BookChapterList {
fun analyzeChapterList( fun analyzeChapterList(
coroutineScope: CoroutineScope,
book: Book, book: Book,
response: Response<String>, response: Response<String>,
bookSource: BookSource, bookSource: BookSource,
@ -35,17 +38,17 @@ object BookChapterList {
chapterData.chapterList?.let { chapterData.chapterList?.let {
chapterList.addAll(it) chapterList.addAll(it)
} }
if (chapterData.nextUrlList.size == 1) { if (chapterData.nextUrl.size == 1) {
var nextUrl = chapterData.nextUrlList[0] var nextUrl = chapterData.nextUrl[0]
while (nextUrl.isNotEmpty() && !nextUrlList.contains(nextUrl)) { while (nextUrl.isNotEmpty() && !nextUrlList.contains(nextUrl)) {
nextUrlList.add(nextUrl) nextUrlList.add(nextUrl)
AnalyzeUrl(ruleUrl = nextUrl, book = book).getResponse().execute() AnalyzeUrl(ruleUrl = nextUrl, book = book).getResponse().execute()
.body()?.let { nextBody -> .body()?.let { nextBody ->
chapterData = analyzeChapterList(nextBody, nextUrl, tocRule, book) chapterData = analyzeChapterList(nextBody, nextUrl, tocRule, book)
nextUrl = if (chapterData.nextUrlList.isEmpty()) { nextUrl = if (chapterData.nextUrl.isEmpty()) {
"" ""
} else { } else {
chapterData.nextUrlList[0] chapterData.nextUrl[0]
} }
chapterData.chapterList?.let { chapterData.chapterList?.let {
chapterList.addAll(it) chapterList.addAll(it)
@ -53,17 +56,24 @@ object BookChapterList {
} }
} }
success(chapterList) success(chapterList)
} else if (chapterData.nextUrlList.size > 1) { } else if (chapterData.nextUrl.size > 1) {
val chapterDataList = arrayListOf<ChapterData<String>>() val chapterDataList = arrayListOf<ChapterData<String>>()
for (item in chapterData.nextUrlList) { for (item in chapterData.nextUrl) {
if (!nextUrlList.contains(item)) { if (!nextUrlList.contains(item)) {
val data = ChapterData(nextUrlList = item) val data = ChapterData(nextUrl = item)
chapterDataList.add(data) chapterDataList.add(data)
} }
} }
var successCount = 0
for (item in chapterDataList) {
coroutineScope.launch {
AnalyzeUrl(ruleUrl = item.nextUrl, book = book).getResponse().execute().body()
}
}
} }
} }
private fun analyzeChapterList( private fun analyzeChapterList(
body: String, body: String,
baseUrl: String, baseUrl: String,

@ -4,5 +4,5 @@ import io.legado.app.data.entities.BookChapter
data class ChapterData<T>( data class ChapterData<T>(
var chapterList: List<BookChapter>? = null, var chapterList: List<BookChapter>? = null,
var nextUrlList: T var nextUrl: T
) )
Loading…
Cancel
Save