|
|
|
@ -35,7 +35,6 @@ class AnalyzeUrl( |
|
|
|
|
val speakText: String? = null, |
|
|
|
|
val speakSpeed: Int? = null, |
|
|
|
|
var baseUrl: String = "", |
|
|
|
|
var useWebView: Boolean = false, |
|
|
|
|
val book: BaseBook? = null, |
|
|
|
|
val chapter: BookChapter? = null, |
|
|
|
|
private val ruleData: RuleDataInterface? = null, |
|
|
|
@ -48,17 +47,18 @@ class AnalyzeUrl( |
|
|
|
|
private val accessTime = hashMapOf<String, FetchRecord>() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var url: String = "" |
|
|
|
|
val headerMap = HashMap<String, String>() |
|
|
|
|
var body: String? = null |
|
|
|
|
var type: String? = null |
|
|
|
|
private lateinit var urlHasQuery: String |
|
|
|
|
private var url: String = "" |
|
|
|
|
private var queryStr: String? = null |
|
|
|
|
private val fieldMap = LinkedHashMap<String, String>() |
|
|
|
|
private var charset: String? = null |
|
|
|
|
private var method = RequestMethod.GET |
|
|
|
|
private var proxy: String? = null |
|
|
|
|
private var retry: Int = 0 |
|
|
|
|
private var useWebView: Boolean = false |
|
|
|
|
private var webJs: String? = null |
|
|
|
|
|
|
|
|
|
init { |
|
|
|
|
val urlMatcher = paramPattern.matcher(baseUrl) |
|
|
|
@ -141,12 +141,13 @@ class AnalyzeUrl( |
|
|
|
|
*/ |
|
|
|
|
private fun initUrl() { //replaceKeyPageJs已经替换掉额外内容,此处url是基础形式,可以直接切首个‘,’之前字符串。 |
|
|
|
|
val urlMatcher = paramPattern.matcher(ruleUrl) |
|
|
|
|
urlHasQuery = if (urlMatcher.find()) ruleUrl.substring(0, urlMatcher.start()) else ruleUrl |
|
|
|
|
url = NetworkUtils.getAbsoluteURL(baseUrl, urlHasQuery) |
|
|
|
|
val urlNoOption = |
|
|
|
|
if (urlMatcher.find()) ruleUrl.substring(0, urlMatcher.start()) else ruleUrl |
|
|
|
|
url = NetworkUtils.getAbsoluteURL(baseUrl, urlNoOption) |
|
|
|
|
NetworkUtils.getBaseUrl(url)?.let { |
|
|
|
|
baseUrl = it |
|
|
|
|
} |
|
|
|
|
if (urlHasQuery.length != ruleUrl.length) { |
|
|
|
|
if (urlNoOption.length != ruleUrl.length) { |
|
|
|
|
GSON.fromJsonObject<UrlOption>(ruleUrl.substring(urlMatcher.end()))?.let { option -> |
|
|
|
|
option.method?.let { |
|
|
|
|
if (it.equals("POST", true)) method = RequestMethod.POST |
|
|
|
@ -171,6 +172,7 @@ class AnalyzeUrl( |
|
|
|
|
useWebView = true |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
webJs = option.webJs |
|
|
|
|
option.js?.let { |
|
|
|
|
evalJS(it) |
|
|
|
|
} |
|
|
|
@ -183,23 +185,23 @@ class AnalyzeUrl( |
|
|
|
|
} |
|
|
|
|
when (method) { |
|
|
|
|
RequestMethod.GET -> { |
|
|
|
|
if (!useWebView) { |
|
|
|
|
val pos = url.indexOf('?') |
|
|
|
|
if (pos != -1) { |
|
|
|
|
analyzeFields(url.substring(pos + 1)) |
|
|
|
|
url = url.substring(0, pos) |
|
|
|
|
} else body?.let { |
|
|
|
|
if (!it.isJson()) { |
|
|
|
|
analyzeFields(it) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
RequestMethod.POST -> { |
|
|
|
|
body?.let { |
|
|
|
|
RequestMethod.POST -> body?.let { |
|
|
|
|
if (!it.isJson()) { |
|
|
|
|
analyzeFields(it) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 解析QueryMap |
|
|
|
@ -416,7 +418,14 @@ class AnalyzeUrl( |
|
|
|
|
headerMap.forEach { (key, value) -> |
|
|
|
|
headers.addHeader(key, value) |
|
|
|
|
} |
|
|
|
|
return GlideUrl(urlHasQuery, headers.build()) |
|
|
|
|
return GlideUrl(getDirectUrl(), headers.build()) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun getDirectUrl(): String { |
|
|
|
|
val qs = fieldMap.map { |
|
|
|
|
"${it.key}=${it.value}" |
|
|
|
|
} |
|
|
|
|
return "$url?${qs.joinToString("&")}" |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun getUserAgent(): String { |
|
|
|
@ -431,6 +440,7 @@ class AnalyzeUrl( |
|
|
|
|
val method: String?, |
|
|
|
|
val charset: String?, |
|
|
|
|
val webView: Any?, |
|
|
|
|
val webJs: String?, |
|
|
|
|
val headers: Any?, |
|
|
|
|
val body: Any?, |
|
|
|
|
val type: String?, |
|
|
|
|