loklok: fix search

This commit is contained in:
hexated 2023-03-18 01:18:50 +07:00
parent 39df95bf96
commit fa8fc96ab6
3 changed files with 34 additions and 30 deletions

View file

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

View file

@ -96,34 +96,36 @@ class Loklok : MainAPI() {
}
}
override suspend fun search(query: String): List<SearchResponse> {
val res = app.get(
"$searchApi/search?keyword=$query",
).document
override suspend fun search(query: String): List<SearchResponse>? = quickSearch(query)
val script = res.select("script").find { it.data().contains("function(a,b,c,d,e") }?.data()
?.substringAfter("searchResults:[")?.substringBefore("]}],fetch")
return res.select("div.search-list div.search-video-card").mapIndexed { num, block ->
val name = block.selectFirst("h2.title")?.text()
val data = block.selectFirst("a")?.attr("href")?.split("/")
val id = data?.last()
val type = data?.get(2)?.toInt()
val image = Regex("coverVerticalUrl:\"(.*?)\",").findAll(script.toString())
.map { it.groupValues[1] }.toList().getOrNull(num)?.replace("\\u002F", "/")
newMovieSearchResponse(
"$name",
UrlData(id, type).toJson(),
TvType.Movie,
) {
this.posterUrl = image
}
}
}
// override suspend fun search(query: String): List<SearchResponse> {
// val res = app.get(
// "$searchApi/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 res.select("div.search-list div.search-video-card").mapIndexed { num, block ->
// val name = block.selectFirst("h2.title")?.text()
// val data = block.selectFirst("a")?.attr("href")?.split("/")
// val id = data?.last()
// val type = data?.get(2)?.toInt()
// val image = Regex("coverVerticalUrl:\"(.*?)\",").findAll(script.toString())
// .map { it.groupValues[1] }.toList().getOrNull(num)?.replace("\\u002F", "/")
//
//
// newMovieSearchResponse(
// "$name",
// UrlData(id, type).toJson(),
// TvType.Movie,
// ) {
// this.posterUrl = image
// }
//
// }
//
// }
override suspend fun load(url: String): LoadResponse? {
val data = parseJson<UrlData>(url)

View file

@ -490,8 +490,10 @@ suspend fun getSoraIdAndType(title: String?, year: Int?, season: Int?) : Pair<St
}
}
val id = script?.third?.last() ?: return null
val type = script.third?.get(2) ?: return null
val id = script?.third?.last()?.substringBefore("-") ?: return null
val type = script.third?.get(2)?.let {
if (it == "drama") "1" else "0"
} ?: return null
return id to type
}