Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
jackjohn committed Dec 1, 2023
1 parent cb0d83a commit f9b1161
Showing 1 changed file with 6 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.lagradost.cloudstream3.utils.ExtractorLink
import com.lagradost.cloudstream3.utils.Qualities
import com.lagradost.cloudstream3.utils.loadExtractor
import com.lagradost.nicehttp.requestCreator
import okhttp3.Headers
import okhttp3.HttpUrl
import org.jsoup.Jsoup
import org.jsoup.nodes.Element
Expand Down Expand Up @@ -203,15 +204,8 @@ class KuramanimeProvider : MainAPI() {

argamap(
{
val token = res.select("meta[name=csrf-token]").attr("content")
val auth = getAuth(data)
headers = mapOf(
"Accept" to "application/json, text/javascript, */*; q=0.01",
"Authorization" to "${auth.authHeader}",
"X-Fuck-ID" to "${auth.fidHeader}",
"X-Requested-With" to "XMLHttpRequest",
"X-CSRF-TOKEN" to token
).filter { !it.value.isNullOrEmpty() }
headers = auth.authHeader?.associate { it.first to it.second }?.filter { it.key != "Cookie" }!!
cookies = req.cookies
res.select("select#changeServer option").apmap { source ->
val server = source.attr("value")
Expand Down Expand Up @@ -251,34 +245,26 @@ class KuramanimeProvider : MainAPI() {
"GET", url
)
)
val addition = found.second.find { !it.headers["Authorization"].isNullOrBlank() || !it.headers["X-Fuck-ID"].isNullOrBlank() }
return AuthParams(found.first?.url, addition?.url.toString(), addition?.headers?.get("Authorization"), addition?.headers?.get("X-Fuck-ID"))
val addition = found.second.findLast { it.headers["X-Requested-With"] == "XMLHttpRequest" }
return AuthParams(found.first?.url, addition?.url.toString(), addition?.headers)
}

private suspend fun getAuth(url: String) = params ?: fetchAuth(url).also { params = it }

private suspend fun getMisc(url: String?): String {
val misc = app.get(
"$url",
headers = headers + mapOf("X-Request-ID" to getRequestId()),
headers = headers,
cookies = cookies
)
cookies = misc.cookies
return misc.parsed()
}

private fun getRequestId(length: Int = 8): String {
val allowedChars = ('a'..'z') + ('0'..'9')
return (1..length)
.map { allowedChars.random() }
.joinToString("")
}

data class AuthParams (
val serverUrl: HttpUrl?,
val authUrl: String?,
val authHeader: String?,
val fidHeader: String?,
val authHeader: Headers?,
)

}

0 comments on commit f9b1161

Please sign in to comment.