|
|
@ -10,6 +10,7 @@ import io.legado.app.help.JsExtensions |
|
|
|
import io.legado.app.utils.* |
|
|
|
import io.legado.app.utils.* |
|
|
|
import org.jsoup.nodes.Entities |
|
|
|
import org.jsoup.nodes.Entities |
|
|
|
import org.mozilla.javascript.NativeObject |
|
|
|
import org.mozilla.javascript.NativeObject |
|
|
|
|
|
|
|
import java.net.URL |
|
|
|
import java.util.* |
|
|
|
import java.util.* |
|
|
|
import java.util.regex.Pattern |
|
|
|
import java.util.regex.Pattern |
|
|
|
import javax.script.SimpleBindings |
|
|
|
import javax.script.SimpleBindings |
|
|
@ -25,6 +26,7 @@ class AnalyzeRule(var book: BaseBook? = null) : JsExtensions { |
|
|
|
var chapter: BookChapter? = null |
|
|
|
var chapter: BookChapter? = null |
|
|
|
private var content: Any? = null |
|
|
|
private var content: Any? = null |
|
|
|
private var baseUrl: String? = null |
|
|
|
private var baseUrl: String? = null |
|
|
|
|
|
|
|
private var baseURL: URL? = null |
|
|
|
private var isJSON: Boolean = false |
|
|
|
private var isJSON: Boolean = false |
|
|
|
private var isRegex: Boolean = false |
|
|
|
private var isRegex: Boolean = false |
|
|
|
|
|
|
|
|
|
|
@ -37,18 +39,28 @@ class AnalyzeRule(var book: BaseBook? = null) : JsExtensions { |
|
|
|
private var objectChangedJP = false |
|
|
|
private var objectChangedJP = false |
|
|
|
|
|
|
|
|
|
|
|
@Throws(Exception::class) |
|
|
|
@Throws(Exception::class) |
|
|
|
@JvmOverloads |
|
|
|
fun setContent(content: Any?): AnalyzeRule { |
|
|
|
fun setContent(content: Any?, baseUrl: String? = this.baseUrl): AnalyzeRule { |
|
|
|
|
|
|
|
if (content == null) throw AssertionError("Content cannot be null") |
|
|
|
if (content == null) throw AssertionError("Content cannot be null") |
|
|
|
isJSON = content.toString().isJson() |
|
|
|
isJSON = content.toString().isJson() |
|
|
|
this.content = content |
|
|
|
this.content = content |
|
|
|
this.baseUrl = baseUrl |
|
|
|
|
|
|
|
objectChangedXP = true |
|
|
|
objectChangedXP = true |
|
|
|
objectChangedJS = true |
|
|
|
objectChangedJS = true |
|
|
|
objectChangedJP = true |
|
|
|
objectChangedJP = true |
|
|
|
return this |
|
|
|
return this |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fun setBaseUrl(baseUrl: String?): AnalyzeRule { |
|
|
|
|
|
|
|
this.baseUrl = baseUrl |
|
|
|
|
|
|
|
baseUrl?.let { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
baseURL = URL(baseUrl.substringBefore(",")) |
|
|
|
|
|
|
|
} catch (e: Exception) { |
|
|
|
|
|
|
|
e.printStackTrace() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return this |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 获取XPath解析类 |
|
|
|
* 获取XPath解析类 |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -157,7 +169,7 @@ class AnalyzeRule(var book: BaseBook? = null) : JsExtensions { |
|
|
|
val urlList = ArrayList<String>() |
|
|
|
val urlList = ArrayList<String>() |
|
|
|
if (result is List<*>) { |
|
|
|
if (result is List<*>) { |
|
|
|
for (url in result as List<*>) { |
|
|
|
for (url in result as List<*>) { |
|
|
|
val absoluteURL = NetworkUtils.getAbsoluteURL(baseUrl, url.toString()) |
|
|
|
val absoluteURL = NetworkUtils.getAbsoluteURL(baseURL, url.toString()) |
|
|
|
if (!absoluteURL.isNullOrEmpty() && !urlList.contains(absoluteURL)) { |
|
|
|
if (!absoluteURL.isNullOrEmpty() && !urlList.contains(absoluteURL)) { |
|
|
|
urlList.add(absoluteURL) |
|
|
|
urlList.add(absoluteURL) |
|
|
|
} |
|
|
|
} |
|
|
@ -220,7 +232,11 @@ class AnalyzeRule(var book: BaseBook? = null) : JsExtensions { |
|
|
|
result.toString() |
|
|
|
result.toString() |
|
|
|
} |
|
|
|
} |
|
|
|
if (isUrl) { |
|
|
|
if (isUrl) { |
|
|
|
return NetworkUtils.getAbsoluteURL(baseUrl, str) ?: "" |
|
|
|
return if (str.isBlank()) { |
|
|
|
|
|
|
|
baseUrl ?: "" |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
NetworkUtils.getAbsoluteURL(baseURL, str) ?: "" |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return str |
|
|
|
return str |
|
|
|
} |
|
|
|
} |
|
|
|