Merge branch 'KotatsuApp:master' into master

pull/368/head
Deivid Gabriel Pereira de Oliveira 3 years ago committed by GitHub
commit 44f70c1388
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -8,6 +8,7 @@ import okhttp3.Cookie
import okhttp3.HttpUrl.Companion.toHttpUrl
import okhttp3.Interceptor
import okhttp3.Response
import okhttp3.internal.closeQuietly
import org.json.JSONObject
import org.jsoup.nodes.Document
import org.koitharu.kotatsu.parsers.MangaLoaderContext
@ -33,6 +34,7 @@ internal abstract class MangaReaderParser(
protected open val listUrl = "/manga"
protected open val datePattern = "MMMM d, yyyy"
protected open val isNetShieldProtected = false
private var tagCache: ArrayMap<String, MangaTag>? = null
private val mutex = Mutex()
@ -304,20 +306,31 @@ internal abstract class MangaReaderParser(
override fun intercept(chain: Interceptor.Chain): Response {
val response = chain.proceed(chain.request())
if (context.cookieJar.getCookies(domain).none { it.name.contains("NetShield") }) {
val cookie = runBlocking { response.parseHtml().getNetShieldCookie() } ?: return response
if (!isNetShieldProtected) {
return response
}
val contentType = response.mimeType
if (
contentType?.endsWith("/html") != false &&
context.cookieJar.getCookies(domain).none { it.name.contains("NetShield") }
) {
val cookie = runBlocking { response.copy().parseHtml().getNetShieldCookie() } ?: return response
context.cookieJar.insertCookie(domain, cookie)
return chain.proceed(response.request.newBuilder().build())
return chain.proceed(response.request.newBuilder().build()).also {
response.closeQuietly()
}
}
return response
}
private suspend fun Document.getNetShieldCookie(): Cookie? {
private suspend fun Document.getNetShieldCookie(): Cookie? = runCatchingCancellable {
val script = select("script").firstNotNullOfOrNull { s ->
s.html().takeIf { x -> x.contains("slowAES.decrypt") }
} ?: return null
} ?: return@runCatchingCancellable null
val min = webClient.httpGet("https://$domain/min.js").parseRaw()
val res = context.evaluateJs(min + "\n\n" + script.replace("document.cookie =", "return"))
return Cookie.parse(baseUri().toHttpUrl(), res ?: return null)
}
val res = context.evaluateJs(min + "\n\n" + script.replace(Regex("document.cookie\\s*=\\s*"), "return "))
res?.let {
Cookie.parse(baseUri().toHttpUrl(), it)
}
}.getOrNull()
}

@ -15,6 +15,7 @@ internal class SwaTeam(context: MangaLoaderContext) :
override val datePattern = "MMMM dd, yyyy"
override val selectMangaList = ".listupd .bs .bsx"
override val selectMangaListImg = "img"
override val isNetShieldProtected = true
override suspend fun getListPage(
page: Int,

@ -13,4 +13,5 @@ internal class MangaSusuku(context: MangaLoaderContext) :
override val listUrl = "/komik"
override val datePattern = "MMM d, yyyy"
override val sourceLocale: Locale = Locale.ENGLISH
override val isNetShieldProtected = true
}

@ -9,4 +9,5 @@ import org.koitharu.kotatsu.parsers.site.mangareader.MangaReaderParser
internal class AfroditScans(context: MangaLoaderContext) :
MangaReaderParser(context, MangaSource.AFRODITSCANS, "afroditscans.com", pageSize = 20, searchPageSize = 10) {
override val datePattern = "MMM d, yyyy"
override val isNetShieldProtected = true
}

@ -14,7 +14,7 @@ suspend fun Call.await(): Response = suspendCancellableCoroutine { continuation
}
val Response.mimeType: String?
get() = body?.contentType()?.run { "$type/$subtype" }
get() = header("content-type")?.takeUnless { it.isEmpty() }
val Response.contentDisposition: String?
get() = header("Content-Disposition")
@ -27,3 +27,7 @@ fun Headers.Builder.mergeWith(other: Headers, replaceExisting: Boolean): Headers
}
return this
}
fun Response.copy() = newBuilder()
.body(peekBody(Long.MAX_VALUE))
.build()

Loading…
Cancel
Save