|
|
|
|
@ -4,6 +4,7 @@ import androidx.core.net.toFile
|
|
|
|
|
import androidx.core.net.toUri
|
|
|
|
|
import kotlinx.coroutines.Dispatchers
|
|
|
|
|
import kotlinx.coroutines.runInterruptible
|
|
|
|
|
import org.koitharu.kotatsu.core.util.AlphanumComparator
|
|
|
|
|
import org.koitharu.kotatsu.core.util.ext.listFilesRecursive
|
|
|
|
|
import org.koitharu.kotatsu.core.util.ext.longHashCode
|
|
|
|
|
import org.koitharu.kotatsu.core.util.ext.toListSorted
|
|
|
|
|
@ -87,8 +88,8 @@ class LocalMangaDirInput(root: File) : LocalMangaInput(root) {
|
|
|
|
|
override suspend fun getPages(chapter: MangaChapter): List<MangaPage> = runInterruptible(Dispatchers.IO) {
|
|
|
|
|
val file = chapter.url.toUri().toFile()
|
|
|
|
|
if (file.isDirectory) {
|
|
|
|
|
file.listFilesRecursive(ImageFileFilter())
|
|
|
|
|
.toListSorted(compareBy(org.koitharu.kotatsu.core.util.AlphanumComparator()) { x -> x.name })
|
|
|
|
|
file.listFilesRecursive(ImageFileFilter)
|
|
|
|
|
.toListSorted(compareBy(AlphanumComparator) { x -> x.name })
|
|
|
|
|
.map {
|
|
|
|
|
val pageUri = it.toUri().toString()
|
|
|
|
|
MangaPage(
|
|
|
|
|
@ -104,7 +105,7 @@ class LocalMangaDirInput(root: File) : LocalMangaInput(root) {
|
|
|
|
|
.asSequence()
|
|
|
|
|
.filter { x -> !x.isDirectory }
|
|
|
|
|
.map { it.name }
|
|
|
|
|
.toListSorted(org.koitharu.kotatsu.core.util.AlphanumComparator())
|
|
|
|
|
.toListSorted(AlphanumComparator)
|
|
|
|
|
.map {
|
|
|
|
|
val pageUri = zipUri(file, it)
|
|
|
|
|
MangaPage(
|
|
|
|
|
@ -120,18 +121,17 @@ class LocalMangaDirInput(root: File) : LocalMangaInput(root) {
|
|
|
|
|
|
|
|
|
|
private fun String.toHumanReadable() = replace("_", " ").toCamelCase()
|
|
|
|
|
|
|
|
|
|
private fun getChaptersFiles(): List<File> = root.listFilesRecursive(CbzFilter())
|
|
|
|
|
.toListSorted(compareBy(org.koitharu.kotatsu.core.util.AlphanumComparator()) { x -> x.name })
|
|
|
|
|
private fun getChaptersFiles(): List<File> = root.listFilesRecursive(CbzFilter)
|
|
|
|
|
.toListSorted(compareBy(AlphanumComparator) { x -> x.name })
|
|
|
|
|
|
|
|
|
|
private fun findFirstImageEntry(): String? {
|
|
|
|
|
val filter = ImageFileFilter()
|
|
|
|
|
root.listFilesRecursive(filter).firstOrNull()?.let {
|
|
|
|
|
root.listFilesRecursive(ImageFileFilter).firstOrNull()?.let {
|
|
|
|
|
return it.toUri().toString()
|
|
|
|
|
}
|
|
|
|
|
val cbz = root.listFilesRecursive(CbzFilter()).firstOrNull() ?: return null
|
|
|
|
|
val cbz = root.listFilesRecursive(CbzFilter).firstOrNull() ?: return null
|
|
|
|
|
return ZipFile(cbz).use { zip ->
|
|
|
|
|
zip.entries().asSequence()
|
|
|
|
|
.firstOrNull { x -> !x.isDirectory && filter.accept(x) }
|
|
|
|
|
.firstOrNull { x -> !x.isDirectory && ImageFileFilter.accept(x) }
|
|
|
|
|
?.let { entry -> zipUri(cbz, entry.name) }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|