Support more image formats for covers (#5524)

* Add TachiyomiImageDecoder for Coil

Is currently used to decode AVIF and JPEG XL images.

* LocalSource: Check against file name for cover

This allows file with all supported formats to be set as cover

* TachiyomiImageDecoder: Handle HEIF on Android 7 and older
This commit is contained in:
Ivan Iskandar
2021-07-11 02:44:34 +07:00
committed by GitHub
parent 24bb2f02dc
commit 1ef7722504
3 changed files with 74 additions and 9 deletions

View File

@@ -29,7 +29,6 @@ class LocalSource(private val context: Context) : CatalogueSource {
const val ID = 0L
const val HELP_URL = "https://tachiyomi.org/help/guides/local-manga/"
private const val COVER_NAME = "cover.jpg"
private val SUPPORTED_ARCHIVE_TYPES = setOf("zip", "rar", "cbr", "cbz", "epub")
private val LATEST_THRESHOLD = TimeUnit.MILLISECONDS.convert(7, TimeUnit.DAYS)
@@ -40,18 +39,29 @@ class LocalSource(private val context: Context) : CatalogueSource {
input.close()
return null
}
val cover = File("${dir.absolutePath}/${manga.url}", COVER_NAME)
val cover = getCoverFile(File("${dir.absolutePath}/${manga.url}"))
// It might not exist if using the external SD card
cover.parentFile?.mkdirs()
input.use {
cover.outputStream().use {
input.copyTo(it)
if (cover != null && cover.exists()) {
// It might not exist if using the external SD card
cover.parentFile?.mkdirs()
input.use {
cover.outputStream().use {
input.copyTo(it)
}
}
}
return cover
}
/**
* Returns valid cover file inside [parent] directory.
*/
private fun getCoverFile(parent: File): File? {
return parent.listFiles()?.find { it.nameWithoutExtension == "cover" }?.takeIf {
it.isFile && ImageUtil.isImage(it.name) { it.inputStream() }
}
}
private fun getBaseDirectories(context: Context): List<File> {
val c = context.getString(R.string.app_name) + File.separator + "local"
return DiskUtil.getExternalStorages(context).map { File(it.absolutePath, c) }
@@ -105,8 +115,8 @@ class LocalSource(private val context: Context) : CatalogueSource {
// Try to find the cover
for (dir in baseDirs) {
val cover = File("${dir.absolutePath}/$url", COVER_NAME)
if (cover.exists()) {
val cover = getCoverFile(File("${dir.absolutePath}/$url"))
if (cover != null && cover.exists()) {
thumbnail_url = cover.absolutePath
break
}