pull/49/head
kunfei 5 years ago
parent 516ba657e5
commit 7b9df84545
  1. 20
      app/src/main/java/io/legado/app/model/rss/RssParserByRule.kt
  2. 44
      app/src/main/java/io/legado/app/model/webbook/BookChapterList.kt
  3. 17
      app/src/main/java/io/legado/app/model/webbook/BookList.kt

@ -45,16 +45,8 @@ object RssParserByRule {
val ruleLink = analyzeRule.splitSourceRule(rssSource.ruleLink ?: "") val ruleLink = analyzeRule.splitSourceRule(rssSource.ruleLink ?: "")
for ((index, item) in collections.withIndex()) { for ((index, item) in collections.withIndex()) {
getItem( getItem(
sourceUrl, sourceUrl, item, analyzeRule, index == 0, ruleTitle,
item, rulePubDate, ruleCategories, ruleDescription, ruleImage, ruleLink
analyzeRule,
index == 0,
ruleTitle,
rulePubDate,
ruleCategories,
ruleDescription,
ruleImage,
ruleLink
)?.let { )?.let {
it.origin = rssSource.sourceUrl it.origin = rssSource.sourceUrl
articleList.add(it) articleList.add(it)
@ -87,11 +79,19 @@ object RssParserByRule {
Debug.log(sourceUrl, "┌获取标题", log) Debug.log(sourceUrl, "┌获取标题", log)
rssArticle.title = analyzeRule.getString(ruleTitle) rssArticle.title = analyzeRule.getString(ruleTitle)
Debug.log(sourceUrl, "${rssArticle.title}", log) Debug.log(sourceUrl, "${rssArticle.title}", log)
Debug.log(sourceUrl, "┌获取时间", log)
rssArticle.pubDate = analyzeRule.getString(rulePubDate) rssArticle.pubDate = analyzeRule.getString(rulePubDate)
Debug.log(sourceUrl, "${rssArticle.pubDate}", log)
Debug.log(sourceUrl, "┌获取类别", log)
rssArticle.categories = analyzeRule.getString(ruleCategories) rssArticle.categories = analyzeRule.getString(ruleCategories)
Debug.log(sourceUrl, "${rssArticle.categories}", log)
rssArticle.description = analyzeRule.getString(ruleDescription) rssArticle.description = analyzeRule.getString(ruleDescription)
Debug.log(sourceUrl, "┌获取图片url", log)
rssArticle.image = analyzeRule.getString(ruleImage, true) rssArticle.image = analyzeRule.getString(ruleImage, true)
Debug.log(sourceUrl, "${rssArticle.image}", log)
Debug.log(sourceUrl, "┌获取文章链接", log)
rssArticle.link = analyzeRule.getString(ruleLink) rssArticle.link = analyzeRule.getString(ruleLink)
Debug.log(sourceUrl, "${rssArticle.link}", log)
if (rssArticle.title.isBlank()) { if (rssArticle.title.isBlank()) {
return null return null
} }

@ -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)
} }

@ -75,19 +75,10 @@ object BookList {
Debug.log(bookSource.bookSourceUrl, "└列表大小:${collections.size}") Debug.log(bookSource.bookSourceUrl, "└列表大小:${collections.size}")
for ((index, item) in collections.withIndex()) { for ((index, item) in collections.withIndex()) {
getSearchItem( getSearchItem(
item, item, analyzeRule, bookSource, baseUrl, index == 0,
analyzeRule, ruleName = ruleName, ruleBookUrl = ruleBookUrl, ruleAuthor = ruleAuthor,
bookSource, ruleCoverUrl = ruleCoverUrl, ruleIntro = ruleIntro, ruleKind = ruleKind,
baseUrl, ruleLastChapter = ruleLastChapter, ruleWordCount = ruleWordCount
index == 0,
ruleName = ruleName,
ruleBookUrl = ruleBookUrl,
ruleAuthor = ruleAuthor,
ruleCoverUrl = ruleCoverUrl,
ruleIntro = ruleIntro,
ruleKind = ruleKind,
ruleLastChapter = ruleLastChapter,
ruleWordCount = ruleWordCount
)?.let { searchBook -> )?.let { searchBook ->
if (baseUrl == searchBook.bookUrl) { if (baseUrl == searchBook.bookUrl) {
searchBook.infoHtml = body searchBook.infoHtml = body

Loading…
Cancel
Save