fixed smelly code

This commit is contained in:
Blatzar 2021-12-16 21:18:47 +01:00
parent 40c454aed9
commit 2580455cd5
2 changed files with 13 additions and 14 deletions

View file

@ -31,14 +31,7 @@ class TenshiProvider : MainAPI() {
override val hasQuickSearch = false
override val hasMainPage = true
override val supportedTypes = setOf(TvType.Anime, TvType.AnimeMovie, TvType.ONA)
private var ddosGuardKiller: DdosGuardKiller? = null
// Because otherwise Network on main thread when just initializing the provider
init {
thread {
ddosGuardKiller = DdosGuardKiller(true)
}
}
private var ddosGuardKiller = DdosGuardKiller(true)
/*private fun loadToken(): Boolean {
return try {

View file

@ -1,5 +1,6 @@
package com.lagradost.cloudstream3.network
import androidx.annotation.AnyThread
import com.lagradost.cloudstream3.app
import okhttp3.Interceptor
import okhttp3.Request
@ -9,14 +10,13 @@ import okhttp3.Response
* @param alwaysBypass will pre-emptively fetch ddos guard cookies if true.
* If false it will only try to get cookies when a request returns 403
* */
// As seen in https://github.com/anime-dl/anime-downloader/blob/master/anime_downloader/sites/erairaws.py
@AnyThread
class DdosGuardKiller(private val alwaysBypass: Boolean) : Interceptor {
val savedCookiesMap = mutableMapOf<String, Map<String, String>>()
// As seen in https://github.com/anime-dl/anime-downloader/blob/master/anime_downloader/sites/erairaws.py
private val resp = app.get(
"https://check.ddos-guard.net/check.js"
).text
private val ddosBypassPath = Regex("'(.*?)'").find(resp)?.groupValues?.get(1)
private var ddosBypassPath: String? = null
override fun intercept(chain: Interceptor.Chain): Response {
val request = chain.request()
@ -29,6 +29,12 @@ class DdosGuardKiller(private val alwaysBypass: Boolean) : Interceptor {
}
private fun bypassDdosGuard(request: Request): Response {
ddosBypassPath = ddosBypassPath ?: Regex("'(.*?)'").find(
app.get(
"https://check.ddos-guard.net/check.js"
).text
)?.groupValues?.get(1)
val cookies =
savedCookiesMap[request.url.host]
// If no cookies are found fetch and save em.