From d741e353e7ff57e805b2d85ff41d9acd0c7720f7 Mon Sep 17 00:00:00 2001 From: AwkwardPeak7 <48650614+AwkwardPeak7@users.noreply.github.com> Date: Wed, 17 Jul 2024 16:37:44 +0500 Subject: [PATCH] Koharu: fix regex removing all title --- src/en/koharu/build.gradle | 2 +- .../eu/kanade/tachiyomi/extension/en/koharu/Koharu.kt | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/en/koharu/build.gradle b/src/en/koharu/build.gradle index 2259384b4..c650ebf32 100644 --- a/src/en/koharu/build.gradle +++ b/src/en/koharu/build.gradle @@ -1,7 +1,7 @@ ext { extName = 'Koharu' extClass = '.Koharu' - extVersionCode = 2 + extVersionCode = 3 isNsfw = true } diff --git a/src/en/koharu/src/eu/kanade/tachiyomi/extension/en/koharu/Koharu.kt b/src/en/koharu/src/eu/kanade/tachiyomi/extension/en/koharu/Koharu.kt index d2ee70dc0..aa6fc94f0 100644 --- a/src/en/koharu/src/eu/kanade/tachiyomi/extension/en/koharu/Koharu.kt +++ b/src/en/koharu/src/eu/kanade/tachiyomi/extension/en/koharu/Koharu.kt @@ -48,7 +48,8 @@ class Koharu : HttpSource(), ConfigurableSource { private val json: Json by injectLazy() - private val titleRegex = Regex("""\s*[(\[{].*[)\]}]\s*""") + private val shortenTitleRegex = Regex("""(\[[^]]*]|[({][^)}]*[)}])""") + private fun String.shortenTitle() = replace(shortenTitleRegex, "").trim() private val preferences: SharedPreferences by lazy { Injekt.get().getSharedPreferences("source_$id", 0x0000) @@ -64,7 +65,7 @@ class Koharu : HttpSource(), ConfigurableSource { private fun getManga(book: Entry) = SManga.create().apply { setUrlWithoutDomain("${book.id}/${book.public_key}") - title = if (remadd()) book.title.replace(titleRegex, "").trim() else book.title + title = if (remadd()) book.title.shortenTitle() else book.title thumbnail_url = book.thumbnail.path } @@ -164,7 +165,7 @@ class Koharu : HttpSource(), ConfigurableSource { listOf( SManga.create().apply { setUrlWithoutDomain("${entry.id}/${entry.public_key}") - title = if (remadd()) entry.title.replace(titleRegex, "").trim() else entry.title + title = if (remadd()) entry.title.shortenTitle() else entry.title thumbnail_url = entry.thumbnails.base + entry.thumbnails.main.path }, ), @@ -214,7 +215,7 @@ class Koharu : HttpSource(), ConfigurableSource { var appended = false fun List.joinAndCapitalizeEach(): String? = this.emptyToNull()?.joinToString { it.capitalizeEach() }?.apply { appended = true } - title = if (remadd()) this@toSManga.title.replace(titleRegex, "").trim() else this@toSManga.title + title = if (remadd()) this@toSManga.title.shortenTitle() else this@toSManga.title author = (circles.emptyToNull() ?: artists).joinToString { it.capitalizeEach() } artist = artists.joinToString { it.capitalizeEach() }