From 534f573f0c5cc0a1d24358d5c2d1657c9ff84721 Mon Sep 17 00:00:00 2001 From: AndyBernie Date: Thu, 3 Sep 2020 09:43:43 +0800 Subject: [PATCH 1/3] update getGlidrUrl --- .../io/legado/app/model/analyzeRule/AnalyzeUrl.kt | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt index 653c3b0a1..6a16a8411 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt @@ -434,15 +434,11 @@ class AnalyzeUrl( } fun getGlideUrl(): Any? { - var glideUrl: Any = urlHasQuery - if (headerMap.isNotEmpty()) { - val headers = LazyHeaders.Builder() - headerMap.forEach { (key, value) -> - headers.addHeader(key, value) - } - glideUrl = GlideUrl(urlHasQuery, headers.build()) + val headers = LazyHeaders.Builder() + headerMap.forEach { (key, value) -> + headers.addHeader(key, value) } - return glideUrl + return GlideUrl(urlHasQuery, headers.build()) } data class UrlOption( From dd0867abd12a6e16e5b874df9da746e1940f4a7a Mon Sep 17 00:00:00 2001 From: AndyBernie Date: Thu, 3 Sep 2020 13:22:50 +0800 Subject: [PATCH 2/3] images can be exported --- .../app/ui/book/download/DownloadViewModel.kt | 42 +++++++++++++++++-- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/download/DownloadViewModel.kt b/app/src/main/java/io/legado/app/ui/book/download/DownloadViewModel.kt index a2a2f00bb..7402dd18b 100644 --- a/app/src/main/java/io/legado/app/ui/book/download/DownloadViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/download/DownloadViewModel.kt @@ -5,13 +5,11 @@ import android.net.Uri import androidx.documentfile.provider.DocumentFile import io.legado.app.App import io.legado.app.R +import io.legado.app.constant.AppPattern import io.legado.app.base.BaseViewModel import io.legado.app.data.entities.Book import io.legado.app.help.BookHelp -import io.legado.app.utils.DocumentUtils -import io.legado.app.utils.FileUtils -import io.legado.app.utils.isContentPath -import io.legado.app.utils.writeText +import io.legado.app.utils.* import java.io.File @@ -38,11 +36,47 @@ class DownloadViewModel(application: Application) : BaseViewModel(application) { private fun export(doc: DocumentFile, book: Book) { DocumentUtils.createFileIfNotExist(doc, "${book.name} 作者:${book.author}.txt") ?.writeText(context, getAllContents(book)) + App.db.bookChapterDao().getChapterList(book.bookUrl).forEach { chapter -> + BookHelp.getContent(book, chapter).let { content -> + content?.split("\n")?.forEachIndexed { index, text -> + val matcher = AppPattern.imgPattern.matcher(text) + if (matcher.find()) { + var src = matcher.group(1) + src = NetworkUtils.getAbsoluteURL(chapter.url, src) + src?.let { + val vfile = BookHelp.getImage(book, src) + if(vfile.exists()) { + DocumentUtils.createFileIfNotExist(doc, "${index}-${MD5Utils.md5Encode16(src)}.jpg", subDirs = arrayOf("${book.name}_${book.author}", "images", chapter.title)) + ?.writeBytes(context, vfile.readBytes()) + } + } + } + } + } + } } private fun export(file: File, book: Book) { FileUtils.createFileIfNotExist(file, "${book.name} 作者:${book.author}.txt") .writeText(getAllContents(book)) + App.db.bookChapterDao().getChapterList(book.bookUrl).forEach { chapter -> + BookHelp.getContent(book, chapter).let { content -> + content?.split("\n")?.forEachIndexed { index, text -> + val matcher = AppPattern.imgPattern.matcher(text) + if (matcher.find()) { + var src = matcher.group(1) + src = NetworkUtils.getAbsoluteURL(chapter.url, src) + src?.let { + val vfile = BookHelp.getImage(book, src) + if(vfile.exists()) { + FileUtils.createFileIfNotExist(file, "${book.name}_${book.author}", "images", chapter.title, "${index}-${MD5Utils.md5Encode16(src)}.jpg") + .writeBytes(vfile.readBytes()) + } + } + } + } + } + } } private fun getAllContents(book: Book): String { From e06115b213a321d33d66be08dd3f2b4c20cea657 Mon Sep 17 00:00:00 2001 From: AndyBernie Date: Thu, 3 Sep 2020 13:44:06 +0800 Subject: [PATCH 3/3] update log --- app/src/main/assets/updateLog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index a3a09e524..b327ee3dc 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -6,6 +6,7 @@ **2020/09/03** * 修复替换中的回车消失的bug * 所有内容恢复htmlFormat, 在想其它办法解决丢失一些内容的问题 +* 图片(漫画)支持导出 **2020/09/02** * 搜索url支持put,get,js里使用java.put,java.get