@@ -10,6 +10,8 @@ object AppPattern {
|
|||||||
|
|
||||||
//匹配格式化后的图片格式
|
//匹配格式化后的图片格式
|
||||||
val imgPattern: Pattern = Pattern.compile("<img[^>]*src=\"([^\"]*(?:\"[^>]+\\})?)\"[^>]*>")
|
val imgPattern: Pattern = Pattern.compile("<img[^>]*src=\"([^\"]*(?:\"[^>]+\\})?)\"[^>]*>")
|
||||||
|
//dataURL图片类型
|
||||||
|
val dataUriRegex = Regex("data:[\\w/\\-\\.]+;base64,(.*)")
|
||||||
|
|
||||||
val nameRegex = Regex("\\s+作\\s*者.*|\\s+\\S+\\s+著")
|
val nameRegex = Regex("\\s+作\\s*者.*|\\s+\\S+\\s+著")
|
||||||
val authorRegex = Regex("^\\s*作\\s*者[::\\s]+|\\s+著")
|
val authorRegex = Regex("^\\s*作\\s*者[::\\s]+|\\s+著")
|
||||||
|
|||||||
@@ -4,9 +4,11 @@ import android.content.Context
|
|||||||
import android.graphics.Bitmap
|
import android.graphics.Bitmap
|
||||||
import android.graphics.drawable.Drawable
|
import android.graphics.drawable.Drawable
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
|
import android.util.Base64
|
||||||
import androidx.annotation.DrawableRes
|
import androidx.annotation.DrawableRes
|
||||||
import com.bumptech.glide.Glide
|
import com.bumptech.glide.Glide
|
||||||
import com.bumptech.glide.RequestBuilder
|
import com.bumptech.glide.RequestBuilder
|
||||||
|
import io.legado.app.constant.AppPattern.dataUriRegex
|
||||||
import io.legado.app.model.analyzeRule.AnalyzeUrl
|
import io.legado.app.model.analyzeRule.AnalyzeUrl
|
||||||
import io.legado.app.utils.isAbsUrl
|
import io.legado.app.utils.isAbsUrl
|
||||||
import io.legado.app.utils.isContentScheme
|
import io.legado.app.utils.isContentScheme
|
||||||
@@ -19,8 +21,14 @@ object ImageLoader {
|
|||||||
* 自动判断path类型
|
* 自动判断path类型
|
||||||
*/
|
*/
|
||||||
fun load(context: Context, path: String?): RequestBuilder<Drawable> {
|
fun load(context: Context, path: String?): RequestBuilder<Drawable> {
|
||||||
|
val dataUriFindResult = dataUriRegex.find(path ?: "")
|
||||||
return when {
|
return when {
|
||||||
path.isNullOrEmpty() -> Glide.with(context).load(path)
|
path.isNullOrEmpty() -> Glide.with(context).load(path)
|
||||||
|
dataUriFindResult != null -> {
|
||||||
|
val dataUriBase64 = dataUriFindResult.groupValues[1]
|
||||||
|
val byteArray = Base64.decode(dataUriBase64, Base64.DEFAULT)
|
||||||
|
Glide.with(context).load(byteArray)
|
||||||
|
}
|
||||||
path.isAbsUrl() -> {
|
path.isAbsUrl() -> {
|
||||||
val url = kotlin.runCatching {
|
val url = kotlin.runCatching {
|
||||||
AnalyzeUrl(path).getGlideUrl()
|
AnalyzeUrl(path).getGlideUrl()
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import com.bumptech.glide.load.model.LazyHeaders
|
|||||||
import io.legado.app.constant.AppConst.SCRIPT_ENGINE
|
import io.legado.app.constant.AppConst.SCRIPT_ENGINE
|
||||||
import io.legado.app.constant.AppConst.UA_NAME
|
import io.legado.app.constant.AppConst.UA_NAME
|
||||||
import io.legado.app.constant.AppPattern.JS_PATTERN
|
import io.legado.app.constant.AppPattern.JS_PATTERN
|
||||||
|
import io.legado.app.constant.AppPattern.dataUriRegex
|
||||||
import io.legado.app.data.entities.BaseSource
|
import io.legado.app.data.entities.BaseSource
|
||||||
import io.legado.app.data.entities.Book
|
import io.legado.app.data.entities.Book
|
||||||
import io.legado.app.data.entities.BookChapter
|
import io.legado.app.data.entities.BookChapter
|
||||||
@@ -463,7 +464,6 @@ class AnalyzeUrl(
|
|||||||
*/
|
*/
|
||||||
suspend fun getByteArrayAwait(): ByteArray {
|
suspend fun getByteArrayAwait(): ByteArray {
|
||||||
@Suppress("RegExpRedundantEscape")
|
@Suppress("RegExpRedundantEscape")
|
||||||
val dataUriRegex = Regex("data:[\\w/\\-\\.]+;base64,(.*)")
|
|
||||||
val dataUriFindResult = dataUriRegex.find(urlNoQuery)
|
val dataUriFindResult = dataUriRegex.find(urlNoQuery)
|
||||||
val concurrentRecord = fetchStart()
|
val concurrentRecord = fetchStart()
|
||||||
setCookie(source?.getKey())
|
setCookie(source?.getKey())
|
||||||
|
|||||||
Reference in New Issue
Block a user