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