From 10ddb3734f3bdeed73a31660e4749a8eef92dae1 Mon Sep 17 00:00:00 2001 From: kana-shii <79055104+kana-shii@users.noreply.github.com> Date: Sat, 27 Jul 2024 11:02:10 -0300 Subject: [PATCH] mangago add scanlator / remove suffix from titles (#4242) * fix for 2 issues on mangago * fix * fix forgot to remove the comment from when I was testing it out * fix * Update src/en/mangago/src/eu/kanade/tachiyomi/extension/en/mangago/Mangago.kt Co-authored-by: AwkwardPeak7 <48650614+AwkwardPeak7@users.noreply.github.com> * Update src/en/mangago/src/eu/kanade/tachiyomi/extension/en/mangago/Mangago.kt Co-authored-by: AwkwardPeak7 <48650614+AwkwardPeak7@users.noreply.github.com> * fix --------- Co-authored-by: AwkwardPeak7 <48650614+AwkwardPeak7@users.noreply.github.com> --- src/en/mangago/build.gradle | 2 +- .../tachiyomi/extension/en/mangago/Mangago.kt | 43 ++++++++++++++++++- 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/src/en/mangago/build.gradle b/src/en/mangago/build.gradle index b8672abbc..020c24b79 100644 --- a/src/en/mangago/build.gradle +++ b/src/en/mangago/build.gradle @@ -1,7 +1,7 @@ ext { extName = 'Mangago' extClass = '.Mangago' - extVersionCode = 15 + extVersionCode = 16 isNsfw = true } diff --git a/src/en/mangago/src/eu/kanade/tachiyomi/extension/en/mangago/Mangago.kt b/src/en/mangago/src/eu/kanade/tachiyomi/extension/en/mangago/Mangago.kt index 9c61dbb77..9a221c383 100644 --- a/src/en/mangago/src/eu/kanade/tachiyomi/extension/en/mangago/Mangago.kt +++ b/src/en/mangago/src/eu/kanade/tachiyomi/extension/en/mangago/Mangago.kt @@ -1,13 +1,18 @@ package eu.kanade.tachiyomi.extension.en.mangago +import android.app.Application +import android.content.SharedPreferences import android.graphics.Bitmap import android.graphics.BitmapFactory import android.graphics.Canvas import android.graphics.Rect import android.util.Base64 +import androidx.preference.PreferenceScreen +import androidx.preference.SwitchPreferenceCompat import app.cash.quickjs.QuickJs import eu.kanade.tachiyomi.network.GET import eu.kanade.tachiyomi.network.interceptor.rateLimit +import eu.kanade.tachiyomi.source.ConfigurableSource import eu.kanade.tachiyomi.source.model.Filter import eu.kanade.tachiyomi.source.model.FilterList import eu.kanade.tachiyomi.source.model.Page @@ -22,6 +27,8 @@ import okhttp3.Request import okhttp3.ResponseBody.Companion.toResponseBody import org.jsoup.nodes.Document import org.jsoup.nodes.Element +import uy.kohesive.injekt.Injekt +import uy.kohesive.injekt.api.get import java.io.ByteArrayOutputStream import java.io.InputStream import java.net.URLEncoder @@ -31,7 +38,7 @@ import javax.crypto.Cipher import javax.crypto.spec.IvParameterSpec import javax.crypto.spec.SecretKeySpec -class Mangago : ParsedHttpSource() { +class Mangago : ParsedHttpSource(), ConfigurableSource { override val name = "Mangago" @@ -41,6 +48,10 @@ class Mangago : ParsedHttpSource() { override val supportsLatest = true + private val preferences: SharedPreferences by lazy { + Injekt.get().getSharedPreferences("source_$id", 0x0000) + } + override val client = network.cloudflareClient.newBuilder() .rateLimit(1, 2) .addInterceptor { chain -> @@ -151,11 +162,20 @@ class Mangago : ParsedHttpSource() { override fun searchMangaNextPageSelector() = genreListingNextPageSelector + private val titleRegex = Regex("""\(yaoi\)|\{Official\}|«Official»|〘Official〙|\(Official\)|\s\[Official]|\s「Official」|『Official』|\s?/Official\b""", RegexOption.IGNORE_CASE) + private fun titleVersion(title: String) = title.replace(titleRegex, "").trim() + override fun mangaDetailsParse(document: Document) = SManga.create().apply { title = document.selectFirst(".w-title h1")!!.text() + if (isRemoveTitleVersion()) { + title = titleVersion(title) + } document.getElementById("information")!!.let { thumbnail_url = it.selectFirst("img")!!.attr("abs:src") - description = it.selectFirst(".manga_summary")!!.text() + description = it.selectFirst(".manga_summary")?.let { summary -> + summary.selectFirst("font")?.remove() + summary.text() + } it.select(".manga_info li, .manga_right tr").forEach { el -> when (el.selectFirst("b, label")!!.text().lowercase()) { "alternative:" -> description += "\n\n${el.text()}" @@ -183,6 +203,9 @@ class Mangago : ParsedHttpSource() { dateFormat.parse(element.select("td:last-child").text().trim())?.time }.getOrNull() ?: 0L scanlator = element.selectFirst("td.no a, td.uk-table-shrink a")?.text()?.trim() + if (scanlator.isNullOrBlank()) { + scanlator = "Unknown" + } } override fun pageListParse(document: Document): List { @@ -473,4 +496,20 @@ class Mangago : ParsedHttpSource() { ) } } + private fun isRemoveTitleVersion() = preferences.getBoolean(REMOVE_TITLE_VERSION_PREF, false) + + override fun setupPreferenceScreen(screen: PreferenceScreen) { + SwitchPreferenceCompat(screen.context).apply { + key = REMOVE_TITLE_VERSION_PREF + title = "Remove version information from entry titles" + summary = "This removes version tags like '(Official)' or '(Yaoi)' from entry titles " + + "and helps identify duplicate entries in your library. " + + "To update existing entries, remove them from your library (unfavorite) and refresh manually. " + + "You might also want to clear the database in advanced settings." + setDefaultValue(false) + }.let(screen::addPreference) + } + companion object { + private const val REMOVE_TITLE_VERSION_PREF = "REMOVE_TITLE_VERSION" + } }