forked from recloudstream/cloudstream
improved the Sflix bypass
This commit is contained in:
parent
2204564de9
commit
5ba3b1f685
1 changed files with 35 additions and 10 deletions
|
@ -7,6 +7,7 @@ import com.lagradost.cloudstream3.APIHolder.unixTimeMS
|
||||||
import com.lagradost.cloudstream3.LoadResponse.Companion.addActors
|
import com.lagradost.cloudstream3.LoadResponse.Companion.addActors
|
||||||
import com.lagradost.cloudstream3.LoadResponse.Companion.setDuration
|
import com.lagradost.cloudstream3.LoadResponse.Companion.setDuration
|
||||||
import com.lagradost.cloudstream3.mvvm.suspendSafeApiCall
|
import com.lagradost.cloudstream3.mvvm.suspendSafeApiCall
|
||||||
|
import com.lagradost.cloudstream3.network.AppResponse
|
||||||
import com.lagradost.cloudstream3.network.WebViewResolver
|
import com.lagradost.cloudstream3.network.WebViewResolver
|
||||||
import com.lagradost.cloudstream3.network.getRequestCreator
|
import com.lagradost.cloudstream3.network.getRequestCreator
|
||||||
import com.lagradost.cloudstream3.network.text
|
import com.lagradost.cloudstream3.network.text
|
||||||
|
@ -365,17 +366,41 @@ class SflixProvider(providerUrl: String, providerName: String) : MainAPI() {
|
||||||
return code.reversed()
|
return code.reversed()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates a session
|
||||||
|
* */
|
||||||
|
private suspend fun negotiateNewSid(baseUrl: String): PollingData? {
|
||||||
|
// Tries multiple times
|
||||||
|
for (i in 1..5) {
|
||||||
|
val jsonText =
|
||||||
|
app.get("$baseUrl&t=${generateTimeStamp()}").text.replaceBefore("{", "")
|
||||||
|
// println("Negotiated sid $jsonText")
|
||||||
|
parseJson<PollingData?>(jsonText)?.let { return it }
|
||||||
|
delay(1000L * i)
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates a new session if the request fails
|
||||||
|
* */
|
||||||
|
private suspend fun getUpdatedData(response: AppResponse, data: PollingData, baseUrl: String) : PollingData {
|
||||||
|
if (!response.response.isSuccessful){
|
||||||
|
return negotiateNewSid(baseUrl) ?: data
|
||||||
|
}
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
|
||||||
override suspend fun extractorVerifierJob(extractorData: String?) {
|
override suspend fun extractorVerifierJob(extractorData: String?) {
|
||||||
if (extractorData == null) return
|
if (extractorData == null) return
|
||||||
|
|
||||||
val jsonText =
|
|
||||||
app.get("$extractorData&t=${generateTimeStamp()}").text.replaceBefore("{", "")
|
|
||||||
val data = parseJson<PollingData>(jsonText)
|
|
||||||
val headers = mapOf(
|
val headers = mapOf(
|
||||||
"User-Agent" to USER_AGENT,
|
"User-Agent" to USER_AGENT,
|
||||||
"Referer" to "https://rabbitstream.net/"
|
"Referer" to "https://rabbitstream.net/"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var data = negotiateNewSid(extractorData) ?: return
|
||||||
// 40 is hardcoded, dunno how it's generated, but it seems to work everywhere.
|
// 40 is hardcoded, dunno how it's generated, but it seems to work everywhere.
|
||||||
// This request is obligatory
|
// This request is obligatory
|
||||||
app.post(
|
app.post(
|
||||||
|
@ -389,7 +414,7 @@ class SflixProvider(providerUrl: String, providerName: String) : MainAPI() {
|
||||||
"$extractorData&t=${generateTimeStamp()}&sid=${data.sid}",
|
"$extractorData&t=${generateTimeStamp()}&sid=${data.sid}",
|
||||||
headers = headers
|
headers = headers
|
||||||
)
|
)
|
||||||
//.also { println("First get ${it.text}") }
|
// .also { println("First get ${it.text}") }
|
||||||
.text.replaceBefore("{", "")
|
.text.replaceBefore("{", "")
|
||||||
).sid
|
).sid
|
||||||
// This response is used in the post requests. Same contents in all it seems.
|
// This response is used in the post requests. Same contents in all it seems.
|
||||||
|
@ -406,14 +431,13 @@ class SflixProvider(providerUrl: String, providerName: String) : MainAPI() {
|
||||||
// Prevents them from fucking us over with doing a while(true){} loop
|
// Prevents them from fucking us over with doing a while(true){} loop
|
||||||
val interval = maxOf(data.pingInterval?.toLong()?.plus(2000) ?: return, 10000L)
|
val interval = maxOf(data.pingInterval?.toLong()?.plus(2000) ?: return, 10000L)
|
||||||
var reconnect = false
|
var reconnect = false
|
||||||
// New SID can be negotiated as above, but not implemented yet as it seems rare.
|
|
||||||
while (true) {
|
while (true) {
|
||||||
val authData = if (reconnect) """
|
val authData = if (reconnect) """
|
||||||
42["_reconnect", "$reconnectSid"]
|
42["_reconnect", "$reconnectSid"]
|
||||||
""".trimIndent() else authInt
|
""".trimIndent() else authInt
|
||||||
|
|
||||||
val url = "${extractorData}&t=${generateTimeStamp()}&sid=${data.sid}"
|
val url = "${extractorData}&t=${generateTimeStamp()}&sid=${data.sid}"
|
||||||
app.post(url, data = authData, headers = headers)
|
data = getUpdatedData(app.post(url, data = authData, headers = headers), data, extractorData)
|
||||||
//.also { println("Sflix post job ${it.text}") }
|
//.also { println("Sflix post job ${it.text}") }
|
||||||
Log.d(this.name, "Running Sflix job $url")
|
Log.d(this.name, "Running Sflix job $url")
|
||||||
|
|
||||||
|
@ -423,15 +447,16 @@ class SflixProvider(providerUrl: String, providerName: String) : MainAPI() {
|
||||||
"${extractorData}&t=${generateTimeStamp()}&sid=${data.sid}",
|
"${extractorData}&t=${generateTimeStamp()}&sid=${data.sid}",
|
||||||
timeout = 60,
|
timeout = 60,
|
||||||
headers = headers
|
headers = headers
|
||||||
).text //.also { println("Sflix get job $it") }
|
)
|
||||||
if (getResponse.contains("sid")) {
|
// .also { println("Sflix get job ${it.text}") }
|
||||||
|
if (getResponse.text.contains("sid")) {
|
||||||
reconnect = true
|
reconnect = true
|
||||||
// println("Reconnecting")
|
// println("Reconnecting")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Always waits even if the get response is instant, to prevent a while true loop.
|
// Always waits even if the get response is instant, to prevent a while true loop.
|
||||||
if (time < interval - 4000)
|
if (time < interval - 4000)
|
||||||
delay(interval)
|
delay(4000)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue