From 70c14d116cd2398505d860934b6cb3690f6891cb Mon Sep 17 00:00:00 2001 From: Blatzar <46196380+Blatzar@users.noreply.github.com> Date: Thu, 28 Oct 2021 13:28:19 +0200 Subject: [PATCH] fixed Sflix and Zoro --- .../animeproviders/ZoroProvider.kt | 31 ++++++++++++++----- .../movieproviders/SflixProvider.kt | 11 +++---- .../cloudstream3/network/Requests.kt | 2 +- .../cloudstream3/network/WebViewResolver.kt | 24 ++++++++++++-- 4 files changed, 51 insertions(+), 17 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 e975af4d..f13d79e3 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/animeproviders/ZoroProvider.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/animeproviders/ZoroProvider.kt @@ -250,7 +250,10 @@ 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"), + 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""") ) @@ -284,17 +287,35 @@ class ZoroProvider : MainAPI() { Regex("""/getSources""") ) ) +// println("RES TEXT ${res.text}") 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)) + Pair( + it.first, + getM3u8FromRapidCloud( + mapper.readValue( + get( + link, + res.request.headers.toMap() + ).text + ).link + ) + ) } responses.forEach { if (it.second.contains("(it.second) + + mapped.tracks?.forEach { track -> + track?.toSubtitleFile()?.let { subtitleFile -> + subtitleCallback.invoke(subtitleFile) + } + } + val list = listOf( mapped.sources to "source 1", mapped.sources1 to "source 2", @@ -307,12 +328,6 @@ class ZoroProvider : MainAPI() { a?.toExtractorLink(this, subList.second + " - ${it.first}")?.forEach(callback) } } - - mapped.tracks?.forEach { track -> - track?.toSubtitleFile()?.let { subtitleFile -> - subtitleCallback.invoke(subtitleFile) - } - } } return true diff --git a/app/src/main/java/com/lagradost/cloudstream3/movieproviders/SflixProvider.kt b/app/src/main/java/com/lagradost/cloudstream3/movieproviders/SflixProvider.kt index 9903e515..4ba21ac8 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/movieproviders/SflixProvider.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/movieproviders/SflixProvider.kt @@ -297,7 +297,11 @@ class SflixProvider : MainAPI() { ).text val mapped = mapper.readValue(sources) - + mapped.tracks?.forEach { + it?.toSubtitleFile()?.let { subtitleFile -> + subtitleCallback.invoke(subtitleFile) + } + } val list = listOf( mapped.sources to "source 1", mapped.sources1 to "source 2", @@ -309,11 +313,6 @@ class SflixProvider : MainAPI() { it?.toExtractorLink(this, subList.second)?.forEach(callback) } } - mapped.tracks?.forEach { - it?.toSubtitleFile()?.let { subtitleFile -> - subtitleCallback.invoke(subtitleFile) - } - } return true } diff --git a/app/src/main/java/com/lagradost/cloudstream3/network/Requests.kt b/app/src/main/java/com/lagradost/cloudstream3/network/Requests.kt index 018be141..8815be0a 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/network/Requests.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/network/Requests.kt @@ -15,7 +15,7 @@ var baseClient = OkHttpClient() private const val DEFAULT_TIME = 10 private val DEFAULT_TIME_UNIT = TimeUnit.MINUTES private const val DEFAULT_USER_AGENT = USER_AGENT -private val DEFAULT_HEADERS = mapOf("User-Agent" to DEFAULT_USER_AGENT) +private val DEFAULT_HEADERS = mapOf("user-agent" to DEFAULT_USER_AGENT) private val DEFAULT_DATA: Map = mapOf() private val DEFAULT_COOKIES: Map = mapOf() private val DEFAULT_REFERER: String? = null 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 f9bc2084..8e4ebbc1 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/network/WebViewResolver.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/network/WebViewResolver.kt @@ -4,12 +4,14 @@ import android.annotation.SuppressLint import android.net.http.SslError import android.webkit.* import com.lagradost.cloudstream3.AcraApplication +import com.lagradost.cloudstream3.USER_AGENT import com.lagradost.cloudstream3.utils.Coroutines.main import kotlinx.coroutines.delay import kotlinx.coroutines.runBlocking import okhttp3.Interceptor import okhttp3.Request import okhttp3.Response +import java.net.URI import java.util.concurrent.TimeUnit class WebViewResolver(val interceptUrl: Regex) : Interceptor { @@ -48,6 +50,7 @@ class WebViewResolver(val interceptUrl: Regex) : Interceptor { // Bare minimum to bypass captcha settings.javaScriptEnabled = true settings.domStorageEnabled = true + settings.userAgentString = USER_AGENT } webView?.webViewClient = object : WebViewClient() { @@ -56,6 +59,7 @@ class WebViewResolver(val interceptUrl: Regex) : Interceptor { request: WebResourceRequest ): WebResourceResponse? { val webViewUrl = request.url.toString() +// println("Loading WebView URL: $webViewUrl") if (interceptUrl.containsMatchIn(webViewUrl)) { fixedRequest = getRequestCreator( @@ -70,12 +74,28 @@ class WebViewResolver(val interceptUrl: Regex) : Interceptor { println("Web-view request finished: $webViewUrl") destroyWebView() + return null } + // Suppress image requests as we don't display them anywhere + // Less data, low chance of causing issues. + val blacklistedFiles = listOf(".jpg", ".png", ".webp", ".jpeg", ".webm", ".mp4") + + /** NOTE! request.requestHeaders is not perfect! + * They don't contain all the headers the browser actually gives. + * Overriding with okhttp might fuck up otherwise working requests, + * e.g the recaptcha request. + * **/ return try { when { - // suppress favicon requests as we don't display them anywhere - webViewUrl.endsWith("/favicon.ico") -> WebResourceResponse("image/png", null, null) + blacklistedFiles.any { URI(webViewUrl).path.endsWith(it) } || webViewUrl.endsWith( + "/favicon.ico" + ) -> WebResourceResponse( + "image/png", + null, + null + ) + webViewUrl.contains("recaptcha") -> super.shouldInterceptRequest(view, request) request.method == "GET" -> get(