|
|
@ -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, |
|
|
|