|
|
|
@ -31,7 +31,7 @@ object BookChapterList { |
|
|
|
|
App.INSTANCE.getString(R.string.error_get_web_content, baseUrl) |
|
|
|
|
) |
|
|
|
|
Debug.log(bookSource.bookSourceUrl, "≡获取成功:${baseUrl}") |
|
|
|
|
val analyzeRule = AnalyzeRule(book) |
|
|
|
|
|
|
|
|
|
val tocRule = bookSource.getTocRule() |
|
|
|
|
val nextUrlList = arrayListOf(baseUrl) |
|
|
|
|
var reverse = false |
|
|
|
@ -45,8 +45,7 @@ object BookChapterList { |
|
|
|
|
} |
|
|
|
|
var chapterData = |
|
|
|
|
analyzeChapterList( |
|
|
|
|
analyzeRule.setContent(body, baseUrl), |
|
|
|
|
book.bookUrl, baseUrl, tocRule, listRule, bookSource, log = true |
|
|
|
|
book, baseUrl, body, tocRule, listRule, bookSource, log = true |
|
|
|
|
) |
|
|
|
|
chapterData.chapterList?.let { |
|
|
|
|
chapterList.addAll(it) |
|
|
|
@ -67,8 +66,7 @@ object BookChapterList { |
|
|
|
|
).getResponseAwait() |
|
|
|
|
.body?.let { nextBody -> |
|
|
|
|
chapterData = analyzeChapterList( |
|
|
|
|
analyzeRule.setContent(nextBody, nextUrl), |
|
|
|
|
book.bookUrl, nextUrl, tocRule, listRule, bookSource |
|
|
|
|
book, nextUrl, nextBody, tocRule, listRule, bookSource |
|
|
|
|
) |
|
|
|
|
nextUrl = if (chapterData.nextUrl.isNotEmpty()) { |
|
|
|
|
chapterData.nextUrl[0] |
|
|
|
@ -100,7 +98,6 @@ object BookChapterList { |
|
|
|
|
item, |
|
|
|
|
book, |
|
|
|
|
bookSource, |
|
|
|
|
analyzeRule, |
|
|
|
|
tocRule, |
|
|
|
|
listRule, |
|
|
|
|
chapterList, |
|
|
|
@ -123,7 +120,6 @@ object BookChapterList { |
|
|
|
|
chapterData: ChapterData<String>, |
|
|
|
|
book: Book, |
|
|
|
|
bookSource: BookSource, |
|
|
|
|
analyzeRule: AnalyzeRule, |
|
|
|
|
tocRule: TocRule, |
|
|
|
|
listRule: String, |
|
|
|
|
chapterList: ArrayList<BookChapter>, |
|
|
|
@ -136,10 +132,9 @@ object BookChapterList { |
|
|
|
|
ruleUrl = chapterData.nextUrl, |
|
|
|
|
book = book, |
|
|
|
|
headerMapF = bookSource.getHeaderMap() |
|
|
|
|
).getResponseAwait().body |
|
|
|
|
).getResponseAwait().body ?: throw Exception("${chapterData.nextUrl}, 下载失败") |
|
|
|
|
val nextChapterData = analyzeChapterList( |
|
|
|
|
analyzeRule.setContent(nextBody, chapterData.nextUrl), |
|
|
|
|
book.bookUrl, chapterData.nextUrl, tocRule, listRule, bookSource, |
|
|
|
|
book, chapterData.nextUrl, nextBody, tocRule, listRule, bookSource, |
|
|
|
|
false |
|
|
|
|
) |
|
|
|
|
synchronized(chapterDataList) { |
|
|
|
@ -203,15 +198,17 @@ object BookChapterList { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun analyzeChapterList( |
|
|
|
|
analyzeRule: AnalyzeRule, |
|
|
|
|
bookUrl: String, |
|
|
|
|
book: Book, |
|
|
|
|
baseUrl: String, |
|
|
|
|
body: String, |
|
|
|
|
tocRule: TocRule, |
|
|
|
|
listRule: String, |
|
|
|
|
bookSource: BookSource, |
|
|
|
|
getNextUrl: Boolean = true, |
|
|
|
|
log: Boolean = false |
|
|
|
|
): ChapterData<List<String>> { |
|
|
|
|
val analyzeRule = AnalyzeRule(book) |
|
|
|
|
analyzeRule.setContent(body, baseUrl) |
|
|
|
|
val chapterList = arrayListOf<BookChapter>() |
|
|
|
|
val nextUrlList = arrayListOf<String>() |
|
|
|
|
val nextTocRule = tocRule.nextTocUrl |
|
|
|
@ -242,7 +239,7 @@ object BookChapterList { |
|
|
|
|
var isVip: String? |
|
|
|
|
for (item in elements) { |
|
|
|
|
analyzeRule.setContent(item) |
|
|
|
|
val bookChapter = BookChapter(bookUrl = bookUrl) |
|
|
|
|
val bookChapter = BookChapter(bookUrl = book.bookUrl) |
|
|
|
|
analyzeRule.chapter = bookChapter |
|
|
|
|
bookChapter.title = analyzeRule.getString(nameRule) |
|
|
|
|
bookChapter.url = analyzeRule.getString(urlRule, true) |
|
|
|
|