From 8c287e2cd13aa42a2dea9522b1286d0379949331 Mon Sep 17 00:00:00 2001 From: hexated Date: Sat, 19 Aug 2023 09:38:32 +0700 Subject: [PATCH] sora: fix filmxy --- .../main/kotlin/com/hexated/SoraExtractor.kt | 2 +- .../src/main/kotlin/com/hexated/SoraUtils.kt | 42 +++++++++---------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/SoraStream/src/main/kotlin/com/hexated/SoraExtractor.kt b/SoraStream/src/main/kotlin/com/hexated/SoraExtractor.kt index 4f91fc46..f2cc5694 100644 --- a/SoraStream/src/main/kotlin/com/hexated/SoraExtractor.kt +++ b/SoraStream/src/main/kotlin/com/hexated/SoraExtractor.kt @@ -562,7 +562,7 @@ object SoraExtractor : SoraStream() { } else { "${filmxyAPI}/tv/$imdbId" } - val filmxyCookies = getFilmxyCookies(imdbId, season) + val filmxyCookies = getFilmxyCookies(url) val doc = session.get(url, cookies = filmxyCookies).document val script = doc.selectFirst("script:containsData(var isSingle)")?.data() ?: return diff --git a/SoraStream/src/main/kotlin/com/hexated/SoraUtils.kt b/SoraStream/src/main/kotlin/com/hexated/SoraUtils.kt index c918810b..f256bf87 100644 --- a/SoraStream/src/main/kotlin/com/hexated/SoraUtils.kt +++ b/SoraStream/src/main/kotlin/com/hexated/SoraUtils.kt @@ -905,31 +905,29 @@ suspend fun getTvMoviesServer(url: String, season: Int?, episode: Int?): Pair { +var filmxyCookies: Map? = null +suspend fun getFilmxyCookies(url: String) = filmxyCookies ?: fetchFilmxyCookies(url).also { filmxyCookies = it } +suspend fun fetchFilmxyCookies(url: String): Map { - val url = if (season == null) { - "${filmxyAPI}/movie/$imdbId" - } else { - "${filmxyAPI}/tv/$imdbId" - } - val cookieUrl = "${filmxyAPI}/wp-admin/admin-ajax.php" - - val res = session.get( + val defaultCookies = mutableMapOf("G_ENABLED_IDPS" to "google", "true_checker" to "1", "XID" to "1") + session.get( url, headers = mapOf( "Accept" to "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8" ), + cookies = defaultCookies, ) - - if (!res.isSuccessful) return emptyMap() - - val userNonce = - res.document.select("script").find { it.data().contains("var userNonce") }?.data()?.let { - Regex("var\\suserNonce.*?\"(\\S+?)\";").find(it)?.groupValues?.get(1) - } - val phpsessid = session.baseClient.cookieJar.loadForRequest(url.toHttpUrl()) .first { it.name == "PHPSESSID" }.value + defaultCookies["PHPSESSID"] = phpsessid + + val userNonce = + app.get("$filmxyAPI/login/?redirect_to=$filmxyAPI/", cookies = defaultCookies).document.select("script") + .find { it.data().contains("var userNonce") }?.data()?.let { + Regex("var\\suserNonce.*?\"(\\S+?)\";").find(it)?.groupValues?.get(1) + } + + val cookieUrl = "${filmxyAPI}/wp-admin/admin-ajax.php" session.post( cookieUrl, @@ -938,12 +936,14 @@ suspend fun getFilmxyCookies(imdbId: String? = null, season: Int? = null): Map