mirror of
https://github.com/gedoor/legado.git
synced 2024-08-30 09:23:26 +08:00
添加多页正文并发访问限制
This commit is contained in:
parent
118be1d2e4
commit
d876fd414e
@ -6,9 +6,11 @@ import io.legado.app.data.entities.Book
|
||||
import io.legado.app.data.entities.BookChapter
|
||||
import io.legado.app.data.entities.BookSource
|
||||
import io.legado.app.data.entities.rule.ContentRule
|
||||
import io.legado.app.exception.ConcurrentException
|
||||
import io.legado.app.exception.ContentEmptyException
|
||||
import io.legado.app.exception.NoStackTraceException
|
||||
import io.legado.app.help.book.BookHelp
|
||||
import io.legado.app.help.http.StrResponse
|
||||
import io.legado.app.model.Debug
|
||||
import io.legado.app.model.analyzeRule.AnalyzeRule
|
||||
import io.legado.app.model.analyzeRule.AnalyzeUrl
|
||||
@ -16,6 +18,7 @@ import io.legado.app.utils.HtmlFormatter
|
||||
import io.legado.app.utils.NetworkUtils
|
||||
import kotlinx.coroutines.Dispatchers.IO
|
||||
import kotlinx.coroutines.async
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.ensureActive
|
||||
import kotlinx.coroutines.withContext
|
||||
import splitties.init.appCtx
|
||||
@ -68,15 +71,28 @@ object BookContent {
|
||||
) break
|
||||
nextUrlList.add(nextUrl)
|
||||
coroutineContext.ensureActive()
|
||||
val res = AnalyzeUrl(
|
||||
val analyzeUrl = AnalyzeUrl(
|
||||
mUrl = nextUrl,
|
||||
source = bookSource,
|
||||
ruleData = book,
|
||||
headerMapF = bookSource.getHeaderMap()
|
||||
).getStrResponseAwait()
|
||||
res.body?.let { nextBody ->
|
||||
)
|
||||
var res: StrResponse? = null
|
||||
var isConcurrent: Boolean
|
||||
do {
|
||||
//控制并发访问
|
||||
isConcurrent = false
|
||||
try {
|
||||
res = analyzeUrl.getStrResponseAwait()
|
||||
} catch (e: ConcurrentException) {
|
||||
isConcurrent = true
|
||||
//如果是并发限制等待再次访问
|
||||
delay(e.waitTime.toLong())
|
||||
}
|
||||
} while (!isConcurrent)
|
||||
res!!.body?.let { nextBody ->
|
||||
contentData = analyzeContent(
|
||||
book, nextUrl, res.url, nextBody, contentRule,
|
||||
book, nextUrl, res!!.url, nextBody, contentRule,
|
||||
bookChapter, bookSource, mNextChapterUrl, false
|
||||
)
|
||||
nextUrl =
|
||||
@ -97,9 +113,21 @@ object BookContent {
|
||||
ruleData = book,
|
||||
headerMapF = bookSource.getHeaderMap()
|
||||
)
|
||||
val res = analyzeUrl.getStrResponseAwait()
|
||||
var res: StrResponse? = null
|
||||
var isConcurrent: Boolean
|
||||
do {
|
||||
//控制并发访问
|
||||
isConcurrent = false
|
||||
try {
|
||||
res = analyzeUrl.getStrResponseAwait()
|
||||
} catch (e: ConcurrentException) {
|
||||
isConcurrent = true
|
||||
//如果是并发限制等待再次访问
|
||||
delay(e.waitTime.toLong())
|
||||
}
|
||||
} while (!isConcurrent)
|
||||
analyzeContent(
|
||||
book, urlStr, res.url, res.body!!, contentRule,
|
||||
book, urlStr, res!!.url, res!!.body!!, contentRule,
|
||||
bookChapter, bookSource, mNextChapterUrl, false
|
||||
).first
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user