From 88bbcfee27dc085022d40354628af578403f92c8 Mon Sep 17 00:00:00 2001 From: Swissky <12152583+swisskyrepo@users.noreply.github.com> Date: Mon, 1 Jul 2024 11:48:41 +0200 Subject: [PATCH] Voe first request --- .../main/kotlin/com/example/SflixPlugin.kt | 4 +- .../main/kotlin/com/example/SflixProvider.kt | 37 +-------- .../main/kotlin/com/example/VoeExtractor.kt | 78 +++++++++++++++++++ 3 files changed, 82 insertions(+), 37 deletions(-) create mode 100644 Sflix/src/main/kotlin/com/example/VoeExtractor.kt diff --git a/Sflix/src/main/kotlin/com/example/SflixPlugin.kt b/Sflix/src/main/kotlin/com/example/SflixPlugin.kt index c79cb50..91fdccd 100644 --- a/Sflix/src/main/kotlin/com/example/SflixPlugin.kt +++ b/Sflix/src/main/kotlin/com/example/SflixPlugin.kt @@ -10,7 +10,7 @@ import android.util.Log import androidx.appcompat.app.AppCompatActivity @CloudstreamPlugin -class TestPlugin: Plugin() { +class SflixPlugin: Plugin() { var activity: AppCompatActivity? = null override fun load(context: Context) { @@ -20,7 +20,9 @@ class TestPlugin: Plugin() { registerExtractorAPI(MixDropCo()) // Force this extractor to be first in the list + // Use this when you rewrite/upgrade an existing extractor addExtractor(Upstream()) + addExtractor(Voe2()) registerMainAPI(ExampleProvider(this)) diff --git a/Sflix/src/main/kotlin/com/example/SflixProvider.kt b/Sflix/src/main/kotlin/com/example/SflixProvider.kt index e4b3b59..d381b84 100644 --- a/Sflix/src/main/kotlin/com/example/SflixProvider.kt +++ b/Sflix/src/main/kotlin/com/example/SflixProvider.kt @@ -17,7 +17,7 @@ import com.fasterxml.jackson.annotation.JsonProperty import org.jsoup.Jsoup import org.jsoup.nodes.Element -class ExampleProvider(val plugin: TestPlugin) : MainAPI() { +class SflixProvider(val plugin: TestPlugin) : MainAPI() { // all providers must be an instance of MainAPI override var mainUrl = "https://sflix.to" override var name = "Sflix" @@ -54,39 +54,6 @@ class ExampleProvider(val plugin: TestPlugin) : MainAPI() { } - /*override val mainPage = mainPageOf( - "tv-show" to "TV Show", - "movie" to "Movie", - "top-imdb" to "Top-IMDB", - ) - - override suspend fun getMainPage(page: Int, request: MainPageRequest): HomePageResponse { - // page: An integer > 0, starts on 1 and counts up, Depends on how much the user has scrolled. - val url = "$mainUrl/${request.data}?page=$page" - var list = mutableListOf() - val res = app.get(url).document - - res.select(".flw-item").mapNotNull { article -> - val name = article.selectFirst("h2 > a")?.text() ?: "" - val poster = article.selectFirst("img")?.attr("data-src") - val url = article.selectFirst("a.btn")?.attr("href") ?: "" - - list.add(newAnimeSearchResponse(name, url){ - this.posterUrl = poster - }) - } - - return newHomePageResponse( - list = HomePageList( - name = request.name, - list = list, - isHorizontalImages = true - ), - hasNext = true - ) - }*/ - - override suspend fun getMainPage(page: Int, request: MainPageRequest): HomePageResponse { val html = app.get("$mainUrl/home").text val document = Jsoup.parse(html) @@ -95,8 +62,6 @@ class ExampleProvider(val plugin: TestPlugin) : MainAPI() { val map = mapOf( "Trending Movies" to "div#trending-movies", "Trending TV Shows" to "div#trending-tv", - // "Latest Movies" to "div#trending-tv", // film_list-wrap - // "Latest TV Shows" to "div#trending-tv", // film_list-wrap ) map.forEach { all.add(HomePageList( diff --git a/Sflix/src/main/kotlin/com/example/VoeExtractor.kt b/Sflix/src/main/kotlin/com/example/VoeExtractor.kt new file mode 100644 index 0000000..f1402ee --- /dev/null +++ b/Sflix/src/main/kotlin/com/example/VoeExtractor.kt @@ -0,0 +1,78 @@ +package com.lagradost.cloudstream3.extractors + +import android.util.Base64 +import com.fasterxml.jackson.annotation.JsonProperty +import com.lagradost.cloudstream3.SubtitleFile +import com.lagradost.cloudstream3.app +import com.lagradost.cloudstream3.utils.AppUtils +import com.lagradost.cloudstream3.utils.ExtractorApi +import com.lagradost.cloudstream3.utils.ExtractorLink +import com.lagradost.cloudstream3.utils.M3u8Helper + +open class Voe2 : ExtractorApi() { + override val name = "Voe" + override val mainUrl = "https://voe.sx" + override val requiresReferer = true + + private val linkRegex = "(http|https)://([\\w_-]+(?:\\.[\\w_-]+)+)([\\w.,@?^=%&:/~+#-]*[\\w@?^=%&/~+#-])".toRegex() + private val base64Regex = Regex("'.*'") + + override suspend fun getUrl( + url: String, + referer: String?, + subtitleCallback: (SubtitleFile) -> Unit, + callback: (ExtractorLink) -> Unit + ) { + Log.d("mnemo", "voe.sx loaded") + + // Extract the first redirect URL, like https://roberteachfinal.com/e/xxxxxxx + val res = app.get(url, referer = referer).document + val redirRegex = """window.location.href = '(.*)'""".toRegex() + val redirResult = redirRegex.find(doc) + if (redirResult != null){ + Log.d("mnemo", redirResult) + } + else{ + Log.d("mnemo", "voe.sx redir not found") + } + + + + + + + + val res = app.get(url, referer = referer).document + val script = res.select("script").find { it.data().contains("sources =") }?.data() + val link = Regex("[\"']hls[\"']:\\s*[\"'](.*)[\"']").find(script ?: return)?.groupValues?.get(1) + + val videoLinks = mutableListOf() + + if (!link.isNullOrBlank()) { + videoLinks.add( + when { + linkRegex.matches(link) -> link + else -> String(Base64.decode(link, Base64.DEFAULT)) + } + ) + } else { + val link2 = base64Regex.find(script)?.value ?: return + val decoded = Base64.decode(link2, Base64.DEFAULT).toString() + val videoLinkDTO = AppUtils.parseJson(decoded) + videoLinkDTO.let { videoLinks.add(it.toString()) } + } + + videoLinks.forEach { videoLink -> + M3u8Helper.generateM3u8( + name, + videoLink, + "$mainUrl/", + headers = mapOf("Origin" to "$mainUrl/") + ).forEach(callback) + } + } + + data class WcoSources( + @JsonProperty("VideoLinkDTO") val VideoLinkDTO: String, + ) +} \ No newline at end of file