|
|
|
@ -17,20 +17,20 @@ import retrofit2.Response |
|
|
|
|
object BookChapterList { |
|
|
|
|
|
|
|
|
|
suspend fun analyzeChapterList( |
|
|
|
|
coroutineScope: CoroutineScope, |
|
|
|
|
book: Book, |
|
|
|
|
response: Response<String>, |
|
|
|
|
bookSource: BookSource, |
|
|
|
|
analyzeUrl: AnalyzeUrl |
|
|
|
|
coroutineScope: CoroutineScope, |
|
|
|
|
book: Book, |
|
|
|
|
response: Response<String>, |
|
|
|
|
bookSource: BookSource, |
|
|
|
|
analyzeUrl: AnalyzeUrl |
|
|
|
|
): List<BookChapter> { |
|
|
|
|
var chapterList = arrayListOf<BookChapter>() |
|
|
|
|
val baseUrl: String = NetworkUtils.getUrl(response) |
|
|
|
|
val body: String? = response.body() |
|
|
|
|
body ?: throw Exception( |
|
|
|
|
App.INSTANCE.getString( |
|
|
|
|
R.string.error_get_web_content, |
|
|
|
|
baseUrl |
|
|
|
|
) |
|
|
|
|
App.INSTANCE.getString( |
|
|
|
|
R.string.error_get_web_content, |
|
|
|
|
baseUrl |
|
|
|
|
) |
|
|
|
|
) |
|
|
|
|
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "获取成功:$baseUrl") |
|
|
|
|
val tocRule = bookSource.getTocRule() |
|
|
|
@ -45,7 +45,7 @@ object BookChapterList { |
|
|
|
|
listRule = listRule.substring(1) |
|
|
|
|
} |
|
|
|
|
var chapterData = |
|
|
|
|
analyzeChapterList(body, baseUrl, tocRule, listRule, book, bookSource, printLog = true) |
|
|
|
|
analyzeChapterList(body, baseUrl, tocRule, listRule, book, bookSource, printLog = true) |
|
|
|
|
chapterData.chapterList?.let { |
|
|
|
|
chapterList.addAll(it) |
|
|
|
|
} |
|
|
|
@ -54,25 +54,25 @@ object BookChapterList { |
|
|
|
|
while (nextUrl.isNotEmpty() && !nextUrlList.contains(nextUrl)) { |
|
|
|
|
nextUrlList.add(nextUrl) |
|
|
|
|
AnalyzeUrl( |
|
|
|
|
ruleUrl = nextUrl, |
|
|
|
|
book = book, |
|
|
|
|
headerMapF = bookSource.getHeaderMap() |
|
|
|
|
ruleUrl = nextUrl, |
|
|
|
|
book = book, |
|
|
|
|
headerMapF = bookSource.getHeaderMap() |
|
|
|
|
).getResponseAsync().await() |
|
|
|
|
.body()?.let { nextBody -> |
|
|
|
|
chapterData = analyzeChapterList( |
|
|
|
|
nextBody, |
|
|
|
|
nextUrl, |
|
|
|
|
tocRule, |
|
|
|
|
listRule, |
|
|
|
|
book, |
|
|
|
|
bookSource |
|
|
|
|
) |
|
|
|
|
nextUrl = |
|
|
|
|
if (chapterData.nextUrl.isNotEmpty()) chapterData.nextUrl[0] else "" |
|
|
|
|
chapterData.chapterList?.let { |
|
|
|
|
chapterList.addAll(it) |
|
|
|
|
.body()?.let { nextBody -> |
|
|
|
|
chapterData = analyzeChapterList( |
|
|
|
|
nextBody, |
|
|
|
|
nextUrl, |
|
|
|
|
tocRule, |
|
|
|
|
listRule, |
|
|
|
|
book, |
|
|
|
|
bookSource |
|
|
|
|
) |
|
|
|
|
nextUrl = |
|
|
|
|
if (chapterData.nextUrl.isNotEmpty()) chapterData.nextUrl[0] else "" |
|
|
|
|
chapterData.chapterList?.let { |
|
|
|
|
chapterList.addAll(it) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} else if (chapterData.nextUrl.size > 1) { |
|
|
|
|
val chapterDataList = arrayListOf<ChapterData<String>>() |
|
|
|
@ -83,18 +83,18 @@ object BookChapterList { |
|
|
|
|
for (item in chapterDataList) { |
|
|
|
|
withContext(coroutineScope.coroutineContext) { |
|
|
|
|
val nextResponse = AnalyzeUrl( |
|
|
|
|
ruleUrl = item.nextUrl, |
|
|
|
|
book = book, |
|
|
|
|
headerMapF = bookSource.getHeaderMap() |
|
|
|
|
ruleUrl = item.nextUrl, |
|
|
|
|
book = book, |
|
|
|
|
headerMapF = bookSource.getHeaderMap() |
|
|
|
|
).getResponseAsync().await() |
|
|
|
|
val nextChapterData = analyzeChapterList( |
|
|
|
|
nextResponse.body() ?: "", |
|
|
|
|
item.nextUrl, |
|
|
|
|
tocRule, |
|
|
|
|
listRule, |
|
|
|
|
book, |
|
|
|
|
bookSource, |
|
|
|
|
getNextUrl = false |
|
|
|
|
nextResponse.body() ?: "", |
|
|
|
|
item.nextUrl, |
|
|
|
|
tocRule, |
|
|
|
|
listRule, |
|
|
|
|
book, |
|
|
|
|
bookSource, |
|
|
|
|
getNextUrl = false |
|
|
|
|
) |
|
|
|
|
item.chapterList = nextChapterData.chapterList |
|
|
|
|
} |
|
|
|
@ -125,14 +125,14 @@ object BookChapterList { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun analyzeChapterList( |
|
|
|
|
body: String, |
|
|
|
|
baseUrl: String, |
|
|
|
|
tocRule: TocRule, |
|
|
|
|
listRule: String, |
|
|
|
|
book: Book, |
|
|
|
|
bookSource: BookSource, |
|
|
|
|
getNextUrl: Boolean = true, |
|
|
|
|
printLog: Boolean = false |
|
|
|
|
body: String, |
|
|
|
|
baseUrl: String, |
|
|
|
|
tocRule: TocRule, |
|
|
|
|
listRule: String, |
|
|
|
|
book: Book, |
|
|
|
|
bookSource: BookSource, |
|
|
|
|
getNextUrl: Boolean = true, |
|
|
|
|
printLog: Boolean = false |
|
|
|
|
): ChapterData<List<String>> { |
|
|
|
|
val chapterList = arrayListOf<BookChapter>() |
|
|
|
|
val nextUrlList = arrayListOf<String>() |
|
|
|
@ -148,10 +148,10 @@ object BookChapterList { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
SourceDebug.printLog( |
|
|
|
|
bookSource.bookSourceUrl, |
|
|
|
|
1, |
|
|
|
|
TextUtils.join(",", nextUrlList), |
|
|
|
|
printLog |
|
|
|
|
bookSource.bookSourceUrl, |
|
|
|
|
1, |
|
|
|
|
TextUtils.join(",", nextUrlList), |
|
|
|
|
printLog |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
SourceDebug.printLog(bookSource.bookSourceUrl, 1, "解析目录列表", printLog) |
|
|
|
@ -173,10 +173,10 @@ object BookChapterList { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
SourceDebug.printLog( |
|
|
|
|
bookSource.bookSourceUrl, |
|
|
|
|
1, |
|
|
|
|
"${chapterList[0].title}${chapterList[0].url}", |
|
|
|
|
printLog |
|
|
|
|
bookSource.bookSourceUrl, |
|
|
|
|
1, |
|
|
|
|
"${chapterList[0].title}${chapterList[0].url}", |
|
|
|
|
printLog |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
return ChapterData(chapterList, nextUrlList) |
|
|
|
|