From 28bb93372b087cb64f1a2ac8350cf39307135134 Mon Sep 17 00:00:00 2001 From: Blatzar <46196380+Blatzar@users.noreply.github.com> Date: Thu, 14 Jul 2022 00:51:24 +0000 Subject: [PATCH] Olgply fixes --- .../movieproviders/OlgplyProvider.kt | 94 ++++++++++++++++--- 1 file changed, 79 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/movieproviders/OlgplyProvider.kt b/app/src/main/java/com/lagradost/cloudstream3/movieproviders/OlgplyProvider.kt index 8bcc546c..9dbc506a 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/movieproviders/OlgplyProvider.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/movieproviders/OlgplyProvider.kt @@ -5,9 +5,14 @@ import com.lagradost.cloudstream3.TvType import com.lagradost.cloudstream3.app import com.lagradost.cloudstream3.metaproviders.TmdbLink import com.lagradost.cloudstream3.metaproviders.TmdbProvider +import com.lagradost.cloudstream3.network.WebViewResolver import com.lagradost.cloudstream3.utils.AppUtils.parseJson import com.lagradost.cloudstream3.utils.ExtractorLink import com.lagradost.cloudstream3.utils.Qualities +import com.lagradost.nicehttp.requestCreator +import org.mozilla.javascript.Context +import org.mozilla.javascript.Scriptable +import org.mozilla.javascript.ScriptableObject class OlgplyProvider : TmdbProvider() { override var mainUrl = "https://olgply.com" @@ -17,6 +22,29 @@ class OlgplyProvider : TmdbProvider() { override val useMetaLoadResponse = true override val supportedTypes = setOf(TvType.TvSeries, TvType.Movie) + private suspend fun loadLinksWithWebView( + url: String, +// subtitleCallback: (SubtitleFile) -> Unit, + callback: (ExtractorLink) -> Unit + ) { + val foundVideo = WebViewResolver( + Regex("""movies4discord""") + ).resolveUsingWebView( + requestCreator("GET", url) + ).first ?: return + + callback.invoke( + ExtractorLink( + this.name, + "Movies4Discord", + foundVideo.url.toString(), + "", + Qualities.Unknown.value + ) + ) + } + + override suspend fun loadLinks( data: String, isCasting: Boolean, @@ -24,24 +52,60 @@ class OlgplyProvider : TmdbProvider() { callback: (ExtractorLink) -> Unit ): Boolean { val mappedData = parseJson(data) - val imdbId = mappedData.imdbID ?: return false - val iframeUrl = - "$mainUrl/api/?imdb=$imdbId${mappedData.season?.let { "&season=$it" } ?: ""}${mappedData.episode?.let { "&episode=$it" } ?: ""}" + val tmdbId = mappedData.tmdbID ?: return false + val jsRegex = Regex("""eval\(.*\);""") - val iframeRegex = Regex("""file:.*?"([^"]*)""") + val apiUrl = + "https://olgply.xyz/${tmdbId}${mappedData.season?.let { "/$it" } ?: ""}${mappedData.episode?.let { "/$it" } ?: ""}" + val html = + app.get(apiUrl).text + val rhino = Context.enter() + rhino.optimizationLevel = -1 + val scope: Scriptable = rhino.initSafeStandardObjects() + val documentJs = """ + Plyr = function(){}; + + hlsPrototype = { + loadSource(url) { + this.url = url; + } + }; - val html = app.get(iframeUrl).text - val link = iframeRegex.find(html)?.groupValues?.getOrNull(1) ?: return false - callback.invoke( - ExtractorLink( - this.name, - this.name, - link, - this.mainUrl + "/", - Qualities.Unknown.value, - headers = mapOf("range" to "bytes=0-") + function Hls() {}; + Hls.isSupported = function(){return true}; + + Hls.prototype = hlsPrototype; + Hls.prototype.constructor = Hls; + + document = { + "querySelector" : function() {} + }; + """.trimIndent() + + val foundJs = jsRegex.find(html)?.groupValues?.getOrNull(0) ?: return false + try { + rhino.evaluateString(scope, documentJs + foundJs, "JavaScript", 1, null) + } catch (e: Exception) { + } + + val hls = scope.get("hls", scope) as? ScriptableObject + + if (hls != null) { + callback.invoke( + ExtractorLink( + this.name, + this.name, + hls["url"].toString(), + this.mainUrl + "/", + Qualities.Unknown.value, + headers = mapOf("range" to "bytes=0-"), + isM3u8 = true + ) ) - ) + } else { + // Disgraceful fallback, but the js for Movies4Discord refuses to work correctly :( + loadLinksWithWebView(apiUrl, callback) + } return true } } \ No newline at end of file