Merge remote-tracking branch 'origin/master'

pull/2731/head
kunfei 2 years ago
commit 38e4897f7c
  1. 35
      app/src/main/java/io/legado/app/help/book/BookHelp.kt

@ -1,5 +1,6 @@
package io.legado.app.help.book
import android.graphics.BitmapFactory
import android.os.ParcelFileDescriptor
import androidx.documentfile.provider.DocumentFile
import io.legado.app.constant.AppLog
@ -16,6 +17,7 @@ import kotlinx.coroutines.*
import kotlinx.coroutines.Dispatchers.IO
import org.apache.commons.text.similarity.JaccardSimilarity
import splitties.init.appCtx
import java.io.ByteArrayInputStream
import java.io.File
import java.io.FileNotFoundException
import java.io.FileOutputStream
@ -147,6 +149,9 @@ object BookHelp {
ImageUtils.decode(
src, bytes, isCover = false, bookSource, book
)?.let {
if (!checkImage(bytes)) {
AppLog.put("图片 $src 下载错误,数据异常")
}
FileUtils.createFileIfNotExist(
downloadDir,
cacheFolderName,
@ -157,7 +162,7 @@ object BookHelp {
}
} catch (e: Exception) {
e.printStackTrace()
AppLog.put("${src}下载错误", e)
AppLog.put("图片 $src 下载错误", e)
} finally {
downloadImages.remove(src)
}
@ -255,16 +260,40 @@ object BookHelp {
if (!hasContent(book, bookChapter)) {
return false
}
var ret = true
val op = BitmapFactory.Options()
op.inJustDecodeBounds = true
getContent(book, bookChapter)?.let {
val matcher = AppPattern.imgPattern.matcher(it)
while (matcher.find()) {
matcher.group(1)?.let { src ->
val src = matcher.group(1)!!
val image = getImage(book, src)
if (!image.exists()) {
return false
ret = false
continue
}
if (SvgUtils.getSize(image.absolutePath) != null) {
continue
}
BitmapFactory.decodeFile(image.absolutePath, op)
if (op.outWidth < 1 && op.outHeight < 1) {
ret = false
image.delete()
}
}
}
return ret
}
private fun checkImage(bytes: ByteArray): Boolean {
if (SvgUtils.getSize(ByteArrayInputStream(bytes)) != null) {
return true
}
val op = BitmapFactory.Options()
op.inJustDecodeBounds = true
BitmapFactory.decodeByteArray(bytes, 0, bytes.size, op)
if (op.outWidth < 1 && op.outHeight < 1) {
return false
}
return true
}

Loading…
Cancel
Save