From 4f4f35559fa8879a8e1ff192e91a8013c09ae128 Mon Sep 17 00:00:00 2001 From: LagradOst Date: Thu, 26 Aug 2021 00:16:20 +0200 Subject: [PATCH] AllMoviesForYouProvider (1/2) movies only atm --- .../com/lagradost/cloudstream3/MainAPI.kt | 2 + .../cloudstream3/extractors/Streamhub.kt | 40 ++++++++ .../movieproviders/AllMoviesForYouProvider.kt | 97 +++++++++++++++++++ .../cloudstream3/utils/ExtractorApi.kt | 11 +++ 4 files changed, 150 insertions(+) create mode 100644 app/src/main/java/com/lagradost/cloudstream3/extractors/Streamhub.kt create mode 100644 app/src/main/java/com/lagradost/cloudstream3/movieproviders/AllMoviesForYouProvider.kt diff --git a/app/src/main/java/com/lagradost/cloudstream3/MainAPI.kt b/app/src/main/java/com/lagradost/cloudstream3/MainAPI.kt index ce800f4c..c3387f7c 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/MainAPI.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/MainAPI.kt @@ -6,6 +6,7 @@ import com.fasterxml.jackson.databind.DeserializationFeature import com.fasterxml.jackson.databind.json.JsonMapper import com.fasterxml.jackson.module.kotlin.KotlinModule import com.lagradost.cloudstream3.animeproviders.* +import com.lagradost.cloudstream3.movieproviders.AllMoviesForYouProvider import com.lagradost.cloudstream3.movieproviders.HDMProvider import com.lagradost.cloudstream3.movieproviders.TrailersToProvider import com.lagradost.cloudstream3.movieproviders.VMoveeProvider @@ -41,6 +42,7 @@ object APIHolder { //LookMovieProvider(), // RECAPTCHA (Please allow up to 5 seconds...) VMoveeProvider(), WatchCartoonOnlineProvider(), + AllMoviesForYouProvider(), ) fun getApiFromName(apiName: String?): MainAPI { diff --git a/app/src/main/java/com/lagradost/cloudstream3/extractors/Streamhub.kt b/app/src/main/java/com/lagradost/cloudstream3/extractors/Streamhub.kt new file mode 100644 index 00000000..7d47278a --- /dev/null +++ b/app/src/main/java/com/lagradost/cloudstream3/extractors/Streamhub.kt @@ -0,0 +1,40 @@ +package com.lagradost.cloudstream3.extractors + +import com.lagradost.cloudstream3.utils.ExtractorApi +import com.lagradost.cloudstream3.utils.ExtractorLink +import com.lagradost.cloudstream3.utils.JsUnpacker +import com.lagradost.cloudstream3.utils.Qualities + +class Streamhub : ExtractorApi() { + override val mainUrl: String + get() = "https://streamhub.to" + override val name: String + get() = "Streamhub" + override val requiresReferer: Boolean + get() = false + + override fun getExtractorUrl(id: String): String { + return "$mainUrl/e/$id" + } + + override fun getUrl(url: String, referer: String?): List? { + val response = khttp.get(url) + Regex("eval((.|\\n)*?)").find(response.text)?.groupValues?.get(1)?.let { jsEval -> + JsUnpacker("eval$jsEval" ).unpack()?.let { unPacked -> + Regex("sources:\\[\\{src:\"(.*?)\"").find(unPacked)?.groupValues?.get(1)?.let { link -> + return listOf( + ExtractorLink( + this.name, + this.name, + link, + referer ?: "", + Qualities.Unknown.value, + link.endsWith(".m3u8") + ) + ) + } + } + } + return null + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lagradost/cloudstream3/movieproviders/AllMoviesForYouProvider.kt b/app/src/main/java/com/lagradost/cloudstream3/movieproviders/AllMoviesForYouProvider.kt new file mode 100644 index 00000000..80b3fdda --- /dev/null +++ b/app/src/main/java/com/lagradost/cloudstream3/movieproviders/AllMoviesForYouProvider.kt @@ -0,0 +1,97 @@ +package com.lagradost.cloudstream3.movieproviders + +import com.lagradost.cloudstream3.* +import com.lagradost.cloudstream3.utils.ExtractorLink +import com.lagradost.cloudstream3.utils.loadExtractor +import org.jsoup.Jsoup + +class AllMoviesForYouProvider : MainAPI() { + companion object { + fun getType(t: String): TvType { + return when { + t.contains("series") -> TvType.TvSeries + t.contains("movies") -> TvType.Movie + else -> TvType.Movie + } + } + } + + override val mainUrl: String + get() = "https://allmoviesforyou.co/" + override val name: String + get() = "AllMoviesForYou" + override val supportedTypes: Set + get() = setOf( + TvType.Movie, + // TvType.TvSeries + ) + + override fun search(query: String): List { + val url = "$mainUrl/?s=$query" + val response = khttp.get(url) + val document = Jsoup.parse(response.text) + + val items = document.select("ul.MovieList > li > article > a") + val returnValue = ArrayList() + for (item in items) { + val href = item.attr("href") + val title = item.selectFirst("> h2.Title").text() + val img = fixUrl(item.selectFirst("> div.Image > figure > img").attr("data-src")) + val type = getType(href) + if (type == TvType.Movie) { + returnValue.add(MovieSearchResponse(title, href, this.name, type, img, null)) + } else if (type == TvType.TvSeries) { + // returnValue.add(TvSeriesSearchResponse(title, href, this.name, type, img, null, null)) + } + } + return returnValue + } + + override fun load(url: String): LoadResponse { + val type = getType(url) + if(type == TvType.TvSeries) throw ErrorLoadingException("TvSeries not implemented yet") + val response = khttp.get(url) + val document = Jsoup.parse(response.text) + val title = document.selectFirst("h1.Title").text() + val descipt = document.selectFirst("div.Description > p").text() + val rating = + document.selectFirst("div.Vote > div.post-ratings > span")?.text()?.toFloatOrNull()?.times(10)?.toInt() + val year = document.selectFirst("span.Date").text() + val duration = document.selectFirst("span.Time").text() + val backgroundPoster = fixUrl(document.selectFirst("div.Image > figure > img").attr("src")) + + val data = Regex("iframe src=\"(.*?)\"").find(response.text)?.groupValues?.get(1) + ?: throw ErrorLoadingException("No Links Found") + + return MovieLoadResponse( + title, + url, + this.name, + type, + data, + backgroundPoster, + year.toIntOrNull(), + descipt, + null, + rating, + duration = duration + ) + } + + override fun loadLinks( + data: String, + isCasting: Boolean, + subtitleCallback: (SubtitleFile) -> Unit, + callback: (ExtractorLink) -> Unit + ): Boolean { + if (data.startsWith(mainUrl) && data != mainUrl) { + val response = khttp.get(data.replace("&","&")) + Regex(" + loadExtractor(url.trimStart(), data, callback) + } + return true + } + + return false + } +} \ 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 f93fe58f..8bb10e00 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/utils/ExtractorApi.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/utils/ExtractorApi.kt @@ -1,5 +1,6 @@ package com.lagradost.cloudstream3.utils +import com.lagradost.cloudstream3.SubtitleFile import com.lagradost.cloudstream3.extractors.* import com.lagradost.cloudstream3.mvvm.normalSafeApiCall @@ -52,6 +53,15 @@ fun getAndUnpack(string: String): String? { return JsUnpacker(packedText).unpack() } +fun loadExtractor(url: String, referer: String?, callback: (ExtractorLink) -> Unit) { + for (extractor in extractorApis) { + if (url.startsWith(extractor.mainUrl)) { + extractor.getSafeUrl(url, referer)?.forEach(callback) + return + } + } +} + val extractorApis: Array = arrayOf( //AllProvider(), Shiro(), @@ -61,6 +71,7 @@ val extractorApis: Array = arrayOf( MixDrop(), XStreamCdn(), StreamSB(), + Streamhub(), ) fun getExtractorApiFromName(name: String): ExtractorApi {