pull/1296/head
gedoor 3 years ago
parent db068853f9
commit b9ec61989d
  1. 8
      app/src/main/java/io/legado/app/help/JsExtensions.kt
  2. 36
      app/src/main/java/io/legado/app/model/ReadBook.kt
  3. 2
      app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt
  4. 19
      app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt
  5. 6
      app/src/main/java/io/legado/app/model/rss/Rss.kt
  6. 4
      app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt
  7. 4
      app/src/main/java/io/legado/app/model/webBook/BookContent.kt
  8. 9
      app/src/main/java/io/legado/app/model/webBook/WebBook.kt

@ -40,7 +40,7 @@ interface JsExtensions {
return runBlocking {
kotlin.runCatching {
val analyzeUrl = AnalyzeUrl(urlStr)
analyzeUrl.getStrResponse(urlStr).body
analyzeUrl.getStrResponse().body
}.onFailure {
it.printStackTrace()
}.getOrElse {
@ -58,7 +58,7 @@ interface JsExtensions {
async(IO) {
val url = urlList[it]
val analyzeUrl = AnalyzeUrl(url)
analyzeUrl.getStrResponse(url)
analyzeUrl.getStrResponse()
}
}
val resArray = Array<StrResponse?>(urlList.size) {
@ -75,7 +75,7 @@ interface JsExtensions {
return runBlocking {
val analyzeUrl = AnalyzeUrl(urlStr)
kotlin.runCatching {
analyzeUrl.getStrResponse(urlStr)
analyzeUrl.getStrResponse()
}.onFailure {
it.printStackTrace()
}.getOrElse {
@ -89,7 +89,7 @@ interface JsExtensions {
val headerMap = GSON.fromJsonObject<Map<String, String>>(header)
val analyzeUrl = AnalyzeUrl(urlStr, headerMapF = headerMap)
kotlin.runCatching {
analyzeUrl.getStrResponse(urlStr)
analyzeUrl.getStrResponse()
}.onFailure {
it.printStackTrace()
}.getOrElse {

@ -136,14 +136,6 @@ object ReadBook : CoroutineScope by MainScope() {
saveRead()
callBack?.upView()
curPageChanged()
Coroutine.async {
//预下载
val maxChapterIndex = durChapterIndex + AppConfig.preDownloadNum
for (i in durChapterIndex.plus(2)..maxChapterIndex) {
delay(1000)
download(i)
}
}
return true
} else {
return false
@ -169,14 +161,6 @@ object ReadBook : CoroutineScope by MainScope() {
saveRead()
callBack?.upView()
curPageChanged()
Coroutine.async {
//预下载
val minChapterIndex = durChapterIndex - 5
for (i in durChapterIndex.minus(2) downTo minChapterIndex) {
delay(1000)
download(i)
}
}
return true
} else {
return false
@ -207,6 +191,7 @@ object ReadBook : CoroutineScope by MainScope() {
readAloud(!BaseReadAloudService.pause)
}
upReadStartTime()
preDownload()
}
/**
@ -436,6 +421,25 @@ object ReadBook : CoroutineScope by MainScope() {
}
}
/**
* 预下载
*/
private fun preDownload() {
Coroutine.async {
//预下载
val maxChapterIndex = durChapterIndex + AppConfig.preDownloadNum
for (i in durChapterIndex.plus(2)..maxChapterIndex) {
delay(1000)
download(i)
}
val minChapterIndex = durChapterIndex - 5
for (i in durChapterIndex.minus(2) downTo minChapterIndex) {
delay(1000)
download(i)
}
}
}
interface CallBack {
fun loadChapterList(book: Book)

@ -659,7 +659,7 @@ class AnalyzeRule(
return runBlocking {
kotlin.runCatching {
val analyzeUrl = AnalyzeUrl(urlStr, book = book, source = source)
analyzeUrl.getStrResponse(urlStr).body
analyzeUrl.getStrResponse().body
}.onFailure {
it.printStackTrace()
}.getOrElse {

@ -68,13 +68,17 @@ class AnalyzeUrl(
headerMap.remove("proxy")
}
}
//替换参数
//执行@js,<js></js>
analyzeJs()
//替换参数
replaceKeyPageJs()
//处理URL
initUrl()
}
/**
* 执行@js,<js></js>
*/
private fun analyzeJs() {
var start = 0
var tmp: String
@ -104,9 +108,7 @@ class AnalyzeUrl(
private fun replaceKeyPageJs() { //先替换内嵌规则再替换页数规则,避免内嵌规则中存在大于小于号时,规则被切错
//js
if (ruleUrl.contains("{{") && ruleUrl.contains("}}")) {
val analyze = RuleAnalyzer(ruleUrl) //创建解析
//替换所有内嵌{{js}}
val url = analyze.innerRule("{{", "}}") {
val jsEval = evalJS(it) ?: ""
@ -262,14 +264,13 @@ class AnalyzeUrl(
}
suspend fun getStrResponse(
tag: String,
jsStr: String? = null,
sourceRegex: String? = null,
): StrResponse {
if (type != null) {
return StrResponse(url, StringUtils.byteToHexString(getByteArray(tag)))
return StrResponse(url, StringUtils.byteToHexString(getByteArray()))
}
setCookie(tag)
setCookie(source?.getStoreUrl())
if (useWebView) {
val params = AjaxWebView.AjaxParams(url)
params.headerMap = headerMap
@ -277,7 +278,7 @@ class AnalyzeUrl(
params.javaScript = jsStr
params.sourceRegex = sourceRegex
params.postData = body?.toByteArray()
params.tag = tag
params.tag = source?.getStoreUrl()
return getWebViewSrc(params)
}
return getProxyClient(proxy).newCallStrResponse(retry) {
@ -296,8 +297,8 @@ class AnalyzeUrl(
}
}
suspend fun getByteArray(tag: String? = null): ByteArray {
setCookie(tag)
suspend fun getByteArray(): ByteArray {
setCookie(source?.getStoreUrl())
@Suppress("BlockingMethodInNonBlockingContext")
return getProxyClient(proxy).newCall(retry) {
addHeaders(headerMap)

@ -39,9 +39,10 @@ object Rss {
sortUrl,
page = page,
ruleData = ruleData,
source = rssSource,
headerMapF = rssSource.getHeaderMap()
)
val body = analyzeUrl.getStrResponse(rssSource.sourceUrl).body
val body = analyzeUrl.getStrResponse().body
return RssParserByRule.parseXML(sortName, sortUrl, body, rssSource, ruleData)
}
@ -66,9 +67,10 @@ object Rss {
rssArticle.link,
baseUrl = rssArticle.origin,
ruleData = rssArticle,
source = rssSource,
headerMapF = rssSource.getHeaderMap()
)
val body = analyzeUrl.getStrResponse(rssArticle.origin).body
val body = analyzeUrl.getStrResponse().body
Debug.log(rssSource.sourceUrl, "≡获取成功:${rssSource.sourceUrl}")
Debug.log(rssSource.sourceUrl, body, state = 20)
val analyzeRule = AnalyzeRule(rssArticle, rssSource)

@ -61,7 +61,7 @@ object BookChapterList {
book = book,
source = bookSource,
headerMapF = bookSource.getHeaderMap()
).getStrResponse(bookSource.bookSourceUrl).body?.let { nextBody ->
).getStrResponse().body?.let { nextBody ->
chapterData = analyzeChapterList(
scope, book, nextUrl, nextUrl,
nextBody, tocRule, listRule, bookSource
@ -84,7 +84,7 @@ object BookChapterList {
source = bookSource,
headerMapF = bookSource.getHeaderMap()
)
val res = analyzeUrl.getStrResponse(bookSource.bookSourceUrl)
val res = analyzeUrl.getStrResponse()
analyzeChapterList(
this, book, urlStr, res.url,
res.body!!, tocRule, listRule, bookSource, false

@ -68,7 +68,7 @@ object BookContent {
book = book,
source = bookSource,
headerMapF = bookSource.getHeaderMap()
).getStrResponse(bookSource.bookSourceUrl)
).getStrResponse()
res.body?.let { nextBody ->
contentData = analyzeContent(
book, nextUrl, res.url, nextBody, contentRule,
@ -92,7 +92,7 @@ object BookContent {
source = bookSource,
headerMapF = bookSource.getHeaderMap()
)
val res = analyzeUrl.getStrResponse(bookSource.bookSourceUrl)
val res = analyzeUrl.getStrResponse()
analyzeContent(
book, urlStr, res.url, res.body!!, contentRule,
bookChapter, bookSource, mNextChapterUrl, false

@ -74,7 +74,7 @@ object WebBook {
book = variableBook,
source = bookSource
)
var res = analyzeUrl.getStrResponse(bookSource.bookSourceUrl)
var res = analyzeUrl.getStrResponse()
//检测书源是否已登录
bookSource.loginCheckJs?.let { checkJs ->
if (checkJs.isNotBlank()) {
@ -124,7 +124,7 @@ object WebBook {
source = bookSource,
headerMapF = bookSource.getHeaderMap(true)
)
var res = analyzeUrl.getStrResponse(bookSource.bookSourceUrl)
var res = analyzeUrl.getStrResponse()
//检测书源是否已登录
bookSource.loginCheckJs?.let { checkJs ->
if (checkJs.isNotBlank()) {
@ -182,7 +182,7 @@ object WebBook {
source = bookSource,
headerMapF = bookSource.getHeaderMap(true)
)
var res = analyzeUrl.getStrResponse(bookSource.bookSourceUrl)
var res = analyzeUrl.getStrResponse()
//检测书源是否已登录
bookSource.loginCheckJs?.let { checkJs ->
if (checkJs.isNotBlank()) {
@ -239,7 +239,7 @@ object WebBook {
source = bookSource,
headerMapF = bookSource.getHeaderMap(true)
)
var res = analyzeUrl.getStrResponse(bookSource.bookSourceUrl)
var res = analyzeUrl.getStrResponse()
//检测书源是否已登录
bookSource.loginCheckJs?.let { checkJs ->
if (checkJs.isNotBlank()) {
@ -305,7 +305,6 @@ object WebBook {
headerMapF = bookSource.getHeaderMap(true)
)
var res = analyzeUrl.getStrResponse(
bookSource.bookSourceUrl,
jsStr = bookSource.getContentRule().webJs,
sourceRegex = bookSource.getContentRule().sourceRegex
)

Loading…
Cancel
Save