pull/32/head
kunfei 5 years ago
parent da594a27b0
commit 7e43288185
  1. 2
      app/src/main/java/io/legado/app/model/WebBook.kt
  2. 16
      app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt

@ -18,7 +18,7 @@ class WebBook(private val bookSource: BookSource) {
bookSource.getSearchRule().searchUrl?.let { searchUrl -> bookSource.getSearchRule().searchUrl?.let { searchUrl ->
val analyzeUrl = AnalyzeUrl(searchUrl, key, page) val analyzeUrl = AnalyzeUrl(searchUrl, key, page)
val response = analyzeUrl.getResponseAsync().await() val response = analyzeUrl.getResponseAsync().await()
return@async BookList.analyzeBookList(response, bookSource, analyzeUrl) return@let BookList.analyzeBookList(response, bookSource, analyzeUrl)
} }
return@async arrayListOf<SearchBook>() return@async arrayListOf<SearchBook>()
} }

@ -41,8 +41,7 @@ class AnalyzeUrl(
private val jsonType = MediaType.parse("application/json; charset=utf-8") private val jsonType = MediaType.parse("application/json; charset=utf-8")
} }
lateinit var baseUrl: String private var baseUrl: String = ""
private set
lateinit var url: String lateinit var url: String
private set private set
var path: String? = null var path: String? = null
@ -101,14 +100,11 @@ class AnalyzeUrl(
if (ruleUrl.contains("{{") && ruleUrl.contains("}}")) { if (ruleUrl.contains("{{") && ruleUrl.contains("}}")) {
var jsEval: Any var jsEval: Any
val sb = StringBuffer(ruleUrl.length) val sb = StringBuffer(ruleUrl.length)
val simpleBindings = object : SimpleBindings() { val simpleBindings = SimpleBindings()
init { simpleBindings["baseUrl"] = baseUrl
this["baseUrl"] = baseUrl simpleBindings["page"] = page
this["page"] = page simpleBindings["key"] = key
this["key"] = key simpleBindings["book"] = book
this["book"] = book
}
}
val expMatcher = EXP_PATTERN.matcher(ruleUrl) val expMatcher = EXP_PATTERN.matcher(ruleUrl)
while (expMatcher.find()) { while (expMatcher.find()) {
jsEval = SCRIPT_ENGINE.eval(expMatcher.group(1), simpleBindings) jsEval = SCRIPT_ENGINE.eval(expMatcher.group(1), simpleBindings)

Loading…
Cancel
Save