添加变量nextChapterUrl

pull/862/head
gedoor 4 years ago
parent 707d0fecf5
commit e254932ae7
  1. 2
      app/src/main/java/io/legado/app/model/Debug.kt
  2. 2
      app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt
  3. 38
      app/src/main/java/io/legado/app/model/webBook/BookContent.kt

@ -206,7 +206,7 @@ object Debug {
if (it.isNotEmpty()) {
log(debugSource, "︽目录页解析完成")
log(debugSource, showTime = false)
val nextChapterUrl = if (it.size > 1) it[1].url else null
val nextChapterUrl = it.getOrNull(1)?.url
contentDebug(scope, webBook, book, it[0], nextChapterUrl)
} else {
log(debugSource, "︽目录列表为空", state = -1)

@ -27,6 +27,7 @@ import kotlin.collections.HashMap
class AnalyzeRule(val ruleData: RuleDataInterface) : JsExtensions {
var book: BaseBook? = null
var chapter: BookChapter? = null
var nextChapterUrl: String? = null
private var content: Any? = null
private var baseUrl: String? = null
private var baseURL: URL? = null
@ -646,6 +647,7 @@ class AnalyzeRule(val ruleData: RuleDataInterface) : JsExtensions {
bindings["chapter"] = chapter
bindings["title"] = chapter?.title
bindings["src"] = content
bindings["nextChapterUrl"] = nextChapterUrl
return runBlocking {
SCRIPT_ENGINE.eval(jsStr, bindings)
}

@ -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
//获取正文

Loading…
Cancel
Save