mirror of
https://github.com/gedoor/legado.git
synced 2024-08-30 09:23:26 +08:00
优化
This commit is contained in:
parent
046d54b3e6
commit
d5dd9df537
@ -76,6 +76,7 @@ class AnalyzeUrl(
|
||||
private var webJs: String? = null
|
||||
private val enabledCookieJar = source?.enabledCookieJar ?: false
|
||||
private val domain: String
|
||||
|
||||
// 服务器ID
|
||||
var serverID: Long? = null
|
||||
private set
|
||||
@ -373,7 +374,15 @@ class AnalyzeUrl(
|
||||
if (type != null) {
|
||||
return StrResponse(url, HexUtil.encodeHexStr(getByteArrayAwait()))
|
||||
}
|
||||
val concurrentRecord = fetchStart()
|
||||
var concurrentRecord: ConcurrentRecord?
|
||||
while (true) {
|
||||
try {
|
||||
concurrentRecord = fetchStart()
|
||||
break
|
||||
} catch (e: ConcurrentException) {
|
||||
delay(e.waitTime.toLong())
|
||||
}
|
||||
}
|
||||
try {
|
||||
setCookie()
|
||||
val strResponse: StrResponse
|
||||
@ -440,24 +449,6 @@ class AnalyzeUrl(
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 访问网站,返回StrResponse
|
||||
* 并发异常自动重试
|
||||
*/
|
||||
suspend fun getStrResponseConcurrentAwait(
|
||||
jsStr: String? = null,
|
||||
sourceRegex: String? = null,
|
||||
useWebView: Boolean = true,
|
||||
): StrResponse {
|
||||
while (true) {
|
||||
try {
|
||||
return getStrResponseAwait(jsStr, sourceRegex, useWebView)
|
||||
} catch (e: ConcurrentException) {
|
||||
delay(e.waitTime.toLong())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@JvmOverloads
|
||||
@Throws(ConcurrentException::class)
|
||||
fun getStrResponse(
|
||||
@ -475,7 +466,15 @@ class AnalyzeUrl(
|
||||
*/
|
||||
@Throws(ConcurrentException::class)
|
||||
suspend fun getResponseAwait(): Response {
|
||||
val concurrentRecord = fetchStart()
|
||||
var concurrentRecord: ConcurrentRecord?
|
||||
while (true) {
|
||||
try {
|
||||
concurrentRecord = fetchStart()
|
||||
break
|
||||
} catch (e: ConcurrentException) {
|
||||
delay(e.waitTime.toLong())
|
||||
}
|
||||
}
|
||||
try {
|
||||
setCookie()
|
||||
@Suppress("BlockingMethodInNonBlockingContext")
|
||||
|
@ -66,7 +66,7 @@ object BookChapterList {
|
||||
source = bookSource,
|
||||
ruleData = book,
|
||||
headerMapF = bookSource.getHeaderMap()
|
||||
).getStrResponseConcurrentAwait() //控制并发访问
|
||||
).getStrResponseAwait() //控制并发访问
|
||||
res.body?.let { nextBody ->
|
||||
chapterData = analyzeChapterList(
|
||||
book, nextUrl, nextUrl,
|
||||
@ -89,7 +89,7 @@ object BookChapterList {
|
||||
source = bookSource,
|
||||
ruleData = book,
|
||||
headerMapF = bookSource.getHeaderMap()
|
||||
).getStrResponseConcurrentAwait() //控制并发访问
|
||||
).getStrResponseAwait() //控制并发访问
|
||||
analyzeChapterList(
|
||||
book, urlStr, res.url,
|
||||
res.body!!, tocRule, listRule, bookSource, false
|
||||
|
@ -76,7 +76,7 @@ object BookContent {
|
||||
source = bookSource,
|
||||
ruleData = book,
|
||||
headerMapF = bookSource.getHeaderMap()
|
||||
).getStrResponseConcurrentAwait() //控制并发访问
|
||||
).getStrResponseAwait() //控制并发访问
|
||||
res.body?.let { nextBody ->
|
||||
contentData = analyzeContent(
|
||||
book, nextUrl, res.url, nextBody, contentRule,
|
||||
@ -99,7 +99,7 @@ object BookContent {
|
||||
source = bookSource,
|
||||
ruleData = book,
|
||||
headerMapF = bookSource.getHeaderMap()
|
||||
).getStrResponseConcurrentAwait() //控制并发访问
|
||||
).getStrResponseAwait() //控制并发访问
|
||||
analyzeContent(
|
||||
book, urlStr, res.url, res.body!!, contentRule,
|
||||
bookChapter, bookSource, mNextChapterUrl, false
|
||||
|
Loading…
Reference in New Issue
Block a user