From ede655d3c7ac953e4ac6b8b845d31befe8c1178a Mon Sep 17 00:00:00 2001 From: ArjixWasTaken <53124886+ArjixWasTaken@users.noreply.github.com> Date: Sun, 10 Oct 2021 23:01:02 +0300 Subject: [PATCH] added sub/dub servers to zoro --- .../animeproviders/ZoroProvider.kt | 70 ++++++++++++++----- .../cloudstream3/network/WebViewResolver.kt | 4 +- 2 files changed, 54 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/animeproviders/ZoroProvider.kt b/app/src/main/java/com/lagradost/cloudstream3/animeproviders/ZoroProvider.kt index 47d0e8cc..901631e6 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/animeproviders/ZoroProvider.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/animeproviders/ZoroProvider.kt @@ -1,5 +1,6 @@ package com.lagradost.cloudstream3.animeproviders +import androidx.core.net.toUri import com.fasterxml.jackson.annotation.JsonProperty import com.fasterxml.jackson.module.kotlin.readValue 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.get import com.lagradost.cloudstream3.network.text +import com.lagradost.cloudstream3.network.url import com.lagradost.cloudstream3.utils.ExtractorLink import org.jsoup.Jsoup 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( data: String, isCasting: Boolean, @@ -256,33 +272,51 @@ class ZoroProvider : MainAPI() { // Copy pasted from Sflix :) - val sources = get( + val servers: List> = Jsoup.parse( + mapper.readValue( + 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, interceptor = WebViewResolver( Regex("""/getSources""") ) - ).text - - val mapped = mapper.readValue(sources) - - val list = listOf( - mapped.sources to "source 1", - mapped.sources1 to "source 2", - mapped.sources2 to "source 3", - mapped.sourcesBackup to "source backup" ) - list.forEach { subList -> - subList.first?.forEach { - it?.toExtractorLink(this, subList.second)?.forEach(callback) + 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(get(link, res.request.headers.toMap()).text).link)) + } + + responses.forEach { + if (it.second.contains("(it.second) + val list = listOf( + mapped.sources to "source 1", + mapped.sources1 to "source 2", + mapped.sources2 to "source 3", + mapped.sourcesBackup to "source backup" + ) + + list.forEach { subList -> + subList.first?.forEach { a -> + a?.toExtractorLink(this, subList.second + " - ${it.first}")?.forEach(callback) + } + } + + mapped.tracks?.forEach { track -> + track?.toSubtitleFile()?.let { subtitleFile -> + subtitleCallback.invoke(subtitleFile) + } } } - mapped.tracks?.forEach { - it?.toSubtitleFile()?.let { subtitleFile -> - subtitleCallback.invoke(subtitleFile) - } - } return true } } diff --git a/app/src/main/java/com/lagradost/cloudstream3/network/WebViewResolver.kt b/app/src/main/java/com/lagradost/cloudstream3/network/WebViewResolver.kt index 7d297920..c92b70c0 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/network/WebViewResolver.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/network/WebViewResolver.kt @@ -24,6 +24,7 @@ class WebViewResolver(val interceptUrl: Regex) : Interceptor { @SuppressLint("SetJavaScriptEnabled") suspend fun resolveUsingWebView(request: Request): Request? { val url = request.url.toString() + val headers = request.headers println("Initial web-view request: $url") var webView: WebView? = null @@ -77,8 +78,7 @@ class WebViewResolver(val interceptUrl: Regex) : Interceptor { handler?.proceed() // Ignore ssl issues } } - - webView?.loadUrl(url) + webView?.loadUrl(url, headers.toMap()) } var loop = 0