YugenMangas: Add preference for fetchAllStrategy (#17338)

* at least rateLimit exist

* now exact search work fine -.-

* Fix search_each

* Add preference

* They turn off the timestamp

* Handle issues with the regex

* Use originalSlug instead throw error if not found
This commit is contained in:
Rolando Lecca 2023-08-01 07:39:20 -05:00 committed by GitHub
parent f9834fcca0
commit 7cec9eab66
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 62 additions and 12 deletions

View File

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

View File

@ -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)

View File

@ -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 {