diff --git a/multisrc/overrides/heancms/yugenmangas/src/YugenMangas.kt b/multisrc/overrides/heancms/yugenmangas/src/YugenMangas.kt index 9a566e728..d34970799 100644 --- a/multisrc/overrides/heancms/yugenmangas/src/YugenMangas.kt +++ b/multisrc/overrides/heancms/yugenmangas/src/YugenMangas.kt @@ -1,8 +1,16 @@ package eu.kanade.tachiyomi.extension.es.yugenmangas +import android.app.Application +import android.content.SharedPreferences +import android.widget.Toast +import androidx.preference.ListPreference +import androidx.preference.PreferenceScreen import eu.kanade.tachiyomi.multisrc.heancms.Genre import eu.kanade.tachiyomi.multisrc.heancms.HeanCms import eu.kanade.tachiyomi.network.interceptor.rateLimit +import eu.kanade.tachiyomi.source.ConfigurableSource +import uy.kohesive.injekt.Injekt +import uy.kohesive.injekt.api.get import java.text.SimpleDateFormat import java.util.TimeZone import java.util.concurrent.TimeUnit @@ -13,17 +21,26 @@ class YugenMangas : "https://yugenmangas.net", "es", "https://api.yugenmangas.net", - ) { + ), + ConfigurableSource { + + private val preferences: SharedPreferences by lazy { + Injekt.get().getSharedPreferences("source_$id", 0x0000) + } // Site changed from Madara to HeanCms. override val versionId = 2 - override val fetchAllTitlesStrategy = FetchAllStrategy.SEARCH_EACH + override val fetchAllTitlesStrategy = when (getfetchAllStrategyPref()) { + "all" -> FetchAllStrategy.SEARCH_ALL + "each" -> FetchAllStrategy.SEARCH_EACH + else -> FetchAllStrategy.NONE + } override val client = super.client.newBuilder() .connectTimeout(60, TimeUnit.SECONDS) .readTimeout(90, TimeUnit.SECONDS) - .rateLimit(1, 1) + .rateLimit(2, 3) .build() override val coverPath: String = "" @@ -82,4 +99,42 @@ class YugenMangas : Genre("Yaoi", 43), Genre("Yuri", 44), ) + + private fun getfetchAllStrategyPref(): String? { + return preferences.getString(PREF_FETCH_ALL_STRATEGY_KEY, PREF_FETCH_ALL_STRATEGY_DEFAULT) + } + + override fun setupPreferenceScreen(screen: PreferenceScreen) { + val fetchAllStrategyPreference = ListPreference(screen.context).apply { + key = PREF_FETCH_ALL_STRATEGY_KEY + title = PREF_FETCH_ALL_STRATEGY_TITLE + summary = PREF_FETCH_ALL_STRATEGY_SUMMARY + entries = PREF_FETCH_ALL_STRATEGY_ENTRIES + entryValues = PREF_FETCH_ALL_STRATEGY_VALUES + setDefaultValue(PREF_FETCH_ALL_STRATEGY_DEFAULT) + + setOnPreferenceChangeListener { _, newValue -> + Toast.makeText(screen.context, RESTART_MESSAGE, Toast.LENGTH_LONG).show() + true + } + } + + screen.addPreference(fetchAllStrategyPreference) + } + + companion object { + const val PREF_FETCH_ALL_STRATEGY_KEY = "prefFetchAllStrategy" + const val PREF_FETCH_ALL_STRATEGY_TITLE = "Método de búsqueda" + const val PREF_FETCH_ALL_STRATEGY_SUMMARY = "Global: Busca las URLs de todas las series al iniciar la aplicación, lento pero más estable.\n" + + "Individual: Busca la URL de la serie al actualizar, rápido pero puede fallar.\n" + + "Ninguno: Usa la URL con la que fue agregado, tendrá que migrar si la URL cambia.\n" + + "Valor actual: %s" + + val PREF_FETCH_ALL_STRATEGY_ENTRIES = arrayOf("Ninguno", "Individual", "Global") + val PREF_FETCH_ALL_STRATEGY_VALUES = arrayOf("off", "each", "all") + + const val PREF_FETCH_ALL_STRATEGY_DEFAULT = "off" + + const val RESTART_MESSAGE = "Reinicie la aplicación para que los cambios surtan efecto." + } } diff --git a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/heancms/HeanCms.kt b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/heancms/HeanCms.kt index 122a56f07..5bef4cfa8 100644 --- a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/heancms/HeanCms.kt +++ b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/heancms/HeanCms.kt @@ -225,11 +225,7 @@ abstract class HeanCms( override fun mangaDetailsRequest(manga: SManga): Request { if (fetchAllTitlesStrategy == FetchAllStrategy.SEARCH_EACH) { - val searchQuery = manga.title.trim() - .replaceAfterLast(" ", "").trim() - .let { - if (it.length > 2) it.dropLast(1).trim() else it - } + val searchQuery = manga.title val searchPayloadObj = HeanCmsSearchPayloadDto(searchQuery) val searchPayload = json.encodeToString(searchPayloadObj) .toRequestBody(JSON_MEDIA_TYPE) @@ -241,7 +237,6 @@ abstract class HeanCms( val mangaSlug = manga.url .substringAfterLast("/") - .replace(TIMESTAMP_REGEX, "") return POST("$apiUrl/series/search#$mangaSlug", apiHeaders, searchPayload) } @@ -309,8 +304,8 @@ abstract class HeanCms( val mangaSlug = searchResult .filter { it.type == "Comic" } .map { it.slug } - .find { it.replace(TIMESTAMP_REGEX, "") == originalSlug } - ?: throw Exception(intl.urlChangedError(name)) + .find { it.startsWith(originalSlug) || originalSlug.startsWith(it) } + ?: originalSlug val apiHeaders = headersBuilder() .add("Accept", ACCEPT_JSON) diff --git a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/heancms/HeanCmsGenerator.kt b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/heancms/HeanCmsGenerator.kt index 7d3cbaa69..36403a2ab 100644 --- a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/heancms/HeanCmsGenerator.kt +++ b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/heancms/HeanCmsGenerator.kt @@ -15,7 +15,7 @@ class HeanCmsGenerator : ThemeSourceGenerator { SingleLang("Glorious Scan", "https://gloriousscan.com", "pt-BR", overrideVersionCode = 17), SingleLang("Omega Scans", "https://omegascans.org", "en", isNsfw = true, overrideVersionCode = 17), SingleLang("Reaper Scans", "https://reaperscans.net", "pt-BR", overrideVersionCode = 35), - SingleLang("YugenMangas", "https://yugenmangas.net", "es", isNsfw = true, overrideVersionCode = 4), + SingleLang("YugenMangas", "https://yugenmangas.net", "es", isNsfw = true, overrideVersionCode = 5), ) companion object {