mirror of
https://github.com/keiyoushi/extensions-source.git
synced 2024-11-25 11:42:47 +01:00
TM: Fix headers (#783)
* TM: Fix headers * more proper header value regex
This commit is contained in:
parent
167e423d5b
commit
59d337d6a0
@ -1,7 +1,7 @@
|
||||
ext {
|
||||
extName = 'Tsuki Mangás'
|
||||
extClass = '.TsukiMangas'
|
||||
extVersionCode = 4
|
||||
extVersionCode = 5
|
||||
isNsfw = true
|
||||
}
|
||||
|
||||
|
@ -13,6 +13,7 @@ import eu.kanade.tachiyomi.source.model.Page
|
||||
import eu.kanade.tachiyomi.source.model.SChapter
|
||||
import eu.kanade.tachiyomi.source.model.SManga
|
||||
import eu.kanade.tachiyomi.source.online.HttpSource
|
||||
import eu.kanade.tachiyomi.util.asJsoup
|
||||
import kotlinx.serialization.json.Json
|
||||
import kotlinx.serialization.json.decodeFromStream
|
||||
import okhttp3.HttpUrl
|
||||
@ -39,6 +40,7 @@ class TsukiMangas : HttpSource() {
|
||||
|
||||
override val client by lazy {
|
||||
network.client.newBuilder()
|
||||
.addInterceptor(::apiHeadersInterceptor)
|
||||
.addInterceptor(::imageCdnSwapper)
|
||||
.rateLimitHost(baseUrl.toHttpUrl(), 2)
|
||||
.rateLimitHost(MAIN_CDN.toHttpUrl(), 1)
|
||||
@ -48,7 +50,6 @@ class TsukiMangas : HttpSource() {
|
||||
|
||||
override fun headersBuilder() = super.headersBuilder()
|
||||
.add("Referer", "$baseUrl/")
|
||||
.add("X-Requested", "HttpsRequests")
|
||||
|
||||
private val json: Json by injectLazy()
|
||||
|
||||
@ -261,6 +262,33 @@ class TsukiMangas : HttpSource() {
|
||||
}
|
||||
}
|
||||
|
||||
private val apiHeadersRegex = Regex("""headers\.common(?:\.(?<key>[0-9A-Za-z_]+)|\[['"](?<key2>[0-9A-Za-z-_]+)['"]])\s*=\s*['"](?<value>[a-zA-Z0-9_ :;.,\\/"'?!(){}\[\]@<>=\-+*#$&`|~^%]+)['"]""")
|
||||
|
||||
private val apiHeaders by lazy {
|
||||
val document = client.newCall(GET(baseUrl, headers)).execute().asJsoup()
|
||||
val scriptUrl = document.selectFirst("script[src*=index-]")!!.absUrl("src")
|
||||
val script = client.newCall(GET(scriptUrl, headers)).execute().body.string()
|
||||
val matches = apiHeadersRegex.findAll(script)
|
||||
|
||||
matches.associate {
|
||||
(it.groups["key"] ?: it.groups["key2"]!!).value to it.groups["value"]!!.value
|
||||
}
|
||||
}
|
||||
|
||||
private fun apiHeadersInterceptor(chain: Interceptor.Chain): Response {
|
||||
val request = chain.request()
|
||||
|
||||
if (!request.url.encodedPath.startsWith(API_PATH)) {
|
||||
return chain.proceed(request)
|
||||
}
|
||||
|
||||
val newRequest = request.newBuilder().apply {
|
||||
apiHeaders.entries.forEach { addHeader(it.key, it.value) }
|
||||
}.build()
|
||||
|
||||
return chain.proceed(newRequest)
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val PREFIX_SEARCH = "id:"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user