Koharu: fix regex removing all title

This commit is contained in:
AwkwardPeak7 2024-07-17 16:37:44 +05:00 committed by Draff
parent 1a3acc77d3
commit d741e353e7
No known key found for this signature in database
GPG Key ID: E8A89F3211677653
2 changed files with 6 additions and 5 deletions

View File

@ -1,7 +1,7 @@
ext {
extName = 'Koharu'
extClass = '.Koharu'
extVersionCode = 2
extVersionCode = 3
isNsfw = true
}

View File

@ -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<Application>().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<String>.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() }