Improve local manga chapter names

master
Koitharu 1 year ago
parent c9d878a0b7
commit dddb00d5ef
Signed by: Koitharu
GPG Key ID: 676DEE768C17A9D7

@ -36,7 +36,6 @@ import org.koitharu.kotatsu.parsers.model.MangaChapter
import org.koitharu.kotatsu.parsers.model.MangaPage import org.koitharu.kotatsu.parsers.model.MangaPage
import org.koitharu.kotatsu.parsers.model.MangaSource import org.koitharu.kotatsu.parsers.model.MangaSource
import org.koitharu.kotatsu.parsers.util.runCatchingCancellable import org.koitharu.kotatsu.parsers.util.runCatchingCancellable
import org.koitharu.kotatsu.parsers.util.toCamelCase
import org.koitharu.kotatsu.parsers.util.toFileNameSafe import org.koitharu.kotatsu.parsers.util.toFileNameSafe
import java.io.File import java.io.File
@ -86,7 +85,7 @@ class LocalMangaParser(private val uri: Uri) {
}, },
) )
} else { } else {
val title = rootFile.nameWithoutExtension.replace("_", " ").toCamelCase() val title = rootFile.name.fileNameToTitle()
val coverEntry = fileSystem.findFirstImage(rootPath) val coverEntry = fileSystem.findFirstImage(rootPath)
Manga( Manga(
id = rootFile.absolutePath.longHashCode(), id = rootFile.absolutePath.longHashCode(),
@ -116,7 +115,7 @@ class LocalMangaParser(private val uri: Uri) {
}.toString().removePrefix(Path.DIRECTORY_SEPARATOR) }.toString().removePrefix(Path.DIRECTORY_SEPARATOR)
MangaChapter( MangaChapter(
id = "$i$s".longHashCode(), id = "$i$s".longHashCode(),
name = s.ifEmpty { title }, name = s.fileNameToTitle().ifEmpty { title },
number = 0f, number = 0f,
volume = 0, volume = 0,
source = LocalMangaSource, source = LocalMangaSource,
@ -269,6 +268,10 @@ class LocalMangaParser(private val uri: Uri) {
Path.DIRECTORY_SEPARATOR + this Path.DIRECTORY_SEPARATOR + this
}.toPath() }.toPath()
private fun String.fileNameToTitle() = substringBeforeLast('.')
.replace('_', ' ')
.replaceFirstChar { it.uppercase() }
private fun Manga.copyInternal( private fun Manga.copyInternal(
url: String = this.url, url: String = this.url,
coverUrl: String = this.coverUrl, coverUrl: String = this.coverUrl,

Loading…
Cancel
Save