From a214daa3b3b8656783f47c16834a0cf396590fad Mon Sep 17 00:00:00 2001 From: hexated Date: Sun, 2 Oct 2022 05:06:16 +0700 Subject: [PATCH] fixed Loklok search --- Loklok/build.gradle.kts | 2 +- Loklok/src/main/kotlin/com/hexated/Loklok.kt | 36 ++++++++++---------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/Loklok/build.gradle.kts b/Loklok/build.gradle.kts index 52e68584..8f4f1a63 100644 --- a/Loklok/build.gradle.kts +++ b/Loklok/build.gradle.kts @@ -1,5 +1,5 @@ // use an integer for version numbers -version = 5 +version = 6 cloudstream { diff --git a/Loklok/src/main/kotlin/com/hexated/Loklok.kt b/Loklok/src/main/kotlin/com/hexated/Loklok.kt index 30f9dc49..5d574001 100644 --- a/Loklok/src/main/kotlin/com/hexated/Loklok.kt +++ b/Loklok/src/main/kotlin/com/hexated/Loklok.kt @@ -70,29 +70,29 @@ class Loklok : MainAPI() { } override suspend fun search(query: String): List { -// val res = app.post( -// "$apiUrl/search/v1/searchWithKeyWord", data = mapOf( -// "searchKeyWord" to query, -// "size" to "50", -// "sort" to "", -// "searchType" to "" -// ), headers = headers -// ) - val buildId = app.get("${base64Decode("aHR0cHM6Ly9maWxtaG90LmxpdmUvc2VhcmNo")}?q=$query").text.substringAfterLast("\"buildId\":\"").substringBefore("\",") - val searchApi = "${base64Decode("aHR0cHM6Ly9maWxtaG90LmxpdmUvX25leHQvZGF0YQ==")}/$buildId" val res = app.get( - "$searchApi/search.json?q=$query", - headers = mapOf("x-nextjs-data" to "1") - ) - return res.parsedSafe()?.pageProps?.result?.mapNotNull { media -> + "https://loklok.com/search?keyword=$query", + ).document + + val script = res.select("script").find { it.data().contains("function(a,b,c,d,e") }?.data() + ?.substringAfter("searchResults:[")?.substringBefore("]}],fetch") + + return script?.split("areas")?.filter { it.contains("domainType") }?.map { item -> + val name = Regex("\",name:\"(.*?)\",").find(item)?.groupValues?.getOrNull(1) + val id = Regex("id:\"([0-9]{3,}?)\",").find(item)?.groupValues?.getOrNull(1) + val type = Regex("domainType:([ae]),").find(item)?.groupValues?.getOrNull(1)?.let { if(it == "a") 1 else 0 } + val image = Regex("coverVerticalUrl:\"(\\S+?)\",").find(item)?.groupValues?.getOrNull(1)?.replace("\\u002F", "/") + newMovieSearchResponse( - media.name ?: return@mapNotNull null, - UrlData(media.id?.toIntOrNull(), media.domainType).toJson(), + "$name", + UrlData(id, type).toJson(), TvType.Movie, ) { - this.posterUrl = media.coverVerticalUrl + this.posterUrl = image } - } ?: throw ErrorLoadingException("Invalid Json Reponse") + + } ?: throw ErrorLoadingException("No media found") + } override suspend fun load(url: String): LoadResponse? {