From 5f392d4a7e202ce6339773098abe46282689c9aa Mon Sep 17 00:00:00 2001 From: Horis <8674809+821938089@users.noreply.github.com> Date: Tue, 17 Dec 2024 13:33:36 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/model/localBook/EpubFile.kt | 10 +++++++++- .../java/io/legado/app/model/localBook/MobiFile.kt | 10 +++++++++- .../main/java/io/legado/app/model/localBook/PdfFile.kt | 9 ++++++++- .../main/java/io/legado/app/model/localBook/UmdFile.kt | 10 +++++++++- 4 files changed, 35 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/model/localBook/EpubFile.kt b/app/src/main/java/io/legado/app/model/localBook/EpubFile.kt index c979f9e46164..c92d4206552d 100644 --- a/app/src/main/java/io/legado/app/model/localBook/EpubFile.kt +++ b/app/src/main/java/io/legado/app/model/localBook/EpubFile.kt @@ -22,6 +22,7 @@ import org.jsoup.Jsoup import org.jsoup.nodes.Element import org.jsoup.parser.Parser import org.jsoup.select.Elements +import java.io.File import java.io.FileOutputStream import java.io.IOException import java.io.InputStream @@ -95,6 +96,10 @@ class EpubFile(var book: Book) { return field } + init { + upBookCover(true) + } + /** * 重写epub文件解析代码,直接读出压缩包文件生成Resources给epublib,这样的好处是可以逐一修改某些文件的格式错误 */ @@ -249,12 +254,15 @@ class EpubFile(var book: Book) { return epubBook?.resources?.getByHref(abHref)?.inputStream } - private fun upBookCover() { + private fun upBookCover(fastCheck: Boolean = false) { try { epubBook?.let { if (book.coverUrl.isNullOrEmpty()) { book.coverUrl = LocalBook.getCoverPath(book) } + if (fastCheck && File(book.coverUrl!!).exists()) { + return + } /*部分书籍DRM处理后,封面获取异常,待优化*/ it.coverImage?.inputStream?.use { input -> val cover = BitmapFactory.decodeStream(input) diff --git a/app/src/main/java/io/legado/app/model/localBook/MobiFile.kt b/app/src/main/java/io/legado/app/model/localBook/MobiFile.kt index 94afaa912253..085d4a8fe8be 100644 --- a/app/src/main/java/io/legado/app/model/localBook/MobiFile.kt +++ b/app/src/main/java/io/legado/app/model/localBook/MobiFile.kt @@ -16,6 +16,7 @@ import io.legado.app.utils.FileUtils import io.legado.app.utils.HtmlFormatter import io.legado.app.utils.printOnDebug import org.jsoup.Jsoup +import java.io.File import java.io.FileOutputStream import java.io.InputStream @@ -70,6 +71,10 @@ class MobiFile(var book: Book) { return field } + init { + upBookCover(true) + } + private fun readMobi(): MobiBook? { return kotlin.runCatching { BookHelp.getBookPFD(book)?.let { @@ -266,12 +271,15 @@ class MobiFile(var book: Book) { return kf8Book.getResourceByHref(href)?.inputStream() } - private fun upBookCover() { + private fun upBookCover(fastCheck: Boolean = false) { try { mobiBook?.let { if (book.coverUrl.isNullOrEmpty()) { book.coverUrl = LocalBook.getCoverPath(book) } + if (fastCheck && File(book.coverUrl!!).exists()) { + return + } it.getCover()?.let { bytes -> val bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.size) val file = FileUtils.createFileIfNotExist(book.coverUrl!!) diff --git a/app/src/main/java/io/legado/app/model/localBook/PdfFile.kt b/app/src/main/java/io/legado/app/model/localBook/PdfFile.kt index 26ff42613e25..9723e3a1c821 100644 --- a/app/src/main/java/io/legado/app/model/localBook/PdfFile.kt +++ b/app/src/main/java/io/legado/app/model/localBook/PdfFile.kt @@ -74,6 +74,10 @@ class PdfFile(var book: Book) { return field } + init { + upBookCover(true) + } + /** * 读取PDF文件 * @@ -188,12 +192,15 @@ class PdfFile(var book: Book) { return chapterList } - private fun upBookCover() { + private fun upBookCover(fastCheck: Boolean = false) { try { pdfRenderer?.let { renderer -> if (book.coverUrl.isNullOrEmpty()) { book.coverUrl = LocalBook.getCoverPath(book) } + if (fastCheck && File(book.coverUrl!!).exists()) { + return + } FileOutputStream(FileUtils.createFileIfNotExist(book.coverUrl!!)).use { out -> openPdfPage(renderer, 0)?.compress(Bitmap.CompressFormat.JPEG, 90, out) out.flush() diff --git a/app/src/main/java/io/legado/app/model/localBook/UmdFile.kt b/app/src/main/java/io/legado/app/model/localBook/UmdFile.kt index 196727590d67..c652ddc48d23 100644 --- a/app/src/main/java/io/legado/app/model/localBook/UmdFile.kt +++ b/app/src/main/java/io/legado/app/model/localBook/UmdFile.kt @@ -7,6 +7,7 @@ import io.legado.app.utils.FileUtils import io.legado.app.utils.printOnDebug import me.ag2s.umdlib.domain.UmdBook import me.ag2s.umdlib.umd.UmdReader +import java.io.File import java.io.InputStream class UmdFile(var book: Book) { @@ -58,17 +59,24 @@ class UmdFile(var book: Book) { return field } + init { + upBookCover(true) + } + private fun readUmd(): UmdBook? { val input = LocalBook.getBookInputStream(book) return UmdReader().read(input) } - private fun upBookCover() { + private fun upBookCover(fastCheck: Boolean = false) { try { umdBook?.let { if (book.coverUrl.isNullOrEmpty()) { book.coverUrl = LocalBook.getCoverPath(book) } + if (fastCheck && File(book.coverUrl!!).exists()) { + return + } FileUtils.writeBytes(book.coverUrl!!, it.cover.coverData) } } catch (e: Exception) {