Improve local manga chapter names

(cherry picked from commit dddb00d5ef)
This commit is contained in:
Koitharu
2025-01-11 14:54:02 +02:00
parent 8d52cab6d8
commit 04c7ca7291

View File

@@ -35,7 +35,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
@@ -85,7 +84,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)
val mimeTypeMap = MimeTypeMap.getSingleton() val mimeTypeMap = MimeTypeMap.getSingleton()
Manga( Manga(
@@ -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,
@@ -275,6 +274,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,