|
|
|
@ -26,31 +26,33 @@ object BookContent { |
|
|
|
|
bookChapter: BookChapter, |
|
|
|
|
bookSource: BookSource, |
|
|
|
|
baseUrl: String, |
|
|
|
|
nextChapterUrlF: String? = null |
|
|
|
|
nextChapterUrl: String? = null |
|
|
|
|
): String { |
|
|
|
|
body ?: throw Exception( |
|
|
|
|
appCtx.getString(R.string.error_get_web_content, baseUrl) |
|
|
|
|
) |
|
|
|
|
Debug.log(bookSource.bookSourceUrl, "≡获取成功:${baseUrl}") |
|
|
|
|
val mNextChapterUrl = if (!nextChapterUrl.isNullOrEmpty()) { |
|
|
|
|
nextChapterUrl |
|
|
|
|
} else { |
|
|
|
|
appDb.bookChapterDao.getChapter(book.bookUrl, bookChapter.index + 1)?.url |
|
|
|
|
} |
|
|
|
|
val content = StringBuilder() |
|
|
|
|
val nextUrlList = arrayListOf(baseUrl) |
|
|
|
|
val contentRule = bookSource.getContentRule() |
|
|
|
|
val analyzeRule = AnalyzeRule(book).setContent(body, baseUrl) |
|
|
|
|
analyzeRule.nextChapterUrl = mNextChapterUrl |
|
|
|
|
var contentData = analyzeContent( |
|
|
|
|
book, baseUrl, body, contentRule, bookChapter, bookSource |
|
|
|
|
book, baseUrl, body, contentRule, bookChapter, bookSource, mNextChapterUrl |
|
|
|
|
) |
|
|
|
|
content.append(contentData.content).append("\n") |
|
|
|
|
|
|
|
|
|
if (contentData.nextUrl.size == 1) { |
|
|
|
|
var nextUrl = contentData.nextUrl[0] |
|
|
|
|
val nextChapterUrl = if (!nextChapterUrlF.isNullOrEmpty()) |
|
|
|
|
nextChapterUrlF |
|
|
|
|
else |
|
|
|
|
appDb.bookChapterDao.getChapter(book.bookUrl, bookChapter.index + 1)?.url |
|
|
|
|
while (nextUrl.isNotEmpty() && !nextUrlList.contains(nextUrl)) { |
|
|
|
|
if (!nextChapterUrl.isNullOrEmpty() |
|
|
|
|
if (!mNextChapterUrl.isNullOrEmpty() |
|
|
|
|
&& NetworkUtils.getAbsoluteURL(baseUrl, nextUrl) |
|
|
|
|
== NetworkUtils.getAbsoluteURL(baseUrl, nextChapterUrl) |
|
|
|
|
== NetworkUtils.getAbsoluteURL(baseUrl, mNextChapterUrl) |
|
|
|
|
) break |
|
|
|
|
nextUrlList.add(nextUrl) |
|
|
|
|
AnalyzeUrl( |
|
|
|
@ -59,7 +61,14 @@ object BookContent { |
|
|
|
|
headerMapF = bookSource.getHeaderMap() |
|
|
|
|
).getStrResponse(bookSource.bookSourceUrl).body?.let { nextBody -> |
|
|
|
|
contentData = analyzeContent( |
|
|
|
|
book, nextUrl, nextBody, contentRule, bookChapter, bookSource, false |
|
|
|
|
book, |
|
|
|
|
nextUrl, |
|
|
|
|
nextBody, |
|
|
|
|
contentRule, |
|
|
|
|
bookChapter, |
|
|
|
|
bookSource, |
|
|
|
|
mNextChapterUrl, |
|
|
|
|
false |
|
|
|
|
) |
|
|
|
|
nextUrl = |
|
|
|
|
if (contentData.nextUrl.isNotEmpty()) contentData.nextUrl[0] else "" |
|
|
|
@ -81,7 +90,14 @@ object BookContent { |
|
|
|
|
headerMapF = bookSource.getHeaderMap() |
|
|
|
|
).getStrResponse(bookSource.bookSourceUrl).body?.let { |
|
|
|
|
contentData = analyzeContent( |
|
|
|
|
book, item.nextUrl, it, contentRule, bookChapter, bookSource, false |
|
|
|
|
book, |
|
|
|
|
item.nextUrl, |
|
|
|
|
it, |
|
|
|
|
contentRule, |
|
|
|
|
bookChapter, |
|
|
|
|
bookSource, |
|
|
|
|
mNextChapterUrl, |
|
|
|
|
false |
|
|
|
|
) |
|
|
|
|
item.content = contentData.content |
|
|
|
|
} |
|
|
|
@ -115,10 +131,12 @@ object BookContent { |
|
|
|
|
contentRule: ContentRule, |
|
|
|
|
chapter: BookChapter, |
|
|
|
|
bookSource: BookSource, |
|
|
|
|
nextChapterUrl: String?, |
|
|
|
|
printLog: Boolean = true |
|
|
|
|
): ContentData<List<String>> { |
|
|
|
|
val analyzeRule = AnalyzeRule(book) |
|
|
|
|
analyzeRule.setContent(body).setBaseUrl(baseUrl) |
|
|
|
|
analyzeRule.nextChapterUrl = nextChapterUrl |
|
|
|
|
val nextUrlList = arrayListOf<String>() |
|
|
|
|
analyzeRule.chapter = chapter |
|
|
|
|
//获取正文 |
|
|
|
|