|
|
@ -35,7 +35,7 @@ object BookContent { |
|
|
|
val content = StringBuilder() |
|
|
|
val content = StringBuilder() |
|
|
|
val nextUrlList = arrayListOf(baseUrl) |
|
|
|
val nextUrlList = arrayListOf(baseUrl) |
|
|
|
val contentRule = bookSource.getContentRule() |
|
|
|
val contentRule = bookSource.getContentRule() |
|
|
|
var contentData = analyzeContent(body, contentRule, book, baseUrl) |
|
|
|
var contentData = analyzeContent(body, contentRule, book, bookSource, baseUrl) |
|
|
|
content.append(contentData.content) |
|
|
|
content.append(contentData.content) |
|
|
|
if (contentData.nextUrl.size == 1) { |
|
|
|
if (contentData.nextUrl.size == 1) { |
|
|
|
var nextUrl = contentData.nextUrl[0] |
|
|
|
var nextUrl = contentData.nextUrl[0] |
|
|
@ -55,12 +55,14 @@ object BookContent { |
|
|
|
headerMapF = bookSource.getHeaderMap() |
|
|
|
headerMapF = bookSource.getHeaderMap() |
|
|
|
).getResponseAsync().await() |
|
|
|
).getResponseAsync().await() |
|
|
|
.body()?.let { nextBody -> |
|
|
|
.body()?.let { nextBody -> |
|
|
|
contentData = analyzeContent(nextBody, contentRule, book, baseUrl) |
|
|
|
contentData = |
|
|
|
|
|
|
|
analyzeContent(nextBody, contentRule, book, bookSource, baseUrl, false) |
|
|
|
nextUrl = |
|
|
|
nextUrl = |
|
|
|
if (contentData.nextUrl.isNotEmpty()) contentData.nextUrl[0] else "" |
|
|
|
if (contentData.nextUrl.isNotEmpty()) contentData.nextUrl[0] else "" |
|
|
|
content.append(contentData.content) |
|
|
|
content.append(contentData.content) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
SourceDebug.printLog(bookSource.bookSourceUrl, "下一页数量${nextUrlList.size}") |
|
|
|
} else if (contentData.nextUrl.size > 1) { |
|
|
|
} else if (contentData.nextUrl.size > 1) { |
|
|
|
val contentDataList = arrayListOf<ContentData<String>>() |
|
|
|
val contentDataList = arrayListOf<ContentData<String>>() |
|
|
|
for (item in contentData.nextUrl) { |
|
|
|
for (item in contentData.nextUrl) { |
|
|
@ -69,18 +71,23 @@ object BookContent { |
|
|
|
} |
|
|
|
} |
|
|
|
for (item in contentDataList) { |
|
|
|
for (item in contentDataList) { |
|
|
|
withContext(coroutineScope.coroutineContext) { |
|
|
|
withContext(coroutineScope.coroutineContext) { |
|
|
|
val nextResponse = AnalyzeUrl( |
|
|
|
AnalyzeUrl( |
|
|
|
ruleUrl = item.nextUrl, |
|
|
|
ruleUrl = item.nextUrl, |
|
|
|
book = book, |
|
|
|
book = book, |
|
|
|
headerMapF = bookSource.getHeaderMap() |
|
|
|
headerMapF = bookSource.getHeaderMap() |
|
|
|
).getResponseAsync().await() |
|
|
|
).getResponseAsync().await() |
|
|
|
val nextContentData = analyzeContent( |
|
|
|
.body()?.let { |
|
|
|
nextResponse.body() ?: "", |
|
|
|
contentData = |
|
|
|
contentRule, |
|
|
|
analyzeContent( |
|
|
|
book, |
|
|
|
it, |
|
|
|
item.nextUrl |
|
|
|
contentRule, |
|
|
|
) |
|
|
|
book, |
|
|
|
item.content = nextContentData.content |
|
|
|
bookSource, |
|
|
|
|
|
|
|
item.nextUrl, |
|
|
|
|
|
|
|
false |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
item.content = contentData.content |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
for (item in contentDataList) { |
|
|
|
for (item in contentDataList) { |
|
|
@ -102,13 +109,20 @@ object BookContent { |
|
|
|
body: String, |
|
|
|
body: String, |
|
|
|
contentRule: ContentRule, |
|
|
|
contentRule: ContentRule, |
|
|
|
book: Book, |
|
|
|
book: Book, |
|
|
|
baseUrl: String |
|
|
|
bookSource: BookSource, |
|
|
|
|
|
|
|
baseUrl: String, |
|
|
|
|
|
|
|
printLog: Boolean = true |
|
|
|
): ContentData<List<String>> { |
|
|
|
): ContentData<List<String>> { |
|
|
|
val nextUrlList = arrayListOf<String>() |
|
|
|
val nextUrlList = arrayListOf<String>() |
|
|
|
val analyzeRule = AnalyzeRule(book) |
|
|
|
val analyzeRule = AnalyzeRule(book) |
|
|
|
analyzeRule.setContent(body, baseUrl) |
|
|
|
analyzeRule.setContent(body, baseUrl) |
|
|
|
analyzeRule.getStringList(contentRule.nextContentUrl ?: "", true)?.let { |
|
|
|
val nextUrlRule = contentRule.nextContentUrl |
|
|
|
nextUrlList.addAll(it) |
|
|
|
if (!nextUrlRule.isNullOrEmpty()) { |
|
|
|
|
|
|
|
SourceDebug.printLog(bookSource.bookSourceUrl, "获取下一页URL", printLog) |
|
|
|
|
|
|
|
analyzeRule.getStringList(nextUrlRule, true)?.let { |
|
|
|
|
|
|
|
nextUrlList.addAll(it) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
SourceDebug.printLog(bookSource.bookSourceUrl, nextUrlList.joinToString(",")) |
|
|
|
} |
|
|
|
} |
|
|
|
val content = analyzeRule.getString(contentRule.content ?: "")?.htmlFormat() ?: "" |
|
|
|
val content = analyzeRule.getString(contentRule.content ?: "")?.htmlFormat() ?: "" |
|
|
|
return ContentData(content, nextUrlList) |
|
|
|
return ContentData(content, nextUrlList) |
|
|
|