From 26ba1de2f28b7e0ac70e57933285414ad7973e87 Mon Sep 17 00:00:00 2001 From: Jace <54625750+Jacekun@users.noreply.github.com> Date: Sun, 30 Jan 2022 01:02:52 +0800 Subject: [PATCH] Fix PinoyHDxyz provider issue on some tv series not properly recognized. (#520) * pinoyhd provider code cleanup * Fix PinoyHDxyz provider issue on some tv series not properly recognized. * removed MainAPI prefix on fetchUrls method --- .../com/lagradost/cloudstream3/MainAPI.kt | 8 ++ .../movieproviders/PinoyHDXyzProvider.kt | 132 ++++++++---------- 2 files changed, 66 insertions(+), 74 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/MainAPI.kt b/app/src/main/java/com/lagradost/cloudstream3/MainAPI.kt index 488f4e80..ede6ed25 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/MainAPI.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/MainAPI.kt @@ -657,3 +657,11 @@ fun MainAPI.newTvSeriesLoadResponse( builder.initializer() return builder } + +fun fetchUrls(text: String?): List { + if (text.isNullOrEmpty()) { + return listOf() + } + val linkRegex = Regex("""(https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&\/\/=]*))""") + return linkRegex.findAll(text).map { it.value.trim().removeSurrounding("\"") }.toList() +} 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 7aa931b0..e51b10c4 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/movieproviders/PinoyHDXyzProvider.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/movieproviders/PinoyHDXyzProvider.kt @@ -1,5 +1,6 @@ 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 @@ -94,24 +95,20 @@ class PinoyHDXyzProvider : MainAPI() { val inner = body?.select("div.info") // Video details - val tvtype = when (url.contains("/pinoy_tv_series/", ignoreCase = true)) { - true -> TvType.TvSeries - false -> TvType.Movie - } val imgLinkCode = inner?.select("div.portfolio-tumb.ph-link > img")?.attr("src") val poster = if (!imgLinkCode.isNullOrEmpty()) { "${mainUrl}${imgLinkCode}" } else { null } //Log.i(this.name, "Result => (imgLinkCode) ${imgLinkCode}") val title = inner?.select("td.trFon2.entt")?.firstOrNull()?.text() ?: "" var yearRes = inner?.select("td.trFon2")?.toString() - if (!yearRes.isNullOrEmpty()) { + val year = if (!yearRes.isNullOrEmpty()) { if (yearRes.contains("var year =")) { - yearRes = yearRes.substring(yearRes.indexOf("var year =")) - yearRes = yearRes.substring(0, yearRes.indexOf(';')).replace("var year =", "") - .trim().trim('\'') + yearRes = yearRes.substring(yearRes.indexOf("var year =") + "var year =".length) + //Log.i(this.name, "Result => (yearRes) $yearRes") + yearRes = yearRes.substring(0, yearRes.indexOf(';')) + .trim().removeSurrounding("'") } - } - //Log.i(this.name, "Result => (yearRes) ${yearRes}") - val year = yearRes?.toIntOrNull() + yearRes.toIntOrNull() + } else { null } var descript = body?.select("div.eText")?.text() if (!descript.isNullOrEmpty()) { @@ -121,7 +118,49 @@ class PinoyHDXyzProvider : MainAPI() { } catch (e: java.lang.Exception) { } } - // Video links + // Try looking for episodes, for series + val episodeList = ArrayList() + val bodyText = body?.select("div.section-cotent1.col-md-12")?.select("section") + ?.select("script")?.toString() ?: "" + //Log.i(this.name, "Result => (bodyText) ${bodyText}") + + "(?<=ses=\\(')(.*)(?='\\).split)".toRegex().find(bodyText)?.groupValues?.get(0).let { + if (!it.isNullOrEmpty()) { + var count = 0 + it.split(", ").forEach { ep -> + count++ + val listEpStream = listOf(ep.trim()).toJson() + //Log.i(this.name, "Result => (ep $count) $listEpStream") + episodeList.add( + TvSeriesEpisode( + name = null, + season = null, + episode = count, + data = listEpStream, + posterUrl = null, + date = null + ) + ) + } + } + } + if (episodeList.size > 0) { + return TvSeriesLoadResponse( + title, + url, + this.name, + TvType.TvSeries, + episodeList, + poster, + year, + descript, + null, + null, + null + ) + } + + // Video links for Movie val listOfLinks: MutableList = mutableListOf() body?.select("div.tabcontent > iframe")?.forEach { val linkMain = it?.attr("src") @@ -138,69 +177,12 @@ class PinoyHDXyzProvider : MainAPI() { } } - var extraLinks = body?.select("div.tabcontent.hide")?.text() - if (!extraLinks.isNullOrEmpty()) { - try { - extraLinks = extraLinks.substring(extraLinks.indexOf("_x_Polus1")) - extraLinks = extraLinks.trim().substring("_x_Polus1".length) - extraLinks = extraLinks.substring(0, extraLinks.indexOf("