|
|
@ -39,7 +39,7 @@ object BookChapterList { |
|
|
|
listRule = listRule.substring(1) |
|
|
|
listRule = listRule.substring(1) |
|
|
|
} |
|
|
|
} |
|
|
|
var chapterData = |
|
|
|
var chapterData = |
|
|
|
analyzeChapterList(body, baseUrl, tocRule, listRule, book, bookSource, printLog = true) |
|
|
|
analyzeChapterList(body, baseUrl, tocRule, listRule, book, bookSource, log = true) |
|
|
|
chapterData.chapterList?.let { |
|
|
|
chapterData.chapterList?.let { |
|
|
|
chapterList.addAll(it) |
|
|
|
chapterList.addAll(it) |
|
|
|
} |
|
|
|
} |
|
|
@ -48,19 +48,12 @@ object BookChapterList { |
|
|
|
while (nextUrl.isNotEmpty() && !nextUrlList.contains(nextUrl)) { |
|
|
|
while (nextUrl.isNotEmpty() && !nextUrlList.contains(nextUrl)) { |
|
|
|
nextUrlList.add(nextUrl) |
|
|
|
nextUrlList.add(nextUrl) |
|
|
|
AnalyzeUrl( |
|
|
|
AnalyzeUrl( |
|
|
|
ruleUrl = nextUrl, |
|
|
|
ruleUrl = nextUrl, book = book, headerMapF = bookSource.getHeaderMap() |
|
|
|
book = book, |
|
|
|
|
|
|
|
headerMapF = bookSource.getHeaderMap() |
|
|
|
|
|
|
|
).getResponseAwait() |
|
|
|
).getResponseAwait() |
|
|
|
.body()?.let { nextBody -> |
|
|
|
.body()?.let { nextBody -> |
|
|
|
chapterData = analyzeChapterList( |
|
|
|
chapterData = analyzeChapterList( |
|
|
|
nextBody, |
|
|
|
nextBody, nextUrl, tocRule, listRule, |
|
|
|
nextUrl, |
|
|
|
book, bookSource, log = false |
|
|
|
tocRule, |
|
|
|
|
|
|
|
listRule, |
|
|
|
|
|
|
|
book, |
|
|
|
|
|
|
|
bookSource, |
|
|
|
|
|
|
|
printLog = false |
|
|
|
|
|
|
|
) |
|
|
|
) |
|
|
|
nextUrl = if (chapterData.nextUrl.isNotEmpty()) |
|
|
|
nextUrl = if (chapterData.nextUrl.isNotEmpty()) |
|
|
|
chapterData.nextUrl[0] |
|
|
|
chapterData.nextUrl[0] |
|
|
@ -79,18 +72,13 @@ object BookChapterList { |
|
|
|
} |
|
|
|
} |
|
|
|
for (item in chapterDataList) { |
|
|
|
for (item in chapterDataList) { |
|
|
|
withContext(coroutineScope.coroutineContext) { |
|
|
|
withContext(coroutineScope.coroutineContext) { |
|
|
|
val nextResponse = AnalyzeUrl( |
|
|
|
val nextBody = AnalyzeUrl( |
|
|
|
ruleUrl = item.nextUrl, |
|
|
|
ruleUrl = item.nextUrl, |
|
|
|
book = book, |
|
|
|
book = book, |
|
|
|
headerMapF = bookSource.getHeaderMap() |
|
|
|
headerMapF = bookSource.getHeaderMap() |
|
|
|
).getResponseAwait() |
|
|
|
).getResponseAwait().body() ?: "" |
|
|
|
val nextChapterData = analyzeChapterList( |
|
|
|
val nextChapterData = analyzeChapterList( |
|
|
|
nextResponse.body() ?: "", |
|
|
|
nextBody, item.nextUrl, tocRule, listRule, book, bookSource |
|
|
|
item.nextUrl, |
|
|
|
|
|
|
|
tocRule, |
|
|
|
|
|
|
|
listRule, |
|
|
|
|
|
|
|
book, |
|
|
|
|
|
|
|
bookSource |
|
|
|
|
|
|
|
) |
|
|
|
) |
|
|
|
item.chapterList = nextChapterData.chapterList |
|
|
|
item.chapterList = nextChapterData.chapterList |
|
|
|
} |
|
|
|
} |
|
|
@ -128,7 +116,7 @@ object BookChapterList { |
|
|
|
book: Book, |
|
|
|
book: Book, |
|
|
|
bookSource: BookSource, |
|
|
|
bookSource: BookSource, |
|
|
|
getNextUrl: Boolean = true, |
|
|
|
getNextUrl: Boolean = true, |
|
|
|
printLog: Boolean = false |
|
|
|
log: Boolean = false |
|
|
|
): ChapterData<List<String>> { |
|
|
|
): ChapterData<List<String>> { |
|
|
|
val chapterList = arrayListOf<BookChapter>() |
|
|
|
val chapterList = arrayListOf<BookChapter>() |
|
|
|
val nextUrlList = arrayListOf<String>() |
|
|
|
val nextUrlList = arrayListOf<String>() |
|
|
@ -136,7 +124,7 @@ object BookChapterList { |
|
|
|
analyzeRule.setContent(body, baseUrl) |
|
|
|
analyzeRule.setContent(body, baseUrl) |
|
|
|
val nextTocRule = tocRule.nextTocUrl |
|
|
|
val nextTocRule = tocRule.nextTocUrl |
|
|
|
if (getNextUrl && !nextTocRule.isNullOrEmpty()) { |
|
|
|
if (getNextUrl && !nextTocRule.isNullOrEmpty()) { |
|
|
|
Debug.log(bookSource.bookSourceUrl, "┌获取目录下一页列表", printLog) |
|
|
|
Debug.log(bookSource.bookSourceUrl, "┌获取目录下一页列表", log) |
|
|
|
analyzeRule.getStringList(nextTocRule, true)?.let { |
|
|
|
analyzeRule.getStringList(nextTocRule, true)?.let { |
|
|
|
for (item in it) { |
|
|
|
for (item in it) { |
|
|
|
if (item != baseUrl) { |
|
|
|
if (item != baseUrl) { |
|
|
@ -147,14 +135,14 @@ object BookChapterList { |
|
|
|
Debug.log( |
|
|
|
Debug.log( |
|
|
|
bookSource.bookSourceUrl, |
|
|
|
bookSource.bookSourceUrl, |
|
|
|
"└" + TextUtils.join(",\n", nextUrlList), |
|
|
|
"└" + TextUtils.join(",\n", nextUrlList), |
|
|
|
printLog |
|
|
|
log |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
Debug.log(bookSource.bookSourceUrl, "┌获取目录列表", printLog) |
|
|
|
Debug.log(bookSource.bookSourceUrl, "┌获取目录列表", log) |
|
|
|
val elements = analyzeRule.getElements(listRule) |
|
|
|
val elements = analyzeRule.getElements(listRule) |
|
|
|
Debug.log(bookSource.bookSourceUrl, "└列表大小:${elements.size}", printLog) |
|
|
|
Debug.log(bookSource.bookSourceUrl, "└列表大小:${elements.size}", log) |
|
|
|
if (elements.isNotEmpty()) { |
|
|
|
if (elements.isNotEmpty()) { |
|
|
|
Debug.log(bookSource.bookSourceUrl, "┌获取首章名称", printLog) |
|
|
|
Debug.log(bookSource.bookSourceUrl, "┌获取首章名称", log) |
|
|
|
val nameRule = analyzeRule.splitSourceRule(tocRule.chapterName) |
|
|
|
val nameRule = analyzeRule.splitSourceRule(tocRule.chapterName) |
|
|
|
val urlRule = analyzeRule.splitSourceRule(tocRule.chapterUrl) |
|
|
|
val urlRule = analyzeRule.splitSourceRule(tocRule.chapterUrl) |
|
|
|
val vipRule = analyzeRule.splitSourceRule(tocRule.isVip) |
|
|
|
val vipRule = analyzeRule.splitSourceRule(tocRule.isVip) |
|
|
@ -176,9 +164,9 @@ object BookChapterList { |
|
|
|
chapterList.add(bookChapter) |
|
|
|
chapterList.add(bookChapter) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
Debug.log(bookSource.bookSourceUrl, "└${chapterList[0].title}", printLog) |
|
|
|
Debug.log(bookSource.bookSourceUrl, "└${chapterList[0].title}", log) |
|
|
|
Debug.log(bookSource.bookSourceUrl, "┌获取首章链接", printLog) |
|
|
|
Debug.log(bookSource.bookSourceUrl, "┌获取首章链接", log) |
|
|
|
Debug.log(bookSource.bookSourceUrl, "└${chapterList[0].url}", printLog) |
|
|
|
Debug.log(bookSource.bookSourceUrl, "└${chapterList[0].url}", log) |
|
|
|
} |
|
|
|
} |
|
|
|
return ChapterData(chapterList, nextUrlList) |
|
|
|
return ChapterData(chapterList, nextUrlList) |
|
|
|
} |
|
|
|
} |
|
|
|