This commit is contained in:
Horis
2025-05-16 15:54:45 +08:00
parent e97c37765c
commit 848c703d39
6 changed files with 38 additions and 20 deletions
@@ -52,22 +52,19 @@ import kotlin.coroutines.EmptyCoroutineContext
@Keep
@Suppress("unused", "RegExpRedundantEscape", "MemberVisibilityCanBePrivate")
class AnalyzeRule(
var ruleData: RuleDataInterface? = null,
private var ruleData: RuleDataInterface? = null,
private val source: BaseSource? = null,
private val preUpdateJs: Boolean = false
) : JsExtensions {
val book get() = ruleData as? BaseBook
val rssArticle get() = ruleData as? RssArticle
private val book get() = ruleData as? BaseBook
private val rssArticle get() = ruleData as? RssArticle
var chapter: BookChapter? = null
var nextChapterUrl: String? = null
var content: Any? = null
private set
var baseUrl: String? = null
private set
var redirectUrl: URL? = null
private set
private var chapter: BookChapter? = null
private var nextChapterUrl: String? = null
private var content: Any? = null
private var baseUrl: String? = null
private var redirectUrl: URL? = null
private var isJSON: Boolean = false
private var isRegex: Boolean = false
@@ -894,6 +891,21 @@ class AnalyzeRule(
return this
}
fun AnalyzeRule.setRuleData(ruleData: RuleDataInterface?): AnalyzeRule {
this.ruleData = ruleData
return this
}
fun AnalyzeRule.setNextChapterUrl(nextChapterUrl: String?): AnalyzeRule {
this.nextChapterUrl = nextChapterUrl
return this
}
fun AnalyzeRule.setChapter(chapter: BookChapter?): AnalyzeRule {
this.chapter = chapter
return this
}
}
}
@@ -8,6 +8,7 @@ import io.legado.app.exception.NoStackTraceException
import io.legado.app.model.Debug
import io.legado.app.model.analyzeRule.AnalyzeRule
import io.legado.app.model.analyzeRule.AnalyzeRule.Companion.setCoroutineContext
import io.legado.app.model.analyzeRule.AnalyzeRule.Companion.setRuleData
import io.legado.app.model.analyzeRule.RuleData
import io.legado.app.utils.NetworkUtils
import splitties.init.appCtx
@@ -101,7 +102,7 @@ object RssParserByRule {
ruleLink: List<AnalyzeRule.SourceRule>
): RssArticle? {
val rssArticle = RssArticle(variable = variable)
analyzeRule.ruleData = rssArticle
analyzeRule.setRuleData(rssArticle)
analyzeRule.setContent(item)
Debug.log(sourceUrl, "┌获取标题", log)
rssArticle.title = analyzeRule.getString(ruleTitle)
@@ -16,6 +16,7 @@ import io.legado.app.help.book.simulatedTotalChapterNum
import io.legado.app.help.config.AppConfig
import io.legado.app.model.Debug
import io.legado.app.model.analyzeRule.AnalyzeRule
import io.legado.app.model.analyzeRule.AnalyzeRule.Companion.setChapter
import io.legado.app.model.analyzeRule.AnalyzeRule.Companion.setCoroutineContext
import io.legado.app.model.analyzeRule.AnalyzeUrl
import io.legado.app.utils.isTrue
@@ -217,7 +218,7 @@ object BookChapterList {
coroutineContext.ensureActive()
analyzeRule.setContent(item)
val bookChapter = BookChapter(bookUrl = book.bookUrl, baseUrl = redirectUrl)
analyzeRule.chapter = bookChapter
analyzeRule.setChapter(bookChapter)
bookChapter.title = analyzeRule.getString(nameRule)
bookChapter.url = analyzeRule.getString(urlRule)
bookChapter.tag = analyzeRule.getString(upTimeRule)
@@ -13,7 +13,9 @@ import io.legado.app.help.book.BookHelp
import io.legado.app.help.config.AppConfig
import io.legado.app.model.Debug
import io.legado.app.model.analyzeRule.AnalyzeRule
import io.legado.app.model.analyzeRule.AnalyzeRule.Companion.setChapter
import io.legado.app.model.analyzeRule.AnalyzeRule.Companion.setCoroutineContext
import io.legado.app.model.analyzeRule.AnalyzeRule.Companion.setNextChapterUrl
import io.legado.app.model.analyzeRule.AnalyzeUrl
import io.legado.app.utils.HtmlFormatter
import io.legado.app.utils.NetworkUtils
@@ -58,8 +60,8 @@ object BookContent {
analyzeRule.setContent(body, baseUrl)
analyzeRule.setRedirectUrl(redirectUrl)
analyzeRule.setCoroutineContext(coroutineContext)
analyzeRule.chapter = bookChapter
analyzeRule.nextChapterUrl = mNextChapterUrl
analyzeRule.setChapter(bookChapter)
analyzeRule.setNextChapterUrl(mNextChapterUrl)
coroutineContext.ensureActive()
val titleRule = contentRule.title
if (!titleRule.isNullOrBlank()) {
@@ -170,9 +172,9 @@ object BookContent {
analyzeRule.setContent(body, baseUrl)
analyzeRule.setCoroutineContext(coroutineContext)
val rUrl = analyzeRule.setRedirectUrl(redirectUrl)
analyzeRule.nextChapterUrl = nextChapterUrl
analyzeRule.setNextChapterUrl(nextChapterUrl)
val nextUrlList = arrayListOf<String>()
analyzeRule.chapter = chapter
analyzeRule.setChapter(chapter)
//获取正文
var content = analyzeRule.getString(contentRule.content, unescape = false)
content = HtmlFormatter.formatKeepImg(content, rUrl)
@@ -13,6 +13,7 @@ import io.legado.app.help.source.getBookType
import io.legado.app.model.Debug
import io.legado.app.model.analyzeRule.AnalyzeRule
import io.legado.app.model.analyzeRule.AnalyzeRule.Companion.setCoroutineContext
import io.legado.app.model.analyzeRule.AnalyzeRule.Companion.setRuleData
import io.legado.app.model.analyzeRule.AnalyzeUrl
import io.legado.app.model.analyzeRule.RuleData
import io.legado.app.utils.GSON
@@ -170,7 +171,7 @@ object BookList {
book.originName = bookSource.bookSourceName
book.originOrder = bookSource.customOrder
book.type = bookSource.getBookType()
analyzeRule.ruleData = book
analyzeRule.setRuleData(book)
BookInfo.analyzeBookInfo(
book,
body,
@@ -212,7 +213,7 @@ object BookList {
searchBook.origin = bookSource.bookSourceUrl
searchBook.originName = bookSource.bookSourceName
searchBook.originOrder = bookSource.customOrder
analyzeRule.ruleData = searchBook
analyzeRule.setRuleData(searchBook)
analyzeRule.setContent(item)
coroutineContext.ensureActive()
Debug.log(bookSource.bookSourceUrl, "┌获取书名", log)
@@ -60,6 +60,7 @@ import io.legado.app.lib.theme.accentColor
import io.legado.app.model.ReadAloud
import io.legado.app.model.ReadBook
import io.legado.app.model.analyzeRule.AnalyzeRule
import io.legado.app.model.analyzeRule.AnalyzeRule.Companion.setChapter
import io.legado.app.model.analyzeRule.AnalyzeRule.Companion.setCoroutineContext
import io.legado.app.model.localBook.EpubFile
import io.legado.app.model.localBook.MobiFile
@@ -1289,7 +1290,7 @@ class ReadBookActivity : BaseReadBookActivity(),
val analyzeRule = AnalyzeRule(book, source)
analyzeRule.setCoroutineContext(coroutineContext)
analyzeRule.setBaseUrl(chapter.url)
analyzeRule.chapter = chapter
analyzeRule.setChapter(chapter)
analyzeRule.evalJS(payAction).toString()
}.onSuccess(IO) {
if (it.isAbsUrl()) {