|
|
@ -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 |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |