pull/32/head
kunfei 5 years ago
parent 0d2ee98480
commit 26ffcc9a46
  1. 103
      app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt

@ -120,30 +120,29 @@ class AnalyzeRule(private var book: BaseBook? = null) {
content?.let { o -> content?.let { o ->
if (ruleList.isNotEmpty()) { if (ruleList.isNotEmpty()) {
if (ruleList.isNotEmpty()) result = o if (ruleList.isNotEmpty()) result = o
for (rule in ruleList) { for (sourceRule in ruleList) {
putRule(rule.putMap) putRule(sourceRule.putMap)
rule.makeUpRule(result) sourceRule.makeUpRule(result)
result?.let { result?.let {
if (rule.rule.isNotEmpty()) { if (sourceRule.rule.isNotEmpty()) {
when (rule.mode) { when (sourceRule.mode) {
Mode.Js -> result = evalJS(rule.rule, result) Mode.Js -> result = evalJS(sourceRule.rule, result)
Mode.Json -> result = Mode.Json -> result =
getAnalyzeByJSonPath(it).getStringList(rule.rule) getAnalyzeByJSonPath(it).getStringList(sourceRule.rule)
Mode.XPath -> result = Mode.XPath -> result =
getAnalyzeByXPath(it).getStringList(rule.rule) getAnalyzeByXPath(it).getStringList(sourceRule.rule)
Mode.Default -> result = getAnalyzeByJSoup(it).getStringList(rule.rule) Mode.Default -> result = getAnalyzeByJSoup(it).getStringList(sourceRule.rule)
else -> { else -> result = sourceRule.rule
}
} }
} }
if (rule.replaceRegex.isNotEmpty() && result is List<*>) { if (sourceRule.replaceRegex.isNotEmpty() && result is List<*>) {
val newList = ArrayList<String>() val newList = ArrayList<String>()
for (item in result as List<*>) { for (item in result as List<*>) {
newList.add(replaceRegex(item.toString(), rule)) newList.add(replaceRegex(item.toString(), sourceRule))
} }
result = newList result = newList
} else if (rule.replaceRegex.isNotEmpty()) { } else if (sourceRule.replaceRegex.isNotEmpty()) {
result = replaceRegex(result.toString(), rule) result = replaceRegex(result.toString(), sourceRule)
} }
} }
} }
@ -192,26 +191,25 @@ class AnalyzeRule(private var book: BaseBook? = null) {
var result: Any? = null var result: Any? = null
content?.let { o -> content?.let { o ->
if (ruleList.isNotEmpty()) result = o if (ruleList.isNotEmpty()) result = o
for (rule in ruleList) { for (sourceRule in ruleList) {
putRule(rule.putMap) putRule(sourceRule.putMap)
rule.makeUpRule(result) sourceRule.makeUpRule(result)
result?.let { result?.let {
if (rule.rule.isNotBlank()) { if (sourceRule.rule.isNotBlank()) {
when (rule.mode) { when (sourceRule.mode) {
Mode.Js -> result = evalJS(rule.rule, it) Mode.Js -> result = evalJS(sourceRule.rule, it)
Mode.Json -> result = getAnalyzeByJSonPath(it).getString(rule.rule) Mode.Json -> result = getAnalyzeByJSonPath(it).getString(sourceRule.rule)
Mode.XPath -> result = getAnalyzeByXPath(it).getString(rule.rule) Mode.XPath -> result = getAnalyzeByXPath(it).getString(sourceRule.rule)
Mode.Default -> result = if (isUrl) { Mode.Default -> result = if (isUrl) {
getAnalyzeByJSoup(it).getString0(rule.rule) getAnalyzeByJSoup(it).getString0(sourceRule.rule)
} else { } else {
getAnalyzeByJSoup(it).getString(rule.rule) getAnalyzeByJSoup(it).getString(sourceRule.rule)
}
else -> {
} }
else -> result = sourceRule.rule
} }
} }
if (rule.replaceRegex.isNotEmpty()) { if (sourceRule.replaceRegex.isNotEmpty()) {
result = replaceRegex(result.toString(), rule) result = replaceRegex(result.toString(), sourceRule)
} }
} }
} }
@ -235,19 +233,19 @@ class AnalyzeRule(private var book: BaseBook? = null) {
val ruleList = splitSourceRule(ruleStr) val ruleList = splitSourceRule(ruleStr)
content?.let { o -> content?.let { o ->
if (ruleList.isNotEmpty()) result = o if (ruleList.isNotEmpty()) result = o
for (rule in ruleList) { for (sourceRule in ruleList) {
putRule(rule.putMap) putRule(sourceRule.putMap)
result?.let { result?.let {
when (rule.mode) { when (sourceRule.mode) {
Mode.Regex -> result = Mode.Regex -> result =
AnalyzeByRegex.getElement(result.toString(), rule.rule.splitNotBlank("&&")) AnalyzeByRegex.getElement(result.toString(), sourceRule.rule.splitNotBlank("&&"))
Mode.Js -> result = evalJS(rule.rule, it) Mode.Js -> result = evalJS(sourceRule.rule, it)
Mode.Json -> result = getAnalyzeByJSonPath(it).getObject(rule.rule) Mode.Json -> result = getAnalyzeByJSonPath(it).getObject(sourceRule.rule)
Mode.XPath -> result = getAnalyzeByXPath(it).getElements(rule.rule) Mode.XPath -> result = getAnalyzeByXPath(it).getElements(sourceRule.rule)
else -> result = getAnalyzeByJSoup(it).getElements(rule.rule) else -> result = getAnalyzeByJSoup(it).getElements(sourceRule.rule)
} }
if (rule.replaceRegex.isNotEmpty()) { if (sourceRule.replaceRegex.isNotEmpty()) {
result = replaceRegex(result.toString(), rule) result = replaceRegex(result.toString(), sourceRule)
} }
} }
} }
@ -265,19 +263,19 @@ class AnalyzeRule(private var book: BaseBook? = null) {
val ruleList = splitSourceRule(ruleStr) val ruleList = splitSourceRule(ruleStr)
content?.let { o -> content?.let { o ->
if (ruleList.isNotEmpty()) result = o if (ruleList.isNotEmpty()) result = o
for (rule in ruleList) { for (sourceRule in ruleList) {
putRule(rule.putMap) putRule(sourceRule.putMap)
result?.let { result?.let {
when (rule.mode) { when (sourceRule.mode) {
Mode.Regex -> result = Mode.Regex -> result =
AnalyzeByRegex.getElements(result.toString(), rule.rule.splitNotBlank("&&")) AnalyzeByRegex.getElements(result.toString(), sourceRule.rule.splitNotBlank("&&"))
Mode.Js -> result = evalJS(rule.rule, result) Mode.Js -> result = evalJS(sourceRule.rule, result)
Mode.Json -> result = getAnalyzeByJSonPath(it).getList(rule.rule) Mode.Json -> result = getAnalyzeByJSonPath(it).getList(sourceRule.rule)
Mode.XPath -> result = getAnalyzeByXPath(it).getElements(rule.rule) Mode.XPath -> result = getAnalyzeByXPath(it).getElements(sourceRule.rule)
else -> result = getAnalyzeByJSoup(it).getElements(rule.rule) else -> result = getAnalyzeByJSoup(it).getElements(sourceRule.rule)
} }
if (rule.replaceRegex.isNotEmpty()) { if (sourceRule.replaceRegex.isNotEmpty()) {
result = replaceRegex(result.toString(), rule) result = replaceRegex(result.toString(), sourceRule)
} }
} }
} }
@ -370,11 +368,11 @@ class AnalyzeRule(private var book: BaseBook? = null) {
} }
vRuleStr.startsWith("@Json:", true) -> { vRuleStr.startsWith("@Json:", true) -> {
mode = Mode.Json mode = Mode.Json
isRegex = true
vRuleStr = vRuleStr.substring(6) vRuleStr = vRuleStr.substring(6)
} }
vRuleStr.startsWith(":") -> { vRuleStr.startsWith(":") -> {
mode = Mode.Regex mode = Mode.Regex
isRegex = true
vRuleStr = vRuleStr.substring(1) vRuleStr = vRuleStr.substring(1)
} }
else -> mode = else -> mode =
@ -477,7 +475,10 @@ class AnalyzeRule(private var book: BaseBook? = null) {
val regType = ruleType[j] val regType = ruleType[j]
if (regType > 0) { if (regType > 0) {
@Suppress("UNCHECKED_CAST") @Suppress("UNCHECKED_CAST")
infoVal.insert(0, (result as List<String>)[regType]) val resultList = result as List<String>
if (resultList.size > regType) {
infoVal.insert(0, resultList[regType])
}
} else if (regType < 0) { } else if (regType < 0) {
val jsEval: Any = evalJS(ruleParam[j], result) val jsEval: Any = evalJS(ruleParam[j], result)
if (jsEval is String) { if (jsEval is String) {

Loading…
Cancel
Save