stremioX: added custom request

This commit is contained in:
hexated 2023-04-16 06:15:07 +07:00
parent 1d420814bd
commit 970186e653
4 changed files with 39 additions and 14 deletions

View file

@ -1,5 +1,5 @@
// use an integer for version numbers
version = 8
version = 9
cloudstream {

View file

@ -1,6 +1,5 @@
package com.hexated
import android.util.Log
import com.fasterxml.jackson.annotation.JsonProperty
import com.hexated.SubsExtractors.invokeOpenSubs
import com.hexated.SubsExtractors.invokeWatchsomuch
@ -11,7 +10,6 @@ import com.lagradost.cloudstream3.utils.*
import com.lagradost.cloudstream3.utils.AppUtils.parseJson
import com.lagradost.cloudstream3.utils.AppUtils.toJson
import com.lagradost.cloudstream3.utils.AppUtils.tryParseJson
import org.json.JSONObject
import java.net.URI
private const val TRACKER_LIST_URL =
@ -65,9 +63,9 @@ class StremioC : MainAPI() {
callback: (ExtractorLink) -> Unit
): Boolean {
val loadData = parseJson<LoadData>(data)
val request = app.get("${mainUrl}/stream/${loadData.type}/${loadData.id}.json")
if (request.isSuccessful) {
val res = tryParseJson<StreamsResponse>(request.text) ?: return false
val request = request("${mainUrl}/stream/${loadData.type}/${loadData.id}.json")
if (request.code.isSuccessful()) {
val res = tryParseJson<StreamsResponse>(request.body.string()) ?: return false
res.streams.forEach { stream ->
stream.runCallback(subtitleCallback, callback)
}
@ -108,8 +106,9 @@ class StremioC : MainAPI() {
AcraApplication.getKey<Array<CustomSite>>(USER_PROVIDER_API)?.toMutableList()
?: mutableListOf()
sites.filter { it.parentJavaClass == "StremioX" }.apmap { site ->
val request = request("${site.url.fixSourceUrl()}/stream/${type}/${id}.json").body.string()
val res =
tryParseJson<StreamsResponse>(app.get("${site.url.fixSourceUrl()}/stream/${type}/${id}.json").text)
tryParseJson<StreamsResponse>(request)
?: return@apmap
res.streams.forEach { stream ->
stream.runCallback(subtitleCallback, callback)

View file

@ -1,6 +1,5 @@
package com.hexated
import android.util.Log
import com.fasterxml.jackson.annotation.JsonProperty
import com.hexated.SubsExtractors.invokeOpenSubs
import com.hexated.SubsExtractors.invokeWatchsomuch
@ -9,7 +8,6 @@ import com.lagradost.cloudstream3.LoadResponse.Companion.addTrailer
import com.lagradost.cloudstream3.utils.*
import com.lagradost.cloudstream3.utils.AppUtils.parseJson
import com.lagradost.cloudstream3.utils.AppUtils.toJson
import org.json.JSONObject
import java.net.URI
import java.util.ArrayList
import kotlin.math.roundToInt
@ -26,8 +24,6 @@ open class StremioX : MainAPI() {
companion object {
const val TRACKER_LIST_URL =
"https://raw.githubusercontent.com/ngosang/trackerslist/master/trackers_best.txt"
const val openSubAPI = "https://opensubtitles.strem.io/stremio/v1"
const val watchSomuchAPI = "https://watchsomuch.tv"
private const val tmdbAPI = "https://api.themoviedb.org/3"
private val apiKey =
base64DecodeAPI("ZTM=NTg=MjM=MjM=ODc=MzI=OGQ=MmE=Nzk=Nzk=ZjI=NTA=NDY=NDA=MzA=YjA=") // PLEASE DON'T STEAL
@ -241,7 +237,7 @@ open class StremioX : MainAPI() {
} else {
"$fixMainUrl/stream/series/$imdbId:$season:$episode.json"
}
val res = AppUtils.tryParseJson<StreamsResponse>(app.get(url).text) ?: return
val res = AppUtils.tryParseJson<StreamsResponse>(request(url).body.string()) ?: return
res.streams.forEach { stream ->
stream.runCallback(subtitleCallback, callback)
}

View file

@ -1,10 +1,40 @@
package com.hexated
fun String.fixSourceUrl() : String {
import com.lagradost.nicehttp.Requests.Companion.await
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.Response
import java.util.concurrent.TimeUnit
const val defaultTimeOut = 30L
suspend fun request(
url: String,
allowRedirects: Boolean = true,
timeout: Long = defaultTimeOut
): Response {
val client = OkHttpClient().newBuilder()
.connectTimeout(timeout, TimeUnit.SECONDS)
.readTimeout(timeout, TimeUnit.SECONDS)
.writeTimeout(timeout, TimeUnit.SECONDS)
.followRedirects(allowRedirects)
.followSslRedirects(allowRedirects)
.build()
val request: Request = Request.Builder()
.url(url)
.build()
return client.newCall(request).await()
}
fun Int.isSuccessful() : Boolean {
return this in 200..299
}
fun String.fixSourceUrl(): String {
return this.replace("/manifest.json", "").replace("stremio://", "https://")
}
fun fixRDSourceName(name: String?, title: String?) : String {
fun fixRDSourceName(name: String?, title: String?): String {
return when {
name?.contains("[RD+]", true) == true -> "[RD+] $title"
name?.contains("[RD download]", true) == true -> "[RD] $title"