added sub/dub servers to zoro

This commit is contained in:
ArjixWasTaken 2021-10-10 23:01:02 +03:00
parent 24dbf00c67
commit ede655d3c7
2 changed files with 54 additions and 20 deletions

View file

@ -1,5 +1,6 @@
package com.lagradost.cloudstream3.animeproviders package com.lagradost.cloudstream3.animeproviders
import androidx.core.net.toUri
import com.fasterxml.jackson.annotation.JsonProperty import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.module.kotlin.readValue import com.fasterxml.jackson.module.kotlin.readValue
import com.lagradost.cloudstream3.* import com.lagradost.cloudstream3.*
@ -9,6 +10,7 @@ import com.lagradost.cloudstream3.movieproviders.SflixProvider.Companion.toSubti
import com.lagradost.cloudstream3.network.WebViewResolver import com.lagradost.cloudstream3.network.WebViewResolver
import com.lagradost.cloudstream3.network.get import com.lagradost.cloudstream3.network.get
import com.lagradost.cloudstream3.network.text import com.lagradost.cloudstream3.network.text
import com.lagradost.cloudstream3.network.url
import com.lagradost.cloudstream3.utils.ExtractorLink import com.lagradost.cloudstream3.utils.ExtractorLink
import org.jsoup.Jsoup import org.jsoup.Jsoup
import org.jsoup.nodes.Element import org.jsoup.nodes.Element
@ -247,6 +249,20 @@ class ZoroProvider : MainAPI() {
) )
} }
private fun getM3u8FromRapidCloud(url: String): String {
return get(
"$url&autoPlay=1&oa=0",
headers = mapOf("Referer" to "https://zoro.to/", "User-Agent" to "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:94.0) Gecko/20100101 Firefox/94.0"),
interceptor = WebViewResolver(
Regex("""/getSources""")
)
).text
}
private data class rapidCloudResponse(
@JsonProperty("link") val link: String
)
override fun loadLinks( override fun loadLinks(
data: String, data: String,
isCasting: Boolean, isCasting: Boolean,
@ -256,15 +272,31 @@ class ZoroProvider : MainAPI() {
// Copy pasted from Sflix :) // Copy pasted from Sflix :)
val sources = get( val servers: List<Pair<DubStatus, String>> = Jsoup.parse(
mapper.readValue<Response>(
get("$mainUrl/ajax/v2/episode/servers?episodeId=" + data.split("=")[1]).text
).html
).select(".server-item[data-type][data-id]").map {
Pair(if (it.attr("data-type") == "sub") DubStatus.Subbed else DubStatus.Dubbed, it.attr("data-id")!!)
}
val res = get(
data, data,
interceptor = WebViewResolver( interceptor = WebViewResolver(
Regex("""/getSources""") Regex("""/getSources""")
) )
).text )
val mapped = mapper.readValue<SflixProvider.SourceObject>(sources) val recaptchaToken = res.request.url.queryParameter("_token")
val responses = servers.map {
val link = "$mainUrl/ajax/v2/episode/sources?id=${it.second}&_token=$recaptchaToken"
Pair(it.first, getM3u8FromRapidCloud(mapper.readValue<rapidCloudResponse>(get(link, res.request.headers.toMap()).text).link))
}
responses.forEach {
if (it.second.contains("<html")) return@forEach
val mapped = mapper.readValue<SflixProvider.SourceObject>(it.second)
val list = listOf( val list = listOf(
mapped.sources to "source 1", mapped.sources to "source 1",
mapped.sources1 to "source 2", mapped.sources1 to "source 2",
@ -273,16 +305,18 @@ class ZoroProvider : MainAPI() {
) )
list.forEach { subList -> list.forEach { subList ->
subList.first?.forEach { subList.first?.forEach { a ->
it?.toExtractorLink(this, subList.second)?.forEach(callback) a?.toExtractorLink(this, subList.second + " - ${it.first}")?.forEach(callback)
} }
} }
mapped.tracks?.forEach { mapped.tracks?.forEach { track ->
it?.toSubtitleFile()?.let { subtitleFile -> track?.toSubtitleFile()?.let { subtitleFile ->
subtitleCallback.invoke(subtitleFile) subtitleCallback.invoke(subtitleFile)
} }
} }
}
return true return true
} }
} }

View file

@ -24,6 +24,7 @@ class WebViewResolver(val interceptUrl: Regex) : Interceptor {
@SuppressLint("SetJavaScriptEnabled") @SuppressLint("SetJavaScriptEnabled")
suspend fun resolveUsingWebView(request: Request): Request? { suspend fun resolveUsingWebView(request: Request): Request? {
val url = request.url.toString() val url = request.url.toString()
val headers = request.headers
println("Initial web-view request: $url") println("Initial web-view request: $url")
var webView: WebView? = null var webView: WebView? = null
@ -77,8 +78,7 @@ class WebViewResolver(val interceptUrl: Regex) : Interceptor {
handler?.proceed() // Ignore ssl issues handler?.proceed() // Ignore ssl issues
} }
} }
webView?.loadUrl(url, headers.toMap())
webView?.loadUrl(url)
} }
var loop = 0 var loop = 0