forked from recloudstream/cloudstream
fixed smelly code
This commit is contained in:
parent
40c454aed9
commit
2580455cd5
2 changed files with 13 additions and 14 deletions
|
@ -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 {
|
||||
|
|
|
@ -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,26 +10,31 @@ 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()
|
||||
if (alwaysBypass) return bypassDdosGuard(request)
|
||||
|
||||
val response = chain.proceed(request)
|
||||
return if (response.code == 403){
|
||||
return if (response.code == 403) {
|
||||
bypassDdosGuard(request)
|
||||
} else 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 =
|
||||
savedCookiesMap[request.url.host]
|
||||
// If no cookies are found fetch and save em.
|
||||
|
|
Loading…
Reference in a new issue