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