parent
394cfb9b13
commit
e935556bff
|
@ -1,7 +1,7 @@
|
||||||
ext {
|
ext {
|
||||||
extName = 'Ikigai Mangas'
|
extName = 'Ikigai Mangas'
|
||||||
extClass = '.IkigaiMangas'
|
extClass = '.IkigaiMangas'
|
||||||
extVersionCode = 16
|
extVersionCode = 17
|
||||||
isNsfw = true
|
isNsfw = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,11 +33,13 @@ import kotlin.concurrent.thread
|
||||||
|
|
||||||
class IkigaiMangas : HttpSource(), ConfigurableSource {
|
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"
|
private val isCi = System.getenv("CI") == "true"
|
||||||
override val baseUrl get() = when {
|
override val baseUrl: String by lazy {
|
||||||
isCi -> defaultBaseUrl
|
when {
|
||||||
else -> preferences.getPrefBaseUrl()
|
isCi -> defaultBaseUrl
|
||||||
|
else -> fetchDomain()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private val apiBaseUrl: String = "https://panel.ikigaimangas.com"
|
private val apiBaseUrl: String = "https://panel.ikigaimangas.com"
|
||||||
|
@ -67,11 +69,28 @@ class IkigaiMangas : HttpSource(), ConfigurableSource {
|
||||||
Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000)
|
Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000)
|
||||||
|
|
||||||
override fun headersBuilder() = super.headersBuilder()
|
override fun headersBuilder() = super.headersBuilder()
|
||||||
.add("Origin", baseUrl)
|
|
||||||
.add("Referer", "$baseUrl/")
|
.add("Referer", "$baseUrl/")
|
||||||
|
|
||||||
private val json: Json by injectLazy()
|
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 {
|
private val dateFormat = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSS'Z'", Locale.US).apply {
|
||||||
timeZone = TimeZone.getTimeZone("UTC")
|
timeZone = TimeZone.getTimeZone("UTC")
|
||||||
}
|
}
|
||||||
|
@ -256,6 +275,13 @@ class IkigaiMangas : HttpSource(), ConfigurableSource {
|
||||||
setDefaultValue(SHOW_NSFW_PREF_DEFAULT)
|
setDefaultValue(SHOW_NSFW_PREF_DEFAULT)
|
||||||
}.also { screen.addPreference(it) }
|
}.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 {
|
EditTextPreference(screen.context).apply {
|
||||||
key = BASE_URL_PREF
|
key = BASE_URL_PREF
|
||||||
title = BASE_URL_PREF_TITLE
|
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.showNsfwPref() = getBoolean(SHOW_NSFW_PREF, SHOW_NSFW_PREF_DEFAULT)
|
||||||
private fun SharedPreferences.getPrefBaseUrl() = getString(BASE_URL_PREF, defaultBaseUrl)!!
|
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? =
|
private inline fun <reified R> List<*>.firstInstanceOrNull(): R? =
|
||||||
filterIsInstance<R>().firstOrNull()
|
filterIsInstance<R>().firstOrNull()
|
||||||
|
@ -285,9 +312,14 @@ class IkigaiMangas : HttpSource(), ConfigurableSource {
|
||||||
|
|
||||||
private const val BASE_URL_PREF = "overrideBaseUrl"
|
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_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 DEFAULT_BASE_URL_PREF = "defaultBaseUrl"
|
||||||
private const val RESTART_APP_MESSAGE = "Reinicie la aplicación para aplicar los cambios"
|
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 {
|
init {
|
||||||
|
|
Loading…
Reference in New Issue