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. 17
      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 concurrentRate: String? // 并发率
var loginUrl: String? // 登录地址 var loginUrl: String? // 登录地址
var loginUi: List<RowUi>? // 登录UI var loginUi: String? // 登录UI
var header: String? // 请求头 var header: String? // 请求头
fun getTag(): String fun getTag(): String
fun getKey(): String fun getKey(): String
fun getLoginUiStr(): String? { fun loginUi(): List<RowUi>? {
return loginUi?.let { return GSON.fromJsonArray(loginUi)
GSON.toJson(it)
}
}
fun setLoginUi(uiJson: String?) {
loginUi = GSON.fromJsonArray(uiJson)
} }
fun getLoginJs(): String? { fun getLoginJs(): String? {

@ -29,7 +29,7 @@ data class BookSource(
override var concurrentRate: String? = null, // 并发率 override var concurrentRate: String? = null, // 并发率
override var header: String? = null, // 请求头 override var header: String? = null, // 请求头
override var loginUrl: 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 loginCheckJs: String? = null, // 登录检测js
var bookSourceComment: String? = null, // 注释 var bookSourceComment: String? = null, // 注释
var lastUpdateTime: Long = 0, // 最后更新时间,用于排序 var lastUpdateTime: Long = 0, // 最后更新时间,用于排序
@ -154,11 +154,6 @@ data class BookSource(
private fun equal(a: String?, b: String?) = a == b || (a.isNullOrEmpty() && b.isNullOrEmpty()) private fun equal(a: String?, b: String?) = a == b || (a.isNullOrEmpty() && b.isNullOrEmpty())
class Converters { class Converters {
@TypeConverter
fun loginUiRuleToString(loginUi: List<RowUi>?): String = GSON.toJson(loginUi)
@TypeConverter
fun stringToLoginRule(json: String?): List<RowUi>? = GSON.fromJsonArray(json)
@TypeConverter @TypeConverter
fun exploreRuleToString(exploreRule: ExploreRule?): String = GSON.toJson(exploreRule) 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.Entity
import androidx.room.PrimaryKey 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") @Entity(tableName = "httpTTS")
data class HttpTTS( data class HttpTTS(
@PrimaryKey @PrimaryKey
@ -17,7 +14,7 @@ data class HttpTTS(
var url: String = "", var url: String = "",
override var concurrentRate: String? = null, override var concurrentRate: String? = null,
override var loginUrl: String? = null, override var loginUrl: String? = null,
override var loginUi: List<RowUi>? = null, override var loginUi: String? = null,
override var header: String? = null, override var header: String? = null,
var loginCheckJs: String? = null, var loginCheckJs: String? = null,
) : BaseSource { ) : BaseSource {
@ -34,13 +31,4 @@ data class HttpTTS(
return this 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 package io.legado.app.data.entities
import android.os.Parcelable import android.os.Parcelable
import androidx.room.* import androidx.room.Entity
import io.legado.app.data.entities.rule.RowUi import androidx.room.Index
import androidx.room.PrimaryKey
import io.legado.app.utils.ACache import io.legado.app.utils.ACache
import io.legado.app.utils.GSON
import io.legado.app.utils.fromJsonArray
import kotlinx.parcelize.Parcelize import kotlinx.parcelize.Parcelize
import splitties.init.appCtx import splitties.init.appCtx
@Parcelize @Parcelize
@TypeConverters(RssSource.Converters::class)
@Entity(tableName = "rssSources", indices = [(Index(value = ["sourceUrl"], unique = false))]) @Entity(tableName = "rssSources", indices = [(Index(value = ["sourceUrl"], unique = false))])
data class RssSource( data class RssSource(
@PrimaryKey @PrimaryKey
@ -23,7 +21,7 @@ data class RssSource(
override var concurrentRate: String? = null, //并发率 override var concurrentRate: String? = null, //并发率
override var header: String? = null, // 请求头 override var header: String? = null, // 请求头
override var loginUrl: 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 loginCheckJs: String? = null, //登录检测js
var sortUrl: String? = null, var sortUrl: String? = null,
var singleUrl: Boolean = false, 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") ?: "" bookSourceName = jsonItem.readString("bookSourceName") ?: ""
bookSourceGroup = jsonItem.readString("bookSourceGroup") bookSourceGroup = jsonItem.readString("bookSourceGroup")
loginUrl = jsonItem.readString("loginUrl") loginUrl = jsonItem.readString("loginUrl")
loginUi = GSON.fromJsonArray(jsonItem.readString("loginUi")) loginUi = jsonItem.readString("loginUi")
loginCheckJs = jsonItem.readString("loginCheckJs") loginCheckJs = jsonItem.readString("loginCheckJs")
bookSourceComment = jsonItem.readString("bookSourceComment") ?: "" bookSourceComment = jsonItem.readString("bookSourceComment") ?: ""
bookUrlPattern = jsonItem.readString("ruleBookUrlPattern") bookUrlPattern = jsonItem.readString("ruleBookUrlPattern")
@ -117,7 +117,11 @@ object BookSourceAnalyzer {
is String -> sourceAny.loginUrl.toString() is String -> sourceAny.loginUrl.toString()
else -> JsonPath.parse(sourceAny.loginUrl).readString("url") 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.loginCheckJs = sourceAny.loginCheckJs
source.bookSourceComment = sourceAny.bookSourceComment source.bookSourceComment = sourceAny.bookSourceComment
source.lastUpdateTime = sourceAny.lastUpdateTime source.lastUpdateTime = sourceAny.lastUpdateTime
@ -170,7 +174,7 @@ object BookSourceAnalyzer {
var concurrentRate: String? = null, // 并发率 var concurrentRate: String? = null, // 并发率
var header: String? = null, // 请求头 var header: String? = null, // 请求头
var loginUrl: Any? = null, // 登录规则 var loginUrl: Any? = null, // 登录规则
var loginUi: List<RowUi>? = null, // 登录UI var loginUi: Any? = null, // 登录UI
var loginCheckJs: String? = null, //登录检测js var loginCheckJs: String? = null, //登录检测js
var bookSourceComment: String? = "", //书源注释 var bookSourceComment: String? = "", //书源注释
var lastUpdateTime: Long = 0, // 最后更新时间,用于排序 var lastUpdateTime: Long = 0, // 最后更新时间,用于排序

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

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

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

@ -43,7 +43,7 @@ class SourceLoginDialog : BaseDialogFragment(R.layout.dialog_login) {
binding.toolBar.setBackgroundColor(primaryColor) binding.toolBar.setBackgroundColor(primaryColor)
binding.toolBar.title = getString(R.string.login_source, source.getTag()) binding.toolBar.title = getString(R.string.login_source, source.getTag())
val loginInfo = source.getLoginInfoMap() val loginInfo = source.getLoginInfoMap()
val loginUi = source.loginUi val loginUi = source.loginUi()
loginUi?.forEachIndexed { index, rowUi -> loginUi?.forEachIndexed { index, rowUi ->
when (rowUi.type) { when (rowUi.type) {
"text" -> ItemSourceEditBinding.inflate(layoutInflater, binding.root, false).let { "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("sourceGroup", source?.sourceGroup, R.string.source_group))
add(EditEntity("sourceComment", source?.sourceComment, R.string.comment)) add(EditEntity("sourceComment", source?.sourceComment, R.string.comment))
add(EditEntity("loginUrl", source?.loginUrl, R.string.login_url)) 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("loginCheckJs", source?.loginCheckJs, R.string.login_check_js))
add(EditEntity("header", source?.header, R.string.source_http_header)) add(EditEntity("header", source?.header, R.string.source_http_header))
add( add(
@ -196,7 +196,7 @@ class RssSourceEditActivity :
"sourceGroup" -> source.sourceGroup = it.value "sourceGroup" -> source.sourceGroup = it.value
"sourceComment" -> source.sourceComment = it.value "sourceComment" -> source.sourceComment = it.value
"loginUrl" -> source.loginUrl = it.value "loginUrl" -> source.loginUrl = it.value
"loginUi" -> source.setLoginUi(it.value) "loginUi" -> source.loginUi = it.value
"loginCheckJs" -> source.loginCheckJs = it.value "loginCheckJs" -> source.loginCheckJs = it.value
"header" -> source.header = it.value "header" -> source.header = it.value
"concurrentRate" -> source.concurrentRate = it.value "concurrentRate" -> source.concurrentRate = it.value

Loading…
Cancel
Save