From 3e020355f23d9586de838d07310cb5c84ffc9784 Mon Sep 17 00:00:00 2001 From: antonydp <38143733+antonydp@users.noreply.github.com> Date: Sun, 31 Jul 2022 20:15:14 +0200 Subject: [PATCH] New provider ilgeniodellostreaming(IT) (#1375) * ilgeniodellostreaming --- .../com/lagradost/cloudstream3/MainAPI.kt | 1 + .../IlGenioDelloStreamingProvider.kt | 181 ++++++++++++++++++ .../cloudstream3/utils/UnshortenUrl.kt | 4 +- 3 files changed, 184 insertions(+), 2 deletions(-) create mode 100644 app/src/main/java/com/lagradost/cloudstream3/movieproviders/IlGenioDelloStreamingProvider.kt diff --git a/app/src/main/java/com/lagradost/cloudstream3/MainAPI.kt b/app/src/main/java/com/lagradost/cloudstream3/MainAPI.kt index 8e3d8975..368c9986 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/MainAPI.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/MainAPI.kt @@ -94,6 +94,7 @@ object APIHolder { StreamingcommunityProvider(), TantifilmProvider(), CineblogProvider(), + IlGenioDelloStreamingProvider(), AltadefinizioneProvider(), FilmpertuttiProvider(), HDMovie5(), diff --git a/app/src/main/java/com/lagradost/cloudstream3/movieproviders/IlGenioDelloStreamingProvider.kt b/app/src/main/java/com/lagradost/cloudstream3/movieproviders/IlGenioDelloStreamingProvider.kt new file mode 100644 index 00000000..a123c4a2 --- /dev/null +++ b/app/src/main/java/com/lagradost/cloudstream3/movieproviders/IlGenioDelloStreamingProvider.kt @@ -0,0 +1,181 @@ +package com.lagradost.cloudstream3.movieproviders + +import com.lagradost.cloudstream3.* +import com.lagradost.cloudstream3.mvvm.logError +import com.lagradost.cloudstream3.LoadResponse.Companion.addRating +import com.lagradost.cloudstream3.utils.AppUtils.toJson +import com.lagradost.cloudstream3.utils.AppUtils.tryParseJson +import com.lagradost.cloudstream3.utils.ExtractorLink +import com.lagradost.cloudstream3.utils.ShortLink +import com.lagradost.cloudstream3.utils.loadExtractor +import org.jsoup.Jsoup + + +class IlGenioDelloStreamingProvider : MainAPI() { + override var lang = "it" + override var mainUrl = "https://ilgeniodellostreaming.quest" + override var name = "IlGenioDelloStreaming" + override val hasMainPage = true + override val hasChromecastSupport = true + override val supportedTypes = setOf( + TvType.Movie, + TvType.TvSeries, + ) + override val mainPage = mainPageOf( + Pair("$mainUrl/category/film/page/", "Film Popolari"), + Pair("$mainUrl/category/serie-tv/page/", "Serie Tv Popolari"), + Pair("$mainUrl/the-most-voted/page/", "I piĆ¹ votati"), + Pair("$mainUrl/prime-visioni/page/", "Ultime uscite"), + ) + + override suspend fun getMainPage( + page: Int, + request: MainPageRequest + ): HomePageResponse { + val url = request.data + page + val soup = app.get(url).document + val home = soup.select("div.items > article.item").map { + val title = it.selectFirst("div.data > h3 > a")!!.text().substringBeforeLast("(").substringBeforeLast("[") + val link = it.selectFirst("div.poster > a")!!.attr("href") + val quality = getQualityFromString(it.selectFirst("span.quality")?.text()) + TvSeriesSearchResponse( + title, + link, + this.name, + TvType.Movie, + it.selectFirst("img")!!.attr("data-src-img"), + null, + null, + quality = quality + ) + } + return newHomePageResponse(request.name, home) + } + + override suspend fun search(query: String): List { + val queryformatted = query.replace(" ", "+") + val url = "$mainUrl?s=$queryformatted" + val doc = app.get(url,referer= mainUrl ).document + return doc.select("div.result-item").map { + val href = it.selectFirst("div.image > div > a")!!.attr("href") + val poster = it.selectFirst("div.image > div > a > img")!!.attr("data-src-img") + val name = it.selectFirst("div.details > div.title > a")!!.text().substringBeforeLast("(").substringBeforeLast("[") + MovieSearchResponse( + name, + href, + this.name, + TvType.Movie, + poster + ) + + } + } + + override suspend fun load(url: String): LoadResponse { + val page = app.get(url) + val document = page.document + val type = if (document.selectFirst("div.sgeneros")?.text() == "Serie TV"){TvType.TvSeries} else{TvType.Movie} + val title = document.selectFirst("div.data > h1")!!.text().substringBefore("(").substringBefore("[") + val description = document.selectFirst("div#info")?.selectFirst("p")?.html() + val rating = document.select("span.valor").last()?.text()?.split(" ")?.get(0) + var year = document.selectFirst(" div.data > div.extra > span.date")!!.text().substringAfter(",") + .filter { it.isDigit() } + if (year.length > 4) { + year = year.dropLast(4) + } + + val poster = document.selectFirst("div.poster > img")!!.attr("data-src-img") + + val recomm = document.select("article.w_item_b").map { + val href = it.selectFirst("a")!!.attr("href") + val posterUrl = it.selectFirst("img")!!.attr("data-src-img") + val name = it.selectFirst("div.data > h3")!!.text().substringBeforeLast("(").substringBeforeLast("[") + MovieSearchResponse( + name, + href, + this.name, + TvType.Movie, + posterUrl + ) + + } + + + if (type == TvType.TvSeries) { + + val episodeList = ArrayList() + val seasons = document.selectFirst("div#info")?.select("p")?.map {it.children() } + ?.filter { it.size > 1 && it.first()!!.hasAttr("href") } + ?.map{(it.toString().split("
")) + .map{Jsoup.parse(it).select("a") + ?.map { it?.attr("href") }}} + seasons?.mapIndexed { season, element -> + element.mapIndexed { index, list -> + val urls = list?.toJson()?:url + episodeList.add( + Episode( + data = urls, + episode = index + 1, + season = season + 1 + ) + ) + } + } + val seasonnames = document.selectFirst("div#info")?.select("p")?.map {it.children() } + ?.filter { it.size<3 && it.isNotEmpty()}?.map{it.text()} + + return newTvSeriesLoadResponse( + title, + url, + type, + episodeList + ){ + addRating(rating) + this.plot = description + this.year = year.toIntOrNull() + this.posterUrl = poster + this.recommendations = recomm + this.seasonNames = seasonnames!!.mapIndexed { index, s -> SeasonData(index, s) } + + } + + + } else { + val actors: List = + document.select("div.cast_wraper > ul > li").map { actorData -> + val actorName = actorData.children()[1].text() + val actorImage : String? = actorData.selectFirst("img")?.attr("data-src") + val roleActor = actorData.children()[2].text() + ActorData(actor = Actor(actorName, image = actorImage), roleString = roleActor ) + } + return newMovieLoadResponse( + title, + url, + type, + (document.select("div.embed-player") + document.select("a.link_a")).map { (it.attr("href") + it.attr("data-id")).trim() }.distinct().toJson(), + ) { + posterUrl = fixUrlNull(poster) + this.year = year.toIntOrNull() + this.plot = description + addRating(rating) + this.recommendations = recomm + this.duration = null + this.actors = actors + } + } + } + + override suspend fun loadLinks( + data: String, + isCasting: Boolean, + subtitleCallback: (SubtitleFile) -> Unit, + callback: (ExtractorLink) -> Unit + ): Boolean { + val links = tryParseJson>(data) + links?.map { link -> + val url = ShortLink.unshorten(link).replace("/v/", "/e/").replace("/f/", "/e/") + loadExtractor(url, data, subtitleCallback, callback) + } + return true + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lagradost/cloudstream3/utils/UnshortenUrl.kt b/app/src/main/java/com/lagradost/cloudstream3/utils/UnshortenUrl.kt index f8902670..a2e50762 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/utils/UnshortenUrl.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/utils/UnshortenUrl.kt @@ -55,7 +55,7 @@ object ShortLink { while (true) { val oldurl = currentUrl val domain = - URI(currentUrl).host ?: throw IllegalArgumentException("No domain found in URI!") + URI(currentUrl.trim()).host ?: throw IllegalArgumentException("No domain found in URI!") currentUrl = shortList.firstOrNull { it.regex.find(domain) != null || type == it.type }?.function?.let { it(currentUrl) } ?: break @@ -63,7 +63,7 @@ object ShortLink { break } } - return currentUrl + return currentUrl.trim() } suspend fun unshortenAdfly(uri: String): String {