From 4688a80be81b65e0fa61747cb230e89a88c72c05 Mon Sep 17 00:00:00 2001 From: hexated Date: Sun, 9 Oct 2022 22:12:43 +0700 Subject: [PATCH] fixed Hdfilmcehennemi sub & fixed Xcinetop home --- Hdfilmcehennemi/build.gradle.kts | 2 +- .../kotlin/com/hexated/Hdfilmcehennemi.kt | 80 ++++++++++++++----- Xcinetop/build.gradle.kts | 2 +- .../src/main/kotlin/com/hexated/Xcinetop.kt | 8 +- 4 files changed, 68 insertions(+), 24 deletions(-) diff --git a/Hdfilmcehennemi/build.gradle.kts b/Hdfilmcehennemi/build.gradle.kts index 341e2252..33ec5913 100644 --- a/Hdfilmcehennemi/build.gradle.kts +++ b/Hdfilmcehennemi/build.gradle.kts @@ -1,5 +1,5 @@ // use an integer for version numbers -version = 3 +version = 4 cloudstream { diff --git a/Hdfilmcehennemi/src/main/kotlin/com/hexated/Hdfilmcehennemi.kt b/Hdfilmcehennemi/src/main/kotlin/com/hexated/Hdfilmcehennemi.kt index 482472cb..1d946657 100644 --- a/Hdfilmcehennemi/src/main/kotlin/com/hexated/Hdfilmcehennemi.kt +++ b/Hdfilmcehennemi/src/main/kotlin/com/hexated/Hdfilmcehennemi.kt @@ -6,6 +6,7 @@ import com.lagradost.cloudstream3.LoadResponse.Companion.addActors import com.lagradost.cloudstream3.LoadResponse.Companion.addTrailer import com.lagradost.cloudstream3.mvvm.safeApiCall import com.lagradost.cloudstream3.utils.* +import com.lagradost.cloudstream3.utils.AppUtils.tryParseJson import org.jsoup.nodes.Element class Hdfilmcehennemi : MainAPI() { @@ -20,6 +21,10 @@ class Hdfilmcehennemi : MainAPI() { TvType.TvSeries, ) + companion object { + private const val vidmolyServer = "https://vidmoly.to" + } + override val mainPage = mainPageOf( "$mainUrl/category/tavsiye-filmler-izle1/page/" to "Tavsiye Filmler Kategorisi", "$mainUrl/yabancidiziizle/page/" to "Son Eklenen Yabancı Diziler", @@ -152,36 +157,65 @@ class Hdfilmcehennemi : MainAPI() { } } + private fun fixSubUrl(url: String): String { + if (url.startsWith("http") || + // Do not fix JSON objects when passed as urls. + url.startsWith("{\"") + ) { + return url + } + if (url.isEmpty()) { + return "" + } + + val startsWithNoHttp = url.startsWith("//") + if (startsWithNoHttp) { + return "https:$url" + } else { + if (url.startsWith('/')) { + return vidmolyServer + url + } + return "$vidmolyServer/$url" + } + } + + private fun String.addMarks(str: String): String { + return this.replace(Regex("\"?$str\"?"), "\"$str\"") + } + private suspend fun invokeLocalSource( source: String, url: String, subtitleCallback: (SubtitleFile) -> Unit, callback: (ExtractorLink) -> Unit ) { - val res = app.get(url, referer = "$mainUrl/") - val m3uLink = res.document.select("script") - .find { - it.data().contains("var sources = [];") || it.data() - .contains("playerInstance =") - }?.data() - ?.substringAfter("[{file:\"")?.substringBefore("\"}]") ?: return + val script = app.get( + url, + referer = "${mainUrl}/" + ).document.select("script") + .find { it.data().contains("sources:") }?.data() + val videoData = script?.substringAfter("sources: [") + ?.substringBefore("],")?.addMarks("file") + val subData = script?.substringAfter("tracks: [")?.substringBefore("]")?.addMarks("file") + ?.addMarks("label")?.addMarks("kind") - M3u8Helper.generateM3u8( - source, - m3uLink, - if (url.startsWith(mainUrl)) "$mainUrl/" else "https://vidmoly.to/" - ).forEach(callback) + tryParseJson(videoData)?.file?.let { m3uLink -> + M3u8Helper.generateM3u8( + source, + m3uLink, + if (url.startsWith(mainUrl)) "$mainUrl/" else "$vidmolyServer/" + ).forEach(callback) + } - Regex("\"(/srt\\S*?)\",\\slabel:\\s\"(\\S*?)\"").findAll(res.text) - .map { it.groupValues[1] to it.groupValues[2] }.toList().map { (url, lang) -> + tryParseJson>("[${subData}]") + ?.filter { it.kind == "captions" }?.map { subtitleCallback.invoke( SubtitleFile( - lang, - fixUrl(url) + it.label.toString(), + fixSubUrl(it.file.toString()) ) ) } - } override suspend fun loadLinks( @@ -196,13 +230,23 @@ class Hdfilmcehennemi : MainAPI() { safeApiCall { app.get(url).document.select("div.card-video > iframe").attr("data-src") .let { link -> - invokeLocalSource(source, link,subtitleCallback, callback) + invokeLocalSource(source, link, subtitleCallback, callback) } } } return true } + private data class Source( + @JsonProperty("file") val file: String? = null, + ) + + private data class SubSource( + @JsonProperty("file") val file: String? = null, + @JsonProperty("label") val label: String? = null, + @JsonProperty("kind") val kind: String? = null, + ) + data class Result( @JsonProperty("result") val result: ArrayList? = arrayListOf(), ) diff --git a/Xcinetop/build.gradle.kts b/Xcinetop/build.gradle.kts index 0f92ff0d..5846e514 100644 --- a/Xcinetop/build.gradle.kts +++ b/Xcinetop/build.gradle.kts @@ -1,5 +1,5 @@ // use an integer for version numbers -version = 1 +version = 2 cloudstream { diff --git a/Xcinetop/src/main/kotlin/com/hexated/Xcinetop.kt b/Xcinetop/src/main/kotlin/com/hexated/Xcinetop.kt index d5da4d58..ddce60ef 100644 --- a/Xcinetop/src/main/kotlin/com/hexated/Xcinetop.kt +++ b/Xcinetop/src/main/kotlin/com/hexated/Xcinetop.kt @@ -30,7 +30,7 @@ class Xcinetop : MainAPI() { ) override suspend fun getMainPage(page: Int, request: MainPageRequest): HomePageResponse { - val document = app.get(request.data + page).document + val document = app.get("${request.data}$page/").document val home = document.select("div#dle-content div.movie-item").mapNotNull { it.toSearchResult() } @@ -48,7 +48,7 @@ class Xcinetop : MainAPI() { return newAnimeSearchResponse(title, href, TvType.TvSeries) { addQuality(quantity) addDub(episode) - addPoster(posterUrl, headers = mapOf("Referer" to "$mainUrl/")) + this.posterUrl = posterUrl } } @@ -94,7 +94,7 @@ class Xcinetop : MainAPI() { fixUrl(it.attr("data-link")) } return newMovieLoadResponse(title, url, TvType.Movie, Links(link).toJson()) { - addPoster(poster, headers = mapOf("Referer" to "$mainUrl/")) + this.posterUrl = poster this.year = year plot = description this.tags = tags @@ -115,7 +115,7 @@ class Xcinetop : MainAPI() { ) } return newTvSeriesLoadResponse(title, url, TvType.TvSeries, episodes = episodes) { - addPoster(poster, headers = mapOf("Referer" to "$mainUrl/")) + this.posterUrl = poster this.year = year plot = description this.tags = tags