|
|
@ -71,28 +71,15 @@ object BookContent { |
|
|
|
) break |
|
|
|
) break |
|
|
|
nextUrlList.add(nextUrl) |
|
|
|
nextUrlList.add(nextUrl) |
|
|
|
coroutineContext.ensureActive() |
|
|
|
coroutineContext.ensureActive() |
|
|
|
val analyzeUrl = AnalyzeUrl( |
|
|
|
val res = AnalyzeUrl( |
|
|
|
mUrl = nextUrl, |
|
|
|
mUrl = nextUrl, |
|
|
|
source = bookSource, |
|
|
|
source = bookSource, |
|
|
|
ruleData = book, |
|
|
|
ruleData = book, |
|
|
|
headerMapF = bookSource.getHeaderMap() |
|
|
|
headerMapF = bookSource.getHeaderMap() |
|
|
|
) |
|
|
|
).getStrResponseConcurrentAwait() //控制并发访问 |
|
|
|
var res: StrResponse? = null |
|
|
|
res.body?.let { nextBody -> |
|
|
|
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( |
|
|
|
contentData = analyzeContent( |
|
|
|
book, nextUrl, res!!.url, nextBody, contentRule, |
|
|
|
book, nextUrl, res.url, nextBody, contentRule, |
|
|
|
bookChapter, bookSource, mNextChapterUrl, false |
|
|
|
bookChapter, bookSource, mNextChapterUrl, false |
|
|
|
) |
|
|
|
) |
|
|
|
nextUrl = |
|
|
|
nextUrl = |
|
|
@ -107,27 +94,14 @@ object BookContent { |
|
|
|
val asyncArray = Array(contentData.second.size) { |
|
|
|
val asyncArray = Array(contentData.second.size) { |
|
|
|
async(IO) { |
|
|
|
async(IO) { |
|
|
|
val urlStr = contentData.second[it] |
|
|
|
val urlStr = contentData.second[it] |
|
|
|
val analyzeUrl = AnalyzeUrl( |
|
|
|
val res = AnalyzeUrl( |
|
|
|
mUrl = urlStr, |
|
|
|
mUrl = urlStr, |
|
|
|
source = bookSource, |
|
|
|
source = bookSource, |
|
|
|
ruleData = book, |
|
|
|
ruleData = book, |
|
|
|
headerMapF = bookSource.getHeaderMap() |
|
|
|
headerMapF = bookSource.getHeaderMap() |
|
|
|
) |
|
|
|
).getStrResponseConcurrentAwait() //控制并发访问 |
|
|
|
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( |
|
|
|
analyzeContent( |
|
|
|
book, urlStr, res!!.url, res!!.body!!, contentRule, |
|
|
|
book, urlStr, res.url, res.body!!, contentRule, |
|
|
|
bookChapter, bookSource, mNextChapterUrl, false |
|
|
|
bookChapter, bookSource, mNextChapterUrl, false |
|
|
|
).first |
|
|
|
).first |
|
|
|
} |
|
|
|
} |
|
|
|