From f7aa1ce06dfa4d211ae2bdc214f1f8bd75b399f2 Mon Sep 17 00:00:00 2001 From: Jace <54625750+Jacekun@users.noreply.github.com> Date: Tue, 11 Jan 2022 20:36:54 +0800 Subject: [PATCH] Various providers fixes (#426) --- .../movieproviders/DramaSeeProvider.kt | 223 ++++++++-------- .../movieproviders/PinoyHDXyzProvider.kt | 179 +++++++------ .../movieproviders/PinoyMoviePediaProvider.kt | 251 ++++++++---------- 3 files changed, 309 insertions(+), 344 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/movieproviders/DramaSeeProvider.kt b/app/src/main/java/com/lagradost/cloudstream3/movieproviders/DramaSeeProvider.kt index ce4b6e66..f6bd2bef 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/movieproviders/DramaSeeProvider.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/movieproviders/DramaSeeProvider.kt @@ -1,11 +1,12 @@ package com.lagradost.cloudstream3.movieproviders import android.util.Log +import com.fasterxml.jackson.module.kotlin.readValue import com.lagradost.cloudstream3.* import com.lagradost.cloudstream3.extractors.* +import com.lagradost.cloudstream3.utils.AppUtils.toJson import com.lagradost.cloudstream3.utils.ExtractorLink import com.lagradost.cloudstream3.utils.loadExtractor -import org.jsoup.Jsoup class DramaSeeProvider : MainAPI() { override val mainUrl = "https://dramasee.net" @@ -18,36 +19,33 @@ class DramaSeeProvider : MainAPI() { override fun getMainPage(): HomePageResponse { val headers = mapOf("X-Requested-By" to "dramasee.net") - val html = app.get(mainUrl, headers = headers).text - val document = Jsoup.parse(html) + val document = app.get(mainUrl, headers = headers).document val mainbody = document.getElementsByTag("body") - return HomePageResponse( - mainbody?.select("section")?.map { row -> - val main = row?.select("main") - - val title = main?.select("div.title > div > h2")?.text() ?: "Main" - val inner = main?.select("li.series-item") ?: return@map null + return HomePageResponse(mainbody?.select("section")?.map { row -> + val main = row?.select("main") ?: return@map null + val title = main.select("div.title > div > h2")?.text() ?: "Main" + val inner = main.select("li.series-item") ?: return@map null HomePageList( title, inner.mapNotNull { - // Get inner div from article - val innerBody = it?.selectFirst("a") - // Fetch details - val link = fixUrlNull(innerBody?.attr("href")) ?: return@mapNotNull null - val image = fixUrlNull(innerBody?.select("img")?.attr("src")) ?: "" - val name = it?.selectFirst("a.series-name")?.text() ?: "" - //Log.i(this.name, "Result => (innerBody, image) ${innerBody} / ${image}") - MovieSearchResponse( - name, - link, - this.name, - TvType.TvSeries, - image, - year = null, - id = null, - ) + // Get inner div from article + val innerBody = it?.selectFirst("a") + // Fetch details + val link = fixUrlNull(innerBody?.attr("href")) ?: return@mapNotNull null + val image = fixUrlNull(innerBody?.select("img")?.attr("src")) ?: "" + val name = it?.selectFirst("a.series-name")?.text() ?: "" + //Log.i(this.name, "Result => (innerBody, image) ${innerBody} / ${image}") + MovieSearchResponse( + name, + link, + this.name, + TvType.TvSeries, + image, + year = null, + id = null, + ) }.distinctBy { c -> c.url }) }?.filterNotNull() ?: listOf() ) @@ -59,24 +57,26 @@ class DramaSeeProvider : MainAPI() { val document = html.getElementsByTag("body") .select("section > main > ul.series > li") ?: return listOf() - return document.map { - val innerA = it?.select("a.series-img") - val href = innerA?.attr("href") ?: return@map null - val link = fixUrlNull(href) ?: return@map null - val title = it?.select("a.series-name")?.text() ?: return@map null + return document.mapNotNull { + if (it == null) { + return@mapNotNull null + } + val innerA = it.select("a.series-img") ?: return@mapNotNull null + val link = fixUrlNull(innerA.attr("href")) ?: return@mapNotNull null + val title = it.select("a.series-name")?.text() ?: return@mapNotNull null val year = null - val imgsrc = innerA?.select("img")?.attr("src") ?: return@map null - val image = fixUrl(imgsrc) + val imgsrc = innerA.select("img")?.attr("src") ?: return@mapNotNull null + val image = fixUrlNull(imgsrc) MovieSearchResponse( - title, - link, - this.name, - TvType.Movie, - image, - year + name = title, + url = link, + apiName = this.name, + type = TvType.Movie, + posterUrl = image, + year = year ) - }.filterNotNull() + } } override fun load(url: String): LoadResponse { @@ -96,48 +96,41 @@ class DramaSeeProvider : MainAPI() { // Episodes Links val episodeList = ArrayList() - val eps = body?.select("ul.episodes > li.episode-item") - //Log.i(this.name, "Result => (eps) ${eps}") - if (!eps.isNullOrEmpty()) { - for (ep in eps) { - if (ep != null) { - val innerA = ep.select("a") - val count = innerA.select("span.episode")?.text()?.toIntOrNull() ?: 0 - val epLink = fixUrlNull(innerA.attr("href")) ?: continue - //Log.i(this.name, "Result => (epLink) ${epLink}") - if (epLink.isNotEmpty()) { - // Fetch video links - val epVidLinkEl = app.get(epLink, referer = mainUrl).document - val ajaxUrl = epVidLinkEl.select("div#js-player")?.attr("embed") - //Log.i(this.name, "Result => (ajaxUrl) ${ajaxUrl}") - if (!ajaxUrl.isNullOrEmpty()) { - val innerPage = Jsoup.parse(app.get(fixUrl(ajaxUrl), referer = epLink).text) - val listOfLinks = mutableListOf() - val serverAvail = innerPage?.select("div.player.active > main > div") - if (!serverAvail.isNullOrEmpty()) { - for (em in serverAvail) { - val href = em.attr("src") - if (!href.isNullOrEmpty()) { - listOfLinks.add(href) - } - } - } - //Log.i(this.name, "Result => (listOfLinks) ${listOfLinks}") - episodeList.add( - TvSeriesEpisode( - name = "Episode $count", - season = null, - episode = count, - data = listOfLinks.toString(), - posterUrl = poster, - date = null - ) - ) + body?.select("ul.episodes > li.episode-item")?.forEach { ep -> + val innerA = ep.select("a") ?: return@forEach + val count = innerA.select("span.episode")?.text()?.toIntOrNull() ?: 0 + val epLink = fixUrlNull(innerA.attr("href")) ?: return@forEach + //Log.i(this.name, "Result => (epLink) ${epLink}") + if (epLink.isNotEmpty()) { + // Fetch video links + val epVidLinkEl = app.get(epLink, referer = mainUrl).document + val ajaxUrl = epVidLinkEl.select("div#js-player")?.attr("embed") + //Log.i(this.name, "Result => (ajaxUrl) ${ajaxUrl}") + if (!ajaxUrl.isNullOrEmpty()) { + val innerPage = app.get(fixUrl(ajaxUrl), referer = epLink).document + val listOfLinks = mutableListOf() + innerPage.select("div.player.active > main > div")?.forEach { em -> + val href = em.attr("src") ?: "" + if (href.isNotEmpty()) { + listOfLinks.add(href) } } + + //Log.i(this.name, "Result => (listOfLinks) ${listOfLinks}") + episodeList.add( + TvSeriesEpisode( + name = null, + season = null, + episode = count, + data = listOfLinks.distinct().toJson(), + posterUrl = poster, + date = null + ) + ) } } } + //If there's only 1 episode, consider it a movie. if (episodeList.size == 1) { return MovieLoadResponse(title, url, this.name, TvType.Movie, episodeList[0].data, poster, year, descript, null, null) @@ -163,55 +156,49 @@ class DramaSeeProvider : MainAPI() { subtitleCallback: (SubtitleFile) -> Unit, callback: (ExtractorLink) -> Unit ): Boolean { - if (data == "about:blank") return false - if (data == "[]") return false if (data.isEmpty()) return false + if (data == "[]") return false + if (data == "about:blank") return false - val urls = data.trim('[').trim(']').split(',') - if (!urls.isNullOrEmpty()) { - for (item in urls) { - if (item.isNotEmpty()) { - var url = item.trim() - if (url.startsWith("//")) { - url = "https:$url" - } - //Log.i(this.name, "Result => (url) ${url}") - if (url.startsWith("https://asianembed.io")) { - // Fetch links - val doc = app.get(url).document - val links = doc.select("div#list-server-more > ul > li.linkserver") - if (!links.isNullOrEmpty()) { - links.forEach { - val datavid = it.attr("data-video") ?: "" - //Log.i(this.name, "Result => (datavid) ${datavid}") - if (datavid.isNotEmpty()) { - if (datavid.startsWith("https://fembed-hd.com")) { - val extractor = XStreamCdn() - extractor.domainUrl = "fembed-hd.com" - val src = extractor.getUrl(datavid, url) - src.forEach { link -> - callback.invoke(link) - } - } else { - loadExtractor(datavid, url, callback) + mapper.readValue>(data).forEach { item -> + if (item.isNotEmpty()) { + var url = item.trim() + if (url.startsWith("//")) { + url = "https:$url" + } + //Log.i(this.name, "Result => (url) ${url}") + if (url.startsWith("https://asianembed.io")) { + // Fetch links + val doc = app.get(url).document + val links = doc.select("div#list-server-more > ul > li.linkserver") + if (!links.isNullOrEmpty()) { + links.forEach { + val datavid = it.attr("data-video") ?: "" + //Log.i(this.name, "Result => (datavid) ${datavid}") + if (datavid.isNotEmpty()) { + if (datavid.startsWith("https://fembed-hd.com")) { + val extractor = XStreamCdn() + extractor.domainUrl = "fembed-hd.com" + extractor.getUrl(datavid, url).forEach { link -> + callback.invoke(link) } + } else { + loadExtractor(datavid, url, callback) } } } - } else if (url.startsWith("https://embedsito.com")) { - val extractor = XStreamCdn() - extractor.domainUrl = "embedsito.com" - val src = extractor.getUrl(url) - src.forEach { link -> - callback.invoke(link) - } - } else { - loadExtractor(url, url, callback) - } // end if - } + } + } else if (url.startsWith("https://embedsito.com")) { + val extractor = XStreamCdn() + extractor.domainUrl = "embedsito.com" + extractor.getUrl(url).forEach { link -> + callback.invoke(link) + } + } else { + loadExtractor(url, mainUrl, callback) + } // end if } - return true } - return false + return true } } \ No newline at end of file diff --git a/app/src/main/java/com/lagradost/cloudstream3/movieproviders/PinoyHDXyzProvider.kt b/app/src/main/java/com/lagradost/cloudstream3/movieproviders/PinoyHDXyzProvider.kt index f0e75180..07bd186c 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/movieproviders/PinoyHDXyzProvider.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/movieproviders/PinoyHDXyzProvider.kt @@ -1,25 +1,26 @@ package com.lagradost.cloudstream3.movieproviders import android.util.Log +import com.fasterxml.jackson.module.kotlin.readValue import com.lagradost.cloudstream3.* +import com.lagradost.cloudstream3.utils.AppUtils.toJson import com.lagradost.cloudstream3.utils.ExtractorLink import com.lagradost.cloudstream3.utils.loadExtractor -import org.jsoup.Jsoup +import java.lang.Exception class PinoyHDXyzProvider : MainAPI() { override val name = "Pinoy-HD" override val mainUrl = "https://www.pinoy-hd.xyz" override val lang = "tl" override val supportedTypes = setOf(TvType.Movie, TvType.TvSeries) - override val hasDownloadSupport = false + override val hasDownloadSupport = true override val hasMainPage = true override val hasQuickSearch = false override fun getMainPage(): HomePageResponse { val all = ArrayList() - val html = app.get(mainUrl, referer = mainUrl).text - val document = Jsoup.parse(html) + val document = app.get(mainUrl, referer = mainUrl).document val mainbody = document.getElementsByTag("body") mainbody?.select("div.section-cotent.col-md-12.bordert")?.forEach { row -> @@ -69,32 +70,28 @@ class PinoyHDXyzProvider : MainAPI() { override fun search(query: String): List { val url = "$mainUrl/search/?q=${query.replace(" ", "+")}" val document = app.get(url).document.select("div.portfolio-thumb") - if (!document.isNullOrEmpty()) { - return document.map { + return document?.mapNotNull { + if (it == null) { + return@mapNotNull null + } + val link = it.selectFirst("a")?.attr("href") ?: return@mapNotNull null + val title = it.text() ?: "" + val year = null + val image = null // site provides no image on search page - val link = it?.select("a")?.firstOrNull()?.attr("href") ?: "" - val title = it?.text() ?: "" - val year = null - val image = null // site provides no image on search page - - MovieSearchResponse( - title, - link, - this.name, - TvType.Movie, - image, - year - ) - }.filter { a -> a.url.isNotEmpty() } - .filter { b -> b.name.isNotEmpty() } - .distinctBy { c -> c.url } - } - return listOf() + MovieSearchResponse( + title, + link, + this.name, + TvType.Movie, + image, + year + ) + }?.distinctBy { c -> c.url } ?: listOf() } override fun load(url: String): LoadResponse { - val response = app.get(url).text - val doc = Jsoup.parse(response) + val doc = app.get(url).document val body = doc.getElementsByTag("body") val inner = body?.select("div.info") @@ -120,32 +117,44 @@ class PinoyHDXyzProvider : MainAPI() { var descript = body?.select("div.eText")?.text() if (!descript.isNullOrEmpty()) { - descript = descript.substring(0, descript.indexOf("_x_Polus1")) - .replace("_x_Polus1", "") + try { + descript = descript.substring(0, descript.indexOf("_x_Polus1")) + .replace("_x_Polus1", "") + } catch (e: java.lang.Exception) { } } // Video links val listOfLinks: MutableList = mutableListOf() - val linkMain = body?.select("div.tabcontent > iframe")?.attr("src") - if (!linkMain.isNullOrEmpty()) { - listOfLinks.add(linkMain) - } - var extraLinks = body?.select("div.tabcontent.hide")?.text() - if (!extraLinks.isNullOrEmpty()) { - extraLinks = extraLinks.substring(extraLinks.indexOf("_x_Polus1")) - extraLinks = extraLinks.trim().substring("_x_Polus1".length) - extraLinks = extraLinks.substring(0, extraLinks.indexOf("