fixed Loklok search

This commit is contained in:
hexated 2022-10-02 05:06:16 +07:00
parent e02ad2a089
commit a214daa3b3
2 changed files with 19 additions and 19 deletions

View file

@ -1,5 +1,5 @@
// use an integer for version numbers // use an integer for version numbers
version = 5 version = 6
cloudstream { cloudstream {

View file

@ -70,29 +70,29 @@ class Loklok : MainAPI() {
} }
override suspend fun search(query: String): List<SearchResponse> { override suspend fun search(query: String): List<SearchResponse> {
// 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( val res = app.get(
"$searchApi/search.json?q=$query", "https://loklok.com/search?keyword=$query",
headers = mapOf("x-nextjs-data" to "1") ).document
)
return res.parsedSafe<Search>()?.pageProps?.result?.mapNotNull { media -> 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( newMovieSearchResponse(
media.name ?: return@mapNotNull null, "$name",
UrlData(media.id?.toIntOrNull(), media.domainType).toJson(), UrlData(id, type).toJson(),
TvType.Movie, 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? { override suspend fun load(url: String): LoadResponse? {