添加通用封面规则

pull/1705/head
kunfei 3 years ago
parent 2fcbe87eab
commit 10bdb9962c
  1. 4
      app/src/main/java/io/legado/app/data/entities/BaseSource.kt
  2. 4
      app/src/main/java/io/legado/app/data/entities/BookSource.kt
  3. 4
      app/src/main/java/io/legado/app/data/entities/HttpTTS.kt
  4. 4
      app/src/main/java/io/legado/app/data/entities/RssSource.kt
  5. 53
      app/src/main/java/io/legado/app/model/BookCover.kt
  6. 6
      app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt

@ -26,6 +26,10 @@ interface BaseSource : JsExtensions {
fun getKey(): String fun getKey(): String
override fun getSource(): BaseSource? {
return this
}
fun loginUi(): List<RowUi>? { fun loginUi(): List<RowUi>? {
return GSON.fromJsonArray<RowUi>(loginUi) return GSON.fromJsonArray<RowUi>(loginUi)
.onFailure { .onFailure {

@ -79,10 +79,6 @@ data class BookSource(
return bookSourceUrl return bookSourceUrl
} }
override fun getSource(): BaseSource {
return this
}
@delegate:Transient @delegate:Transient
@delegate:Ignore @delegate:Ignore
@IgnoredOnParcel @IgnoredOnParcel

@ -33,10 +33,6 @@ data class HttpTTS(
return "httpTts:$id" return "httpTts:$id"
} }
override fun getSource(): BaseSource {
return this
}
@Suppress("MemberVisibilityCanBePrivate") @Suppress("MemberVisibilityCanBePrivate")
companion object { companion object {

@ -52,10 +52,6 @@ data class RssSource(
return sourceUrl return sourceUrl
} }
override fun getSource(): BaseSource {
return this
}
override fun equals(other: Any?): Boolean { override fun equals(other: Any?): Boolean {
if (other is RssSource) { if (other is RssSource) {
return other.sourceUrl == sourceUrl return other.sourceUrl == sourceUrl

@ -8,22 +8,31 @@ import com.bumptech.glide.RequestBuilder
import com.bumptech.glide.request.RequestOptions import com.bumptech.glide.request.RequestOptions
import io.legado.app.R import io.legado.app.R
import io.legado.app.constant.PreferKey import io.legado.app.constant.PreferKey
import io.legado.app.data.entities.BaseSource
import io.legado.app.help.BlurTransformation import io.legado.app.help.BlurTransformation
import io.legado.app.help.CacheManager
import io.legado.app.help.config.AppConfig import io.legado.app.help.config.AppConfig
import io.legado.app.help.glide.ImageLoader import io.legado.app.help.glide.ImageLoader
import io.legado.app.utils.BitmapUtils import io.legado.app.model.analyzeRule.AnalyzeRule
import io.legado.app.utils.getPrefBoolean import io.legado.app.model.analyzeRule.AnalyzeUrl
import io.legado.app.utils.getPrefString import io.legado.app.utils.*
import kotlinx.coroutines.runBlocking
import splitties.init.appCtx import splitties.init.appCtx
object BookCover { object BookCover {
private const val coverRuleConfigKey = "legadoCoverRuleConfig"
var drawBookName = true var drawBookName = true
private set private set
var drawBookAuthor = true var drawBookAuthor = true
private set private set
lateinit var defaultDrawable: Drawable lateinit var defaultDrawable: Drawable
private set private set
var coverRuleConfig: CoverRuleConfig? =
GSON.fromJsonObject<CoverRuleConfig>(CacheManager.get(coverRuleConfigKey)).getOrNull()
private val analyzeRule by lazy {
AnalyzeRule()
}
init { init {
upDefaultCover() upDefaultCover()
@ -58,4 +67,42 @@ object BookCover {
.apply(RequestOptions.bitmapTransform(BlurTransformation(context, 25))) .apply(RequestOptions.bitmapTransform(BlurTransformation(context, 25)))
} }
fun searchCover(name: String, author: String): String? {
val config = coverRuleConfig ?: return null
if (config.searchUrl.isBlank() || config.coverRule.isBlank()) {
return null
}
val analyzeUrl =
AnalyzeUrl(config.searchUrl, name, source = config, headerMapF = config.getHeaderMap())
return runBlocking {
analyzeUrl.getStrResponseAwait().body?.let { body ->
return@let analyzeRule.getString(config.coverRule, body, true)
}
}
}
fun saveCoverRuleConfig(config: CoverRuleConfig) {
coverRuleConfig = config
val json = GSON.toJson(config)
CacheManager.put(coverRuleConfigKey, json)
}
data class CoverRuleConfig(
var searchUrl: String,
var coverRule: String,
override var concurrentRate: String? = null,
override var loginUrl: String? = null,
override var loginUi: String? = null,
override var header: String? = null,
) : BaseSource {
override fun getTag(): String {
return searchUrl
}
override fun getKey(): String {
return searchUrl
}
}
} }

@ -24,7 +24,7 @@ import javax.script.SimpleBindings
@Keep @Keep
@Suppress("unused", "RegExpRedundantEscape", "MemberVisibilityCanBePrivate") @Suppress("unused", "RegExpRedundantEscape", "MemberVisibilityCanBePrivate")
class AnalyzeRule( class AnalyzeRule(
val ruleData: RuleDataInterface, val ruleData: RuleDataInterface? = null,
private val source: BaseSource? = null private val source: BaseSource? = null
) : JsExtensions { ) : JsExtensions {
@ -613,7 +613,7 @@ class AnalyzeRule(
fun put(key: String, value: String): String { fun put(key: String, value: String): String {
chapter?.putVariable(key, value) chapter?.putVariable(key, value)
?: book?.putVariable(key, value) ?: book?.putVariable(key, value)
?: ruleData.putVariable(key, value) ?: ruleData?.putVariable(key, value)
return value return value
} }
@ -628,7 +628,7 @@ class AnalyzeRule(
} }
return chapter?.variableMap?.get(key) return chapter?.variableMap?.get(key)
?: book?.variableMap?.get(key) ?: book?.variableMap?.get(key)
?: ruleData.variableMap[key] ?: ruleData?.variableMap?.get(key)
?: "" ?: ""
} }

Loading…
Cancel
Save