|
|
@ -34,30 +34,28 @@ import javax.script.SimpleBindings |
|
|
|
@SuppressLint("DefaultLocale") |
|
|
|
@SuppressLint("DefaultLocale") |
|
|
|
class AnalyzeUrl( |
|
|
|
class AnalyzeUrl( |
|
|
|
var ruleUrl: String, |
|
|
|
var ruleUrl: String, |
|
|
|
key: String? = null, |
|
|
|
val key: String? = null, |
|
|
|
page: Int? = null, |
|
|
|
val page: Int? = null, |
|
|
|
speakText: String? = null, |
|
|
|
val speakText: String? = null, |
|
|
|
speakSpeed: Int? = null, |
|
|
|
val speakSpeed: Int? = null, |
|
|
|
headerMapF: Map<String, String>? = null, |
|
|
|
var baseUrl: String = "", |
|
|
|
baseUrl: String? = null, |
|
|
|
|
|
|
|
var useWebView: Boolean = false, |
|
|
|
var useWebView: Boolean = false, |
|
|
|
val book: BaseBook? = null, |
|
|
|
val book: BaseBook? = null, |
|
|
|
val chapter: BookChapter? = null |
|
|
|
val chapter: BookChapter? = null, |
|
|
|
|
|
|
|
headerMapF: Map<String, String>? = null |
|
|
|
) : JsExtensions { |
|
|
|
) : JsExtensions { |
|
|
|
companion object { |
|
|
|
companion object { |
|
|
|
private val pagePattern = Pattern.compile("<(.*?)>") |
|
|
|
private val pagePattern = Pattern.compile("<(.*?)>") |
|
|
|
private val jsonType = MediaType.parse("application/json; charset=utf-8") |
|
|
|
private val jsonType = MediaType.parse("application/json; charset=utf-8") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private var baseUrl: String = "" |
|
|
|
var url: String = "" |
|
|
|
lateinit var url: String |
|
|
|
|
|
|
|
private set |
|
|
|
|
|
|
|
private lateinit var urlHasQuery: String |
|
|
|
|
|
|
|
val headerMap = HashMap<String, String>() |
|
|
|
val headerMap = HashMap<String, String>() |
|
|
|
|
|
|
|
var body: String? = null |
|
|
|
|
|
|
|
private lateinit var urlHasQuery: String |
|
|
|
private var queryStr: String? = null |
|
|
|
private var queryStr: String? = null |
|
|
|
private val fieldMap = LinkedHashMap<String, String>() |
|
|
|
private val fieldMap = LinkedHashMap<String, String>() |
|
|
|
private var charset: String? = null |
|
|
|
private var charset: String? = null |
|
|
|
private var body: String? = null |
|
|
|
|
|
|
|
private var requestBody: RequestBody? = null |
|
|
|
private var requestBody: RequestBody? = null |
|
|
|
private var method = RequestMethod.GET |
|
|
|
private var method = RequestMethod.GET |
|
|
|
private val splitUrlRegex = Regex(",\\s*(?=\\{)") |
|
|
|
private val splitUrlRegex = Regex(",\\s*(?=\\{)") |
|
|
@ -65,9 +63,7 @@ class AnalyzeUrl( |
|
|
|
private var type: String? = null |
|
|
|
private var type: String? = null |
|
|
|
|
|
|
|
|
|
|
|
init { |
|
|
|
init { |
|
|
|
baseUrl?.let { |
|
|
|
baseUrl = baseUrl.split(splitUrlRegex, 1)[0] |
|
|
|
this.baseUrl = it.split(splitUrlRegex, 1)[0] |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
headerMapF?.let { |
|
|
|
headerMapF?.let { |
|
|
|
headerMap.putAll(it) |
|
|
|
headerMap.putAll(it) |
|
|
|
if (it.containsKey("proxy")) { |
|
|
|
if (it.containsKey("proxy")) { |
|
|
@ -76,19 +72,13 @@ class AnalyzeUrl( |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
//替换参数 |
|
|
|
//替换参数 |
|
|
|
analyzeJs(key, page, speakText, speakSpeed, book) |
|
|
|
analyzeJs() |
|
|
|
replaceKeyPageJs(key, page, speakText, speakSpeed, book) |
|
|
|
replaceKeyPageJs() |
|
|
|
//处理URL |
|
|
|
//处理URL |
|
|
|
initUrl() |
|
|
|
initUrl() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun analyzeJs( |
|
|
|
private fun analyzeJs() { |
|
|
|
key: String?, |
|
|
|
|
|
|
|
page: Int?, |
|
|
|
|
|
|
|
speakText: String?, |
|
|
|
|
|
|
|
speakSpeed: Int?, |
|
|
|
|
|
|
|
book: BaseBook?, |
|
|
|
|
|
|
|
) { |
|
|
|
|
|
|
|
val ruleList = arrayListOf<String>() |
|
|
|
val ruleList = arrayListOf<String>() |
|
|
|
var start = 0 |
|
|
|
var start = 0 |
|
|
|
var tmp: String |
|
|
|
var tmp: String |
|
|
@ -116,12 +106,12 @@ class AnalyzeUrl( |
|
|
|
ruleStr.startsWith("<js>") -> { |
|
|
|
ruleStr.startsWith("<js>") -> { |
|
|
|
ruleStr = ruleStr.substring(4, ruleStr.lastIndexOf("<")) |
|
|
|
ruleStr = ruleStr.substring(4, ruleStr.lastIndexOf("<")) |
|
|
|
ruleUrl = |
|
|
|
ruleUrl = |
|
|
|
evalJS(ruleStr, ruleUrl, page, key, speakText, speakSpeed, book) as String |
|
|
|
evalJS(ruleStr, ruleUrl) as String |
|
|
|
} |
|
|
|
} |
|
|
|
ruleStr.startsWith("@js", true) -> { |
|
|
|
ruleStr.startsWith("@js", true) -> { |
|
|
|
ruleStr = ruleStr.substring(4) |
|
|
|
ruleStr = ruleStr.substring(4) |
|
|
|
ruleUrl = |
|
|
|
ruleUrl = |
|
|
|
evalJS(ruleStr, ruleUrl, page, key, speakText, speakSpeed, book) as String |
|
|
|
evalJS(ruleStr, ruleUrl) as String |
|
|
|
} |
|
|
|
} |
|
|
|
else -> ruleUrl = ruleStr.replace("@result", ruleUrl) |
|
|
|
else -> ruleUrl = ruleStr.replace("@result", ruleUrl) |
|
|
|
} |
|
|
|
} |
|
|
@ -131,13 +121,7 @@ class AnalyzeUrl( |
|
|
|
/** |
|
|
|
/** |
|
|
|
* 替换关键字,页数,JS |
|
|
|
* 替换关键字,页数,JS |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private fun replaceKeyPageJs( |
|
|
|
private fun replaceKeyPageJs() { |
|
|
|
key: String?, |
|
|
|
|
|
|
|
page: Int?, |
|
|
|
|
|
|
|
speakText: String?, |
|
|
|
|
|
|
|
speakSpeed: Int?, |
|
|
|
|
|
|
|
book: BaseBook?, |
|
|
|
|
|
|
|
) { |
|
|
|
|
|
|
|
//page |
|
|
|
//page |
|
|
|
page?.let { |
|
|
|
page?.let { |
|
|
|
val matcher = pagePattern.matcher(ruleUrl) |
|
|
|
val matcher = pagePattern.matcher(ruleUrl) |
|
|
@ -215,7 +199,12 @@ class AnalyzeUrl( |
|
|
|
body = if (it is String) it else GSON.toJson(it) |
|
|
|
body = if (it is String) it else GSON.toJson(it) |
|
|
|
} |
|
|
|
} |
|
|
|
option.webView?.let { |
|
|
|
option.webView?.let { |
|
|
|
useWebView = it.toString().isNotEmpty() |
|
|
|
if (it.toString().isNotEmpty()) { |
|
|
|
|
|
|
|
useWebView = true |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
option.js?.let { |
|
|
|
|
|
|
|
evalJS(it) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -271,12 +260,7 @@ class AnalyzeUrl( |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private fun evalJS( |
|
|
|
private fun evalJS( |
|
|
|
jsStr: String, |
|
|
|
jsStr: String, |
|
|
|
result: Any?, |
|
|
|
result: Any? = null |
|
|
|
page: Int?, |
|
|
|
|
|
|
|
key: String?, |
|
|
|
|
|
|
|
speakText: String?, |
|
|
|
|
|
|
|
speakSpeed: Int?, |
|
|
|
|
|
|
|
book: BaseBook?, |
|
|
|
|
|
|
|
): Any { |
|
|
|
): Any { |
|
|
|
val bindings = SimpleBindings() |
|
|
|
val bindings = SimpleBindings() |
|
|
|
bindings["java"] = this |
|
|
|
bindings["java"] = this |
|
|
@ -428,7 +412,8 @@ class AnalyzeUrl( |
|
|
|
val webView: Any?, |
|
|
|
val webView: Any?, |
|
|
|
val headers: Any?, |
|
|
|
val headers: Any?, |
|
|
|
val body: Any?, |
|
|
|
val body: Any?, |
|
|
|
val type: String? |
|
|
|
val type: String?, |
|
|
|
|
|
|
|
val js: String? |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|