mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
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 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 {
|
||||||
|
|
|
@ -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,14 +10,13 @@ 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()
|
||||||
|
@ -29,6 +29,12 @@ class DdosGuardKiller(private val alwaysBypass: Boolean) : Interceptor {
|
||||||
}
|
}
|
||||||
|
|
||||||
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.
|
||||||
|
|
Loading…
Reference in a new issue