mirror of
https://github.com/gedoor/legado.git
synced 2025-01-07 03:06:58 +08:00
优化
This commit is contained in:
parent
7db656a610
commit
5f392d4a7e
@ -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)
|
||||
|
@ -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!!)
|
||||
|
@ -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()
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user