优化 #5612
This commit is contained in:
@@ -36,6 +36,7 @@ import io.legado.app.help.http.okHttpClient
|
|||||||
import io.legado.app.model.ReadAloud
|
import io.legado.app.model.ReadAloud
|
||||||
import io.legado.app.model.ReadBook
|
import io.legado.app.model.ReadBook
|
||||||
import io.legado.app.model.analyzeRule.AnalyzeUrl
|
import io.legado.app.model.analyzeRule.AnalyzeUrl
|
||||||
|
import io.legado.app.ui.book.read.page.entities.TextChapter
|
||||||
import io.legado.app.utils.FileUtils
|
import io.legado.app.utils.FileUtils
|
||||||
import io.legado.app.utils.MD5Utils
|
import io.legado.app.utils.MD5Utils
|
||||||
import io.legado.app.utils.printOnDebug
|
import io.legado.app.utils.printOnDebug
|
||||||
@@ -45,6 +46,7 @@ import kotlinx.coroutines.CancellationException
|
|||||||
import kotlinx.coroutines.Dispatchers.Main
|
import kotlinx.coroutines.Dispatchers.Main
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
import kotlinx.coroutines.channels.Channel
|
import kotlinx.coroutines.channels.Channel
|
||||||
|
import kotlinx.coroutines.currentCoroutineContext
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.ensureActive
|
import kotlinx.coroutines.ensureActive
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
@@ -58,7 +60,6 @@ import java.io.File
|
|||||||
import java.io.InputStream
|
import java.io.InputStream
|
||||||
import java.net.ConnectException
|
import java.net.ConnectException
|
||||||
import java.net.SocketTimeoutException
|
import java.net.SocketTimeoutException
|
||||||
import kotlin.coroutines.coroutineContext
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 在线朗读
|
* 在线朗读
|
||||||
@@ -196,8 +197,8 @@ class HttpReadAloudService : BaseReadAloudService(),
|
|||||||
.take(10)
|
.take(10)
|
||||||
.toList()
|
.toList()
|
||||||
contentList.forEach { content ->
|
contentList.forEach { content ->
|
||||||
coroutineContext.ensureActive()
|
currentCoroutineContext().ensureActive()
|
||||||
val fileName = md5SpeakFileName(content)
|
val fileName = md5SpeakFileName(content, textChapter)
|
||||||
val speakText = content.replace(AppPattern.notReadAloudRegex, "")
|
val speakText = content.replace(AppPattern.notReadAloudRegex, "")
|
||||||
if (speakText.isEmpty()) {
|
if (speakText.isEmpty()) {
|
||||||
createSilentSound(fileName)
|
createSilentSound(fileName)
|
||||||
@@ -265,8 +266,8 @@ class HttpReadAloudService : BaseReadAloudService(),
|
|||||||
.take(10)
|
.take(10)
|
||||||
.toList()
|
.toList()
|
||||||
contentList.forEach { content ->
|
contentList.forEach { content ->
|
||||||
coroutineContext.ensureActive()
|
currentCoroutineContext().ensureActive()
|
||||||
val fileName = md5SpeakFileName(content)
|
val fileName = md5SpeakFileName(content, textChapter)
|
||||||
val speakText = content.replace(AppPattern.notReadAloudRegex, "")
|
val speakText = content.replace(AppPattern.notReadAloudRegex, "")
|
||||||
val dataSourceFactory = createDataSourceFactory(httpTts, speakText)
|
val dataSourceFactory = createDataSourceFactory(httpTts, speakText)
|
||||||
val downloader = createDownloader(dataSourceFactory, fileName)
|
val downloader = createDownloader(dataSourceFactory, fileName)
|
||||||
@@ -331,10 +332,10 @@ class HttpReadAloudService : BaseReadAloudService(),
|
|||||||
speakSpeed = speechRate,
|
speakSpeed = speechRate,
|
||||||
source = httpTts,
|
source = httpTts,
|
||||||
readTimeout = 300 * 1000L,
|
readTimeout = 300 * 1000L,
|
||||||
coroutineContext = coroutineContext
|
coroutineContext = currentCoroutineContext()
|
||||||
)
|
)
|
||||||
var response = analyzeUrl.getResponseAwait()
|
var response = analyzeUrl.getResponseAwait()
|
||||||
coroutineContext.ensureActive()
|
currentCoroutineContext().ensureActive()
|
||||||
val checkJs = httpTts.loginCheckJs
|
val checkJs = httpTts.loginCheckJs
|
||||||
if (checkJs?.isNotBlank() == true) {
|
if (checkJs?.isNotBlank() == true) {
|
||||||
response = analyzeUrl.evalJS(checkJs, response) as Response
|
response = analyzeUrl.evalJS(checkJs, response) as Response
|
||||||
@@ -352,7 +353,7 @@ class HttpReadAloudService : BaseReadAloudService(),
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
coroutineContext.ensureActive()
|
currentCoroutineContext().ensureActive()
|
||||||
response.body.byteStream().let { stream ->
|
response.body.byteStream().let { stream ->
|
||||||
downloadErrorNo = 0
|
downloadErrorNo = 0
|
||||||
return stream
|
return stream
|
||||||
@@ -395,7 +396,7 @@ class HttpReadAloudService : BaseReadAloudService(),
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun md5SpeakFileName(content: String): String {
|
private fun md5SpeakFileName(content: String, textChapter: TextChapter? = this.textChapter): String {
|
||||||
return MD5Utils.md5Encode16(textChapter?.title ?: "") + "_" +
|
return MD5Utils.md5Encode16(textChapter?.title ?: "") + "_" +
|
||||||
MD5Utils.md5Encode16("${ReadAloud.httpTTS?.url}-|-$speechRate-|-$content")
|
MD5Utils.md5Encode16("${ReadAloud.httpTTS?.url}-|-$speechRate-|-$content")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user