From 6aaf24500e1a42ad1990a0be944f078900d530de Mon Sep 17 00:00:00 2001 From: Stormunblessed <86633626+Stormunblessed@users.noreply.github.com> Date: Sat, 12 Mar 2022 13:02:30 +0000 Subject: [PATCH] 2embed and Fixes on AllMoviesForYouProvider (#778) * Provider and Fixes on AllMoviesForYouProvider.kt --- .../com/lagradost/cloudstream3/MainAPI.kt | 1 + .../cloudstream3/extractors/Zplayer.kt | 5 + .../movieproviders/AllMoviesForYouProvider.kt | 157 +++++++----------- .../movieproviders/TwoEmbedProvider.kt | 69 ++++++++ .../cloudstream3/utils/ExtractorApi.kt | 3 +- 5 files changed, 139 insertions(+), 96 deletions(-) create mode 100644 app/src/main/java/com/lagradost/cloudstream3/movieproviders/TwoEmbedProvider.kt diff --git a/app/src/main/java/com/lagradost/cloudstream3/MainAPI.kt b/app/src/main/java/com/lagradost/cloudstream3/MainAPI.kt index 1113bcc3..9a69b95a 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/MainAPI.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/MainAPI.kt @@ -81,6 +81,7 @@ object APIHolder { PinoyHDXyzProvider(), PinoyMoviesEsProvider(), TrailersTwoProvider(), + TwoEmbedProvider(), DramaSeeProvider(), WatchAsianProvider(), KdramaHoodProvider(), diff --git a/app/src/main/java/com/lagradost/cloudstream3/extractors/Zplayer.kt b/app/src/main/java/com/lagradost/cloudstream3/extractors/Zplayer.kt index 5a5201ae..561f8b9c 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/extractors/Zplayer.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/extractors/Zplayer.kt @@ -14,6 +14,11 @@ class Upstream: ZplayerV2() { override val mainUrl: String = "https://upstream.to" } +class Streamhub2: ZplayerV2() { + override val name: String = "Streamhub" //Here 'cause works + override val mainUrl: String = "https://streamhub.to" +} + open class ZplayerV2 : ExtractorApi() { override val name = "Zplayer V2" override val mainUrl = "https://v2.zplayer.live" diff --git a/app/src/main/java/com/lagradost/cloudstream3/movieproviders/AllMoviesForYouProvider.kt b/app/src/main/java/com/lagradost/cloudstream3/movieproviders/AllMoviesForYouProvider.kt index 9deb4e05..d7ec624d 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/movieproviders/AllMoviesForYouProvider.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/movieproviders/AllMoviesForYouProvider.kt @@ -1,17 +1,11 @@ package com.lagradost.cloudstream3.movieproviders -import com.fasterxml.jackson.module.kotlin.readValue import com.lagradost.cloudstream3.* import com.lagradost.cloudstream3.LoadResponse.Companion.setDuration -import com.lagradost.cloudstream3.utils.AppUtils.toJson +import com.lagradost.cloudstream3.mvvm.logError import com.lagradost.cloudstream3.utils.ExtractorLink -import com.lagradost.cloudstream3.utils.Qualities -import com.lagradost.cloudstream3.utils.getPostForm import com.lagradost.cloudstream3.utils.loadExtractor -import okio.Buffer import org.jsoup.Jsoup -import org.jsoup.nodes.Document -import java.net.URLDecoder class AllMoviesForYouProvider : MainAPI() { companion object { @@ -27,11 +21,44 @@ class AllMoviesForYouProvider : MainAPI() { // Fetching movies will not work if this link is outdated. override val mainUrl = "https://allmoviesforyou.net" override val name = "AllMoviesForYou" + override val hasMainPage = true override val supportedTypes = setOf( TvType.Movie, TvType.TvSeries ) + override suspend fun getMainPage(): HomePageResponse { + val items = ArrayList() + val soup = app.get(mainUrl).document + val urls = listOf( + Pair("Movies", "section[data-id=movies] article.TPost.B"), + Pair("TV Series", "section[data-id=series] article.TPost.B"), + ) + for ((name, element) in urls) { + try { + val home = soup.select(element).map { + val title = it.selectFirst("h2.title").text() + val link = it.selectFirst("a").attr("href") + TvSeriesSearchResponse( + title, + link, + this.name, + TvType.Movie, + fixUrl(it.selectFirst("figure img").attr("data-src")), + null, + null, + ) + } + + items.add(HomePageList(name, home)) + } catch (e: Exception) { + logError(e) + } + } + if (items.size <= 0) throw ErrorLoadingException() + return HomePageResponse(items) + } + override suspend fun search(query: String): List { val url = "$mainUrl/?s=$query" val document = app.get(url).document @@ -58,23 +85,23 @@ class AllMoviesForYouProvider : MainAPI() { } } - private fun getLink(document: Document): List? { - val list = ArrayList() - Regex("iframe src=\"(.*?)\"").find(document.html())?.groupValues?.get(1)?.let { - list.add(it) - } - document.select("div.OptionBx")?.forEach { element -> - val baseElement = element.selectFirst("> a.Button") - val elementText = element.selectFirst("> p.AAIco-dns")?.text() - if (elementText == "Streamhub" || elementText == "Dood") { - baseElement?.attr("href")?.let { href -> - list.add(href) - } - } - } - - return if (list.isEmpty()) null else list - } +// private fun getLink(document: Document): List? { +// val list = ArrayList() +// Regex("iframe src=\"(.*?)\"").find(document.html())?.groupValues?.get(1)?.let { +// list.add(it) +// } +// document.select("div.OptionBx")?.forEach { element -> +// val baseElement = element.selectFirst("> a.Button") +// val elementText = element.selectFirst("> p.AAIco-dns")?.text() +// if (elementText == "Streamhub" || elementText == "Dood") { +// baseElement?.attr("href")?.let { href -> +// list.add(href) +// } +// } +// } +// +// return if (list.isEmpty()) null else list +// } override suspend fun load(url: String): LoadResponse { val type = getType(url) @@ -144,14 +171,11 @@ class AllMoviesForYouProvider : MainAPI() { rating ) } else { - val data = getLink(document) - ?: throw ErrorLoadingException("No Links Found") - return newMovieLoadResponse( title, url, type, - data.filter { it != "about:blank" }.toJson() + url ) { posterUrl = backgroundPoster this.year = year?.toIntOrNull() @@ -168,74 +192,17 @@ class AllMoviesForYouProvider : MainAPI() { subtitleCallback: (SubtitleFile) -> Unit, callback: (ExtractorLink) -> Unit ): Boolean { - if (data.startsWith("$mainUrl/episode/")) { - val response = app.get(data).text - getLink(Jsoup.parse(response))?.let { links -> - for (link in links) { - if (link == data) continue - loadLinks(link, isCasting, subtitleCallback, callback) + val doc = app.get(data).document + val iframe = doc.select("body iframe").map { it.attr("src") } + iframe.apmap { id -> + if (id.contains("trembed")) { + val soup = app.get(id).document + soup.select("body iframe").map { + val link = it.attr("src").replace("streamhub.to/d/","streamhub.to/e/") + loadExtractor(link, data, callback) } - return true - } - return false - } else if (data.startsWith(mainUrl) && data != mainUrl) { - val realDataUrl = URLDecoder.decode(data, "UTF-8") - if (data.contains("trdownload")) { - val request = app.get(data) - val requestUrl = request.url - if (requestUrl.startsWith("https://streamhub.to/d/")) { - val buffer = Buffer() - val source = request.body?.source() - var html = "" - var tries = 0 // 20 tries = 163840 bytes = 0.16mb - - while (source?.exhausted() == false && tries < 20) { - // 8192 = max size - source.read(buffer, 8192) - tries += 1 - html += buffer.readUtf8() - } - getPostForm(request.url, html)?.let { form -> - val postDocument = Jsoup.parse(form) - - postDocument.selectFirst("a.downloadbtn")?.attr("href")?.let { url -> - callback( - ExtractorLink( - this.name, - this.name, - url, - mainUrl, - Qualities.Unknown.value - ) - ) - } - } - } else if (requestUrl.startsWith("https://dood")) { - loadExtractor(requestUrl, null, callback) - } else { - callback( - ExtractorLink( - this.name, - this.name, - realDataUrl, - mainUrl, - Qualities.Unknown.value - ) - ) - } - return true - } - val response = app.get(realDataUrl).text - Regex(" - loadExtractor(url.trimStart(), realDataUrl, callback) - } - return true - } else { - val links = mapper.readValue>(data) - for (link in links) { - loadLinks(link, isCasting, subtitleCallback, callback) - } - return true + } else loadExtractor(id, data, callback) } + return true } } diff --git a/app/src/main/java/com/lagradost/cloudstream3/movieproviders/TwoEmbedProvider.kt b/app/src/main/java/com/lagradost/cloudstream3/movieproviders/TwoEmbedProvider.kt new file mode 100644 index 00000000..40c51aa8 --- /dev/null +++ b/app/src/main/java/com/lagradost/cloudstream3/movieproviders/TwoEmbedProvider.kt @@ -0,0 +1,69 @@ +package com.lagradost.cloudstream3.movieproviders + +import com.fasterxml.jackson.annotation.JsonProperty +import com.lagradost.cloudstream3.* +import com.lagradost.cloudstream3.APIHolder.getCaptchaToken +import com.lagradost.cloudstream3.metaproviders.TmdbLink +import com.lagradost.cloudstream3.metaproviders.TmdbProvider +import com.lagradost.cloudstream3.movieproviders.SflixProvider.Companion.extractRabbitStream +import com.lagradost.cloudstream3.utils.AppUtils.parseJson +import com.lagradost.cloudstream3.utils.ExtractorLink +import com.lagradost.cloudstream3.utils.loadExtractor + +class TwoEmbedProvider : TmdbProvider() { + override val apiName = "2Embed" + override val name = "2Embed" + override val mainUrl = "https://www.2embed.ru" + override val useMetaLoadResponse = true + override val instantLinkLoading = false + override val supportedTypes = setOf( + TvType.Movie, + TvType.TvSeries, + ) + + data class EmbedJson ( + @JsonProperty("type") val type: String?, + @JsonProperty("link") val link: String, + @JsonProperty("sources") val sources: List, + @JsonProperty("tracks") val tracks: List? + ) + + override suspend fun loadLinks( + data: String, + isCasting: Boolean, + subtitleCallback: (SubtitleFile) -> Unit, + callback: (ExtractorLink) -> Unit + ): Boolean { + val mappedData = parseJson(data) + val (id, site) = if (mappedData.imdbID != null) listOf( + mappedData.imdbID, + "imdb" + ) else listOf(mappedData.tmdbID.toString(), "tmdb") + val isMovie = mappedData.episode == null && mappedData.season == null + val embedUrl = if (isMovie) { + "$mainUrl/embed/$site/movie?id=$id" + + } else { + val suffix = "$id&s=${mappedData.season ?: 1}&e=${mappedData.episode ?: 1}" + "$mainUrl/embed/$site/tv?id=$suffix" + } + val document = app.get(embedUrl).document + val captchaKey = + document.select("script[src*=https://www.google.com/recaptcha/api.js?render=]") + .attr("src").substringAfter("render=") + + val servers = document.select(".dropdown-menu a[data-id]").map { it.attr("data-id") } + servers.apmap { serverID -> + val token = getCaptchaToken(embedUrl, captchaKey) + val ajax = app.get("$mainUrl/ajax/embed/play?id=$serverID&_token=$token", referer = embedUrl).text + val mappedservers = parseJson(ajax) + val iframeLink = mappedservers.link + if (iframeLink.contains("rabbitstream")) { + extractRabbitStream(iframeLink, subtitleCallback, callback) { it } + } else { + loadExtractor(iframeLink, embedUrl, callback) + } + } + return true + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lagradost/cloudstream3/utils/ExtractorApi.kt b/app/src/main/java/com/lagradost/cloudstream3/utils/ExtractorApi.kt index 39e885d0..70e248ce 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/utils/ExtractorApi.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/utils/ExtractorApi.kt @@ -112,7 +112,8 @@ val extractorApis: Array = arrayOf( StreamSB7(), StreamSB8(), StreamSB9(), - Streamhub(), + // Streamhub(), cause Streamhub2() works + Streamhub2(), FEmbed(), FeHD(),