IkigaiMangas: Search domain automatically (#5152)

domain
This commit is contained in:
bapeey 2024-09-22 01:45:42 -05:00 committed by GitHub
parent 690259b5ec
commit 9fbdbc332f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 39 additions and 7 deletions

View File

@ -1,7 +1,7 @@
ext {
extName = 'Ikigai Mangas'
extClass = '.IkigaiMangas'
extVersionCode = 16
extVersionCode = 17
isNsfw = true
}

View File

@ -33,11 +33,13 @@ import kotlin.concurrent.thread
class IkigaiMangas : HttpSource(), ConfigurableSource {
private val defaultBaseUrl: String = "https://lectorikigai.erigu.com"
private val defaultBaseUrl: String = "https://lectorikigai.efope.com"
private val isCi = System.getenv("CI") == "true"
override val baseUrl get() = when {
isCi -> defaultBaseUrl
else -> preferences.getPrefBaseUrl()
override val baseUrl: String by lazy {
when {
isCi -> defaultBaseUrl
else -> fetchDomain()
}
}
private val apiBaseUrl: String = "https://panel.ikigaimangas.com"
@ -67,11 +69,28 @@ class IkigaiMangas : HttpSource(), ConfigurableSource {
Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000)
override fun headersBuilder() = super.headersBuilder()
.add("Origin", baseUrl)
.add("Referer", "$baseUrl/")
private val json: Json by injectLazy()
private fun fetchDomain(): String {
if (!preferences.fetchDomainPref()) return preferences.getPrefBaseUrl()
try {
val initClient = network.cloudflareClient
val headers = super.headersBuilder().build()
val homeDomain = "https://ikigaimangas.com"
val document = initClient.newCall(GET(homeDomain, headers)).execute().asJsoup()
val scriptUrl = document.selectFirst("div[on:click]:containsOwn(Nuevo dominio)")?.attr("on:click")
?: return defaultBaseUrl
val script = initClient.newCall(GET("$homeDomain/build/$scriptUrl", headers)).execute().body.string()
val domain = script.substringAfter("window.open(\"").substringBefore("\"")
val host = initClient.newCall(GET(domain, headers)).execute().request.url.host
return "https://$host"
} catch (e: Exception) {
return defaultBaseUrl
}
}
private val dateFormat = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSS'Z'", Locale.US).apply {
timeZone = TimeZone.getTimeZone("UTC")
}
@ -256,6 +275,13 @@ class IkigaiMangas : HttpSource(), ConfigurableSource {
setDefaultValue(SHOW_NSFW_PREF_DEFAULT)
}.also { screen.addPreference(it) }
SwitchPreferenceCompat(screen.context).apply {
key = FETCH_DOMAIN_PREF
title = FETCH_DOMAIN_PREF_TITLE
summary = FETCH_DOMAIN_PREF_SUMMARY
setDefaultValue(FETCH_DOMAIN_PREF_DEFAULT)
}.also { screen.addPreference(it) }
EditTextPreference(screen.context).apply {
key = BASE_URL_PREF
title = BASE_URL_PREF_TITLE
@ -272,6 +298,7 @@ class IkigaiMangas : HttpSource(), ConfigurableSource {
private fun SharedPreferences.showNsfwPref() = getBoolean(SHOW_NSFW_PREF, SHOW_NSFW_PREF_DEFAULT)
private fun SharedPreferences.getPrefBaseUrl() = getString(BASE_URL_PREF, defaultBaseUrl)!!
private fun SharedPreferences.fetchDomainPref() = getBoolean(FETCH_DOMAIN_PREF, FETCH_DOMAIN_PREF_DEFAULT)
private inline fun <reified R> List<*>.firstInstanceOrNull(): R? =
filterIsInstance<R>().firstOrNull()
@ -285,9 +312,14 @@ class IkigaiMangas : HttpSource(), ConfigurableSource {
private const val BASE_URL_PREF = "overrideBaseUrl"
private const val BASE_URL_PREF_TITLE = "Editar URL de la fuente"
private const val BASE_URL_PREF_SUMMARY = "Para uso temporal, si la extensión se actualiza se perderá el cambio."
private const val BASE_URL_PREF_SUMMARY = "Para uso temporal, si la extensión se actualiza se perderá el cambio. No se aplica si se busca el dominio automáticamente."
private const val DEFAULT_BASE_URL_PREF = "defaultBaseUrl"
private const val RESTART_APP_MESSAGE = "Reinicie la aplicación para aplicar los cambios"
private const val FETCH_DOMAIN_PREF = "fetchDomain"
private const val FETCH_DOMAIN_PREF_TITLE = "Buscar dominio automáticamente"
private const val FETCH_DOMAIN_PREF_SUMMARY = "Intenta buscar el dominio automáticamente al abrir la fuente."
private const val FETCH_DOMAIN_PREF_DEFAULT = true
}
init {