IkigaiMangas: Fix pages not found (#11269)
add nsfw cookie only when needed
This commit is contained in:
parent
cf7446489d
commit
eab806d5b1
@ -1,12 +1,8 @@
|
||||
ext {
|
||||
extName = 'Ikigai Mangas'
|
||||
extClass = '.IkigaiMangas'
|
||||
extVersionCode = 27
|
||||
extVersionCode = 28
|
||||
isNsfw = true
|
||||
}
|
||||
|
||||
apply from: "$rootDir/common.gradle"
|
||||
|
||||
dependencies {
|
||||
implementation(project(":lib:cookieinterceptor"))
|
||||
}
|
||||
|
||||
@ -5,7 +5,6 @@ import android.widget.Toast
|
||||
import androidx.preference.EditTextPreference
|
||||
import androidx.preference.PreferenceScreen
|
||||
import androidx.preference.SwitchPreferenceCompat
|
||||
import eu.kanade.tachiyomi.lib.cookieinterceptor.CookieInterceptor
|
||||
import eu.kanade.tachiyomi.network.GET
|
||||
import eu.kanade.tachiyomi.network.interceptor.rateLimitHost
|
||||
import eu.kanade.tachiyomi.source.ConfigurableSource
|
||||
@ -21,6 +20,7 @@ import keiyoushi.utils.getPreferences
|
||||
import kotlinx.serialization.decodeFromString
|
||||
import kotlinx.serialization.json.Json
|
||||
import okhttp3.HttpUrl.Companion.toHttpUrl
|
||||
import okhttp3.Interceptor
|
||||
import okhttp3.Request
|
||||
import okhttp3.Response
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
@ -38,7 +38,7 @@ class IkigaiMangas : HttpSource(), ConfigurableSource {
|
||||
else -> preferences.prefBaseUrl
|
||||
}
|
||||
|
||||
private val defaultBaseUrl: String = "https://visualikigai.tutorialesminecraft.com"
|
||||
private val defaultBaseUrl: String = "https://visorikigai.damilok.xyz"
|
||||
|
||||
private val fetchedDomainUrl: String by lazy {
|
||||
if (!preferences.fetchDomainPref()) return@lazy preferences.prefBaseUrl
|
||||
@ -67,21 +67,42 @@ class IkigaiMangas : HttpSource(), ConfigurableSource {
|
||||
|
||||
override val supportsLatest: Boolean = true
|
||||
|
||||
private val cookieInterceptor = CookieInterceptor(
|
||||
"",
|
||||
listOf(
|
||||
"nsfw-mode" to "true",
|
||||
),
|
||||
)
|
||||
|
||||
override val client by lazy {
|
||||
network.cloudflareClient.newBuilder()
|
||||
.rateLimitHost(fetchedDomainUrl.toHttpUrl(), 1, 2)
|
||||
.rateLimitHost(apiBaseUrl.toHttpUrl(), 2, 1)
|
||||
.addNetworkInterceptor(cookieInterceptor)
|
||||
.addNetworkInterceptor(::nsfwCookieInterceptor)
|
||||
.build()
|
||||
}
|
||||
|
||||
private fun nsfwCookieInterceptor(chain: Interceptor.Chain): Response {
|
||||
val request = chain.request()
|
||||
return request.header("X-Add-Nsfw-Cookie")?.let {
|
||||
val newRequest = request.newBuilder()
|
||||
.removeHeader("X-Add-Nsfw-Cookie")
|
||||
.setCookie("nsfw-mode", "true")
|
||||
.build()
|
||||
chain.proceed(newRequest)
|
||||
} ?: chain.proceed(request)
|
||||
}
|
||||
|
||||
private fun Request.Builder.setCookie(name: String, value: String): Request.Builder {
|
||||
val existingHeader = this.build().header("Cookie") ?: ""
|
||||
|
||||
val cookies = existingHeader
|
||||
.split(";")
|
||||
.mapNotNull {
|
||||
val parts = it.trim().split("=", limit = 2)
|
||||
if (parts.size == 2) parts[0].trim() to parts[1].trim() else null
|
||||
}.toMap().toMutableMap()
|
||||
|
||||
cookies[name] = value
|
||||
|
||||
val mergedHeader = cookies.entries.joinToString("; ") { "${it.key}=${it.value}" }
|
||||
|
||||
return this.header("Cookie", mergedHeader)
|
||||
}
|
||||
|
||||
private val preferences: SharedPreferences = getPreferences()
|
||||
|
||||
private val lazyHeaders by lazy {
|
||||
@ -204,7 +225,14 @@ class IkigaiMangas : HttpSource(), ConfigurableSource {
|
||||
GET(fetchedDomainUrl + chapter.url.substringBefore("#"), lazyHeaders)
|
||||
|
||||
override fun pageListParse(response: Response): List<Page> {
|
||||
val document = response.asJsoup()
|
||||
val request = response.request
|
||||
var document = response.asJsoup()
|
||||
document.selectFirst("button > span:contains(permitir nsfw)")?.let {
|
||||
val newRequest = request.newBuilder()
|
||||
.header("X-Add-Nsfw-Cookie", "1")
|
||||
.build()
|
||||
document = client.newCall(newRequest).execute().asJsoup()
|
||||
}
|
||||
return document.select("section div.img > img").mapIndexed { i, element ->
|
||||
Page(i, imageUrl = element.attr("abs:src"))
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user