From 046c2aa4218bd3b19e7eca4de5a14d448f9f4442 Mon Sep 17 00:00:00 2001 From: BrutuZ Date: Sun, 17 Mar 2024 15:05:47 -0300 Subject: [PATCH] Anchira: Improve chapter suffix parsing (#1904) * Improve chapter suffix parsing * Don't convert Tags to sequence before sorting --- src/en/anchira/build.gradle | 2 +- .../tachiyomi/extension/en/anchira/Anchira.kt | 14 +++--- .../extension/en/anchira/AnchiraHelper.kt | 43 ++++++++++--------- 3 files changed, 28 insertions(+), 31 deletions(-) diff --git a/src/en/anchira/build.gradle b/src/en/anchira/build.gradle index 20b793df3..9242ce537 100644 --- a/src/en/anchira/build.gradle +++ b/src/en/anchira/build.gradle @@ -1,7 +1,7 @@ ext { extName = 'Anchira' extClass = '.Anchira' - extVersionCode = 10 + extVersionCode = 11 isNsfw = true } diff --git a/src/en/anchira/src/eu/kanade/tachiyomi/extension/en/anchira/Anchira.kt b/src/en/anchira/src/eu/kanade/tachiyomi/extension/en/anchira/Anchira.kt index 180832c19..450382e3a 100644 --- a/src/en/anchira/src/eu/kanade/tachiyomi/extension/en/anchira/Anchira.kt +++ b/src/en/anchira/src/eu/kanade/tachiyomi/extension/en/anchira/Anchira.kt @@ -120,11 +120,6 @@ class Anchira : HttpSource(), ConfigurableSource { query.substringAfter(SLUG_BUNDLE_PREFIX), filters, ).removeAllQueryParameters("page") - if ( - url.build().queryParameter("sort") == "4" - ) { - url.removeAllQueryParameters("sort") - } val manga = SManga.create() .apply { this.url = "?${url.build().query}" } fetchMangaDetails(manga).map { @@ -280,7 +275,7 @@ class Anchira : HttpSource(), ConfigurableSource { for (page in 1..pages) { results.entries.forEach { data -> chapterList.add( - createChapter(data, response, anchiraData), + createChapter(data, anchiraData), ) } if (page < pages) { @@ -298,7 +293,7 @@ class Anchira : HttpSource(), ConfigurableSource { } else { val data = json.decodeFromString(response.body.string()) chapterList.add( - createChapter(data, response, anchiraData), + createChapter(data, anchiraData), ) } return chapterList @@ -468,7 +463,7 @@ class Anchira : HttpSource(), ConfigurableSource { companion object { const val SLUG_SEARCH_PREFIX = "id:" - const val SLUG_BUNDLE_PREFIX = "bundle:" + private const val SLUG_BUNDLE_PREFIX = "bundle:" private const val IMAGE_QUALITY_PREF = "image_quality" private const val OPEN_SOURCE_PREF = "use_manga_source" private const val USE_TAG_GROUPING = "use_tag_grouping" @@ -477,4 +472,5 @@ class Anchira : HttpSource(), ConfigurableSource { } } -val CHAPTER_SUFFIX_RE = Regex("(?) = + fun createChapter(entry: Entry, anchiraData: List) = SChapter.create().apply { - val ch = - CHAPTER_SUFFIX_RE.find(entry.title)?.value?.trim('.') ?: "1" - val source = anchiraData.find { it.id == entry.id }?.url - ?: response.request.url.toString() + val chSuffix = CHAPTER_SUFFIX_RE.find(entry.title)?.value.orEmpty() + val chNumber = + chSuffix.replace(Regex("[^.\\d]"), "").trim('.').takeUnless { it.isEmpty() } ?: "1" + val source = Regex("fakku|irodori").find( + anchiraData.find { it.id == entry.id }?.url.orEmpty(), + )?.value.orEmpty().titleCase() url = "/g/${entry.id}/${entry.key}" - name = "$ch. ${entry.title.removeSuffix(" $ch")}" + name = "$chNumber. ${entry.title.removeSuffix(chSuffix)}" date_upload = entry.publishedAt * 1000 - chapter_number = ch.toFloat() + chapter_number = chNumber.toFloat() scanlator = buildString { - append( - Regex("fakku|irodori|anchira").find(source)?.value.orEmpty() - .replaceFirstChar { - if (it.isLowerCase()) { - it.titlecase( - Locale.getDefault(), - ) - } else { - it.toString() - } - }, - ) - append(" - ${entry.pages} pages") + if (source.isNotEmpty()) { + append("$source - ") + } + append("${entry.pages} pages") } } + + private fun String.titleCase() = replaceFirstChar { + if (it.isLowerCase()) { + it.titlecase(Locale.getDefault()) + } else { + it.toString() + } + } }