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 hasQuickSearch = false
override val hasMainPage = true override val hasMainPage = true
override val supportedTypes = setOf(TvType.Anime, TvType.AnimeMovie, TvType.ONA) override val supportedTypes = setOf(TvType.Anime, TvType.AnimeMovie, TvType.ONA)
private var ddosGuardKiller: DdosGuardKiller? = null private var ddosGuardKiller = DdosGuardKiller(true)
// Because otherwise Network on main thread when just initializing the provider
init {
thread {
ddosGuardKiller = DdosGuardKiller(true)
}
}
/*private fun loadToken(): Boolean { /*private fun loadToken(): Boolean {
return try { return try {

View File

@ -1,5 +1,6 @@
package com.lagradost.cloudstream3.network package com.lagradost.cloudstream3.network
import androidx.annotation.AnyThread
import com.lagradost.cloudstream3.app import com.lagradost.cloudstream3.app
import okhttp3.Interceptor import okhttp3.Interceptor
import okhttp3.Request import okhttp3.Request
@ -9,26 +10,31 @@ import okhttp3.Response
* @param alwaysBypass will pre-emptively fetch ddos guard cookies if true. * @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 * 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 { class DdosGuardKiller(private val alwaysBypass: Boolean) : Interceptor {
val savedCookiesMap = mutableMapOf<String, Map<String, String>>() 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 var ddosBypassPath: String? = null
private val resp = app.get(
"https://check.ddos-guard.net/check.js"
).text
private val ddosBypassPath = Regex("'(.*?)'").find(resp)?.groupValues?.get(1)
override fun intercept(chain: Interceptor.Chain): Response { override fun intercept(chain: Interceptor.Chain): Response {
val request = chain.request() val request = chain.request()
if (alwaysBypass) return bypassDdosGuard(request) if (alwaysBypass) return bypassDdosGuard(request)
val response = chain.proceed(request) val response = chain.proceed(request)
return if (response.code == 403){ return if (response.code == 403) {
bypassDdosGuard(request) bypassDdosGuard(request)
} else response } else response
} }
private fun bypassDdosGuard(request: Request): Response { 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 = val cookies =
savedCookiesMap[request.url.host] savedCookiesMap[request.url.host]
// If no cookies are found fetch and save em. // If no cookies are found fetch and save em.