pull/1395/head
gedoor 3 years ago
parent d7e2df9c9b
commit e8a62a7c00
  1. 12
      app/src/main/java/io/legado/app/data/entities/BaseSource.kt
  2. 7
      app/src/main/java/io/legado/app/data/entities/BookSource.kt
  3. 20
      app/src/main/java/io/legado/app/data/entities/HttpTTS.kt
  4. 17
      app/src/main/java/io/legado/app/data/entities/RssSource.kt
  5. 10
      app/src/main/java/io/legado/app/help/BookSourceAnalyzer.kt
  6. 21
      app/src/main/java/io/legado/app/service/HttpReadAloudService.kt
  7. 7
      app/src/main/java/io/legado/app/ui/book/read/config/HttpTtsEditDialog.kt
  8. 4
      app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt
  9. 2
      app/src/main/java/io/legado/app/ui/login/SourceLoginDialog.kt
  10. 4
      app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt

@ -18,21 +18,15 @@ interface BaseSource : JsExtensions {
var concurrentRate: String? // 并发率
var loginUrl: String? // 登录地址
var loginUi: List<RowUi>? // 登录UI
var loginUi: String? // 登录UI
var header: String? // 请求头
fun getTag(): String
fun getKey(): String
fun getLoginUiStr(): String? {
return loginUi?.let {
GSON.toJson(it)
}
}
fun setLoginUi(uiJson: String?) {
loginUi = GSON.fromJsonArray(uiJson)
fun loginUi(): List<RowUi>? {
return GSON.fromJsonArray(loginUi)
}
fun getLoginJs(): String? {

@ -29,7 +29,7 @@ data class BookSource(
override var concurrentRate: String? = null, // 并发率
override var header: String? = null, // 请求头
override var loginUrl: String? = null, // 登录地址
override var loginUi: List<RowUi>? = null, // 登录UI
override var loginUi: String? = null, // 登录UI
var loginCheckJs: String? = null, // 登录检测js
var bookSourceComment: String? = null, // 注释
var lastUpdateTime: Long = 0, // 最后更新时间,用于排序
@ -154,11 +154,6 @@ data class BookSource(
private fun equal(a: String?, b: String?) = a == b || (a.isNullOrEmpty() && b.isNullOrEmpty())
class Converters {
@TypeConverter
fun loginUiRuleToString(loginUi: List<RowUi>?): String = GSON.toJson(loginUi)
@TypeConverter
fun stringToLoginRule(json: String?): List<RowUi>? = GSON.fromJsonArray(json)
@TypeConverter
fun exploreRuleToString(exploreRule: ExploreRule?): String = GSON.toJson(exploreRule)

@ -2,13 +2,10 @@ package io.legado.app.data.entities
import androidx.room.Entity
import androidx.room.PrimaryKey
import androidx.room.TypeConverter
import androidx.room.TypeConverters
import io.legado.app.data.entities.rule.RowUi
import io.legado.app.utils.GSON
import io.legado.app.utils.fromJsonArray
@TypeConverters(HttpTTS.Converters::class)
/**
* 在线朗读引擎
*/
@Entity(tableName = "httpTTS")
data class HttpTTS(
@PrimaryKey
@ -17,7 +14,7 @@ data class HttpTTS(
var url: String = "",
override var concurrentRate: String? = null,
override var loginUrl: String? = null,
override var loginUi: List<RowUi>? = null,
override var loginUi: String? = null,
override var header: String? = null,
var loginCheckJs: String? = null,
) : BaseSource {
@ -34,13 +31,4 @@ data class HttpTTS(
return this
}
class Converters {
@TypeConverter
fun loginUiRuleToString(loginUi: List<RowUi>?): String = GSON.toJson(loginUi)
@TypeConverter
fun stringToLoginRule(json: String?): List<RowUi>? = GSON.fromJsonArray(json)
}
}

@ -1,16 +1,14 @@
package io.legado.app.data.entities
import android.os.Parcelable
import androidx.room.*
import io.legado.app.data.entities.rule.RowUi
import androidx.room.Entity
import androidx.room.Index
import androidx.room.PrimaryKey
import io.legado.app.utils.ACache
import io.legado.app.utils.GSON
import io.legado.app.utils.fromJsonArray
import kotlinx.parcelize.Parcelize
import splitties.init.appCtx
@Parcelize
@TypeConverters(RssSource.Converters::class)
@Entity(tableName = "rssSources", indices = [(Index(value = ["sourceUrl"], unique = false))])
data class RssSource(
@PrimaryKey
@ -23,7 +21,7 @@ data class RssSource(
override var concurrentRate: String? = null, //并发率
override var header: String? = null, // 请求头
override var loginUrl: String? = null, // 登录地址
override var loginUi: List<RowUi>? = null, //登录UI
override var loginUi: String? = null, //登录UI
var loginCheckJs: String? = null, //登录检测js
var sortUrl: String? = null,
var singleUrl: Boolean = false,
@ -114,11 +112,4 @@ data class RssSource(
}
}
class Converters {
@TypeConverter
fun loginUiRuleToString(loginUi: List<RowUi>?): String = GSON.toJson(loginUi)
@TypeConverter
fun stringToLoginRule(json: String?): List<RowUi>? = GSON.fromJsonArray(json)
}
}

@ -41,7 +41,7 @@ object BookSourceAnalyzer {
bookSourceName = jsonItem.readString("bookSourceName") ?: ""
bookSourceGroup = jsonItem.readString("bookSourceGroup")
loginUrl = jsonItem.readString("loginUrl")
loginUi = GSON.fromJsonArray(jsonItem.readString("loginUi"))
loginUi = jsonItem.readString("loginUi")
loginCheckJs = jsonItem.readString("loginCheckJs")
bookSourceComment = jsonItem.readString("bookSourceComment") ?: ""
bookUrlPattern = jsonItem.readString("ruleBookUrlPattern")
@ -117,7 +117,11 @@ object BookSourceAnalyzer {
is String -> sourceAny.loginUrl.toString()
else -> JsonPath.parse(sourceAny.loginUrl).readString("url")
}
source.loginUi = sourceAny.loginUi
source.loginUi = if (sourceAny.loginUi is List<*>) {
GSON.toJson(sourceAny.loginUi)
} else {
sourceAny.loginUi?.toString()
}
source.loginCheckJs = sourceAny.loginCheckJs
source.bookSourceComment = sourceAny.bookSourceComment
source.lastUpdateTime = sourceAny.lastUpdateTime
@ -170,7 +174,7 @@ object BookSourceAnalyzer {
var concurrentRate: String? = null, // 并发率
var header: String? = null, // 请求头
var loginUrl: Any? = null, // 登录规则
var loginUi: List<RowUi>? = null, // 登录UI
var loginUi: Any? = null, // 登录UI
var loginCheckJs: String? = null, //登录检测js
var bookSourceComment: String? = "", //书源注释
var lastUpdateTime: Long = 0, // 最后更新时间,用于排序

@ -2,6 +2,7 @@ package io.legado.app.service
import android.app.PendingIntent
import android.media.MediaPlayer
import io.legado.app.R
import io.legado.app.constant.AppLog
import io.legado.app.constant.EventBus
import io.legado.app.help.AppConfig
@ -112,7 +113,7 @@ class HttpReadAloudService : BaseReadAloudService(),
try {
if (speakText.isEmpty()) {
ensureActive()
createSpeakFileAsMd5IfNotExist(fileName)
createSilentSound(fileName)
return@let
}
createSpeakCacheFile(fileName)
@ -143,19 +144,24 @@ class HttpReadAloudService : BaseReadAloudService(),
//任务取消,不处理
} catch (e: SocketTimeoutException) {
removeSpeakCacheFile(fileName)
toastOnUi("tts接口超时,尝试重新获取")
downloadAudio()
errorNo++
if (errorNo > 5) {
createSilentSound(fileName)
} else {
toastOnUi("tts接口超时,尝试重新获取")
downloadAudio()
}
} catch (e: ConnectException) {
removeSpeakCacheFile(fileName)
toastOnUi("tts接口网络错误\n${e.localizedMessage}")
} catch (e: IOException) {
removeSpeakCacheFile(fileName)
createSpeakFileAsMd5IfNotExist(fileName)
createSilentSound(fileName)
AppLog.put("tts文件解析错误")
toastOnUi("tts文件解析错误\n${e.localizedMessage}")
} catch (e: Exception) {
removeSpeakCacheFile(fileName)
createSpeakFileAsMd5IfNotExist(fileName)
createSilentSound(fileName)
AppLog.put("tts接口错误\n${e.localizedMessage}", e)
toastOnUi("tts接口错误\n${e.localizedMessage}")
e.printOnDebug()
@ -187,6 +193,11 @@ class HttpReadAloudService : BaseReadAloudService(),
return MD5Utils.md5Encode16(textChapter!!.title) + "_" + MD5Utils.md5Encode16("$url-|-$ttsConfig-|-$content")
}
private fun createSilentSound(fileName: String) {
val file = createSpeakFileAsMd5IfNotExist(fileName)
file.writeBytes(resources.openRawResource(R.raw.silent_sound).readBytes())
}
private fun hasSpeakFile(name: String) =
FileUtils.exist("${speakFilePath()}$name.mp3")

@ -73,7 +73,7 @@ class HttpTtsEditDialog() : BaseDialogFragment(R.layout.dialog_http_tts_edit),
binding.tvName.setText(httpTTS.name)
binding.tvUrl.setText(httpTTS.url)
binding.tvLoginUrl.setText(httpTTS.loginUrl)
binding.tvLoginUi.setText(httpTTS.getLoginUiStr())
binding.tvLoginUi.setText(httpTTS.loginUi)
binding.tvLoginCheckJs.setText(httpTTS.loginCheckJs)
binding.tvHeaders.setText(httpTTS.header)
}
@ -118,11 +118,10 @@ class HttpTtsEditDialog() : BaseDialogFragment(R.layout.dialog_http_tts_edit),
name = binding.tvName.text.toString(),
url = binding.tvUrl.text.toString(),
loginUrl = binding.tvLoginUrl.text?.toString(),
loginUi = binding.tvLoginUi.text?.toString(),
loginCheckJs = binding.tvLoginCheckJs.text?.toString(),
header = binding.tvHeaders.text?.toString()
).apply {
setLoginUi(binding.tvLoginUi.text?.toString())
}
)
}
private fun help() {

@ -201,7 +201,7 @@ class BookSourceEditActivity :
add(EditEntity("bookSourceGroup", source?.bookSourceGroup, R.string.source_group))
add(EditEntity("bookSourceComment", source?.bookSourceComment, R.string.comment))
add(EditEntity("loginUrl", source?.loginUrl, R.string.login_url))
add(EditEntity("loginUi", source?.getLoginUiStr(), R.string.login_ui))
add(EditEntity("loginUi", source?.loginUi, R.string.login_ui))
add(EditEntity("loginCheckJs", source?.loginCheckJs, R.string.login_check_js))
add(EditEntity("bookUrlPattern", source?.bookUrlPattern, R.string.book_url_pattern))
add(EditEntity("header", source?.header, R.string.source_http_header))
@ -300,7 +300,7 @@ class BookSourceEditActivity :
"bookSourceName" -> source.bookSourceName = it.value ?: ""
"bookSourceGroup" -> source.bookSourceGroup = it.value
"loginUrl" -> source.loginUrl = it.value
"loginUi" -> source.setLoginUi(it.value)
"loginUi" -> source.loginUi = it.value
"loginCheckJs" -> source.loginCheckJs = it.value
"bookUrlPattern" -> source.bookUrlPattern = it.value
"header" -> source.header = it.value

@ -43,7 +43,7 @@ class SourceLoginDialog : BaseDialogFragment(R.layout.dialog_login) {
binding.toolBar.setBackgroundColor(primaryColor)
binding.toolBar.title = getString(R.string.login_source, source.getTag())
val loginInfo = source.getLoginInfoMap()
val loginUi = source.loginUi
val loginUi = source.loginUi()
loginUi?.forEachIndexed { index, rowUi ->
when (rowUi.type) {
"text" -> ItemSourceEditBinding.inflate(layoutInflater, binding.root, false).let {

@ -160,7 +160,7 @@ class RssSourceEditActivity :
add(EditEntity("sourceGroup", source?.sourceGroup, R.string.source_group))
add(EditEntity("sourceComment", source?.sourceComment, R.string.comment))
add(EditEntity("loginUrl", source?.loginUrl, R.string.login_url))
add(EditEntity("loginUi", source?.getLoginUiStr(), R.string.login_ui))
add(EditEntity("loginUi", source?.loginUi, R.string.login_ui))
add(EditEntity("loginCheckJs", source?.loginCheckJs, R.string.login_check_js))
add(EditEntity("header", source?.header, R.string.source_http_header))
add(
@ -196,7 +196,7 @@ class RssSourceEditActivity :
"sourceGroup" -> source.sourceGroup = it.value
"sourceComment" -> source.sourceComment = it.value
"loginUrl" -> source.loginUrl = it.value
"loginUi" -> source.setLoginUi(it.value)
"loginUi" -> source.loginUi = it.value
"loginCheckJs" -> source.loginCheckJs = it.value
"header" -> source.header = it.value
"concurrentRate" -> source.concurrentRate = it.value

Loading…
Cancel
Save