[Loklok] added quick search

This commit is contained in:
hexated 2022-12-10 03:28:26 +07:00
parent 9b14e002c2
commit 978c5bc6ba
2 changed files with 36 additions and 20 deletions

View file

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

View file

@ -17,6 +17,7 @@ class Loklok : MainAPI() {
override val hasMainPage = true
override val hasChromecastSupport = true
override val instantLinkLoading = true
override val hasQuickSearch = true
override val supportedTypes = setOf(
TvType.Movie,
TvType.TvSeries,
@ -79,6 +80,23 @@ class Loklok : MainAPI() {
}
}
override suspend fun quickSearch(query: String): List<SearchResponse>? {
val body = mapOf(
"searchKeyWord" to query,
"size" to "50",
"sort" to "",
"searchType" to "",
).toJson().toRequestBody(RequestBodyTypes.JSON.toMediaTypeOrNull())
return app.post(
"$apiUrl/search/v1/searchWithKeyWord",
requestBody = body,
headers = headers
).parsedSafe<QuickSearchRes>()?.data?.searchResults?.mapNotNull { media ->
media.toSearchResponse()
}
}
override suspend fun search(query: String): List<SearchResponse> {
val res = app.get(
"$searchApi/search?keyword=$query",
@ -159,7 +177,7 @@ class Loklok : MainAPI() {
val animeType = if(type == TvType.Anime && data.category == 0) "movie" else "tv"
val malId = if(type == TvType.Anime) {
app.get("${jikanAPI}/anime?q=${res.name}&start_date=${res.year}&type=$animeType&limit=1")
app.get("${jikanAPI}/anime?q=${res.name}&start_date=${res.year}&type=$animeType&order_by=start_date&limit=1")
.parsedSafe<JikanResponse>()?.data?.firstOrNull()?.mal_id
} else {
null
@ -209,26 +227,23 @@ class Loklok : MainAPI() {
subtitleCallback: (SubtitleFile) -> Unit,
callback: (ExtractorLink) -> Unit
): Boolean {
val res = parseJson<UrlEpisode>(data)
val video = res.definitionList?.map {
MetaData(res.category, res.id, res.epId, it.code)
} ?: return false
val json = app.post(
"$apiUrl/media/bathGetplayInfo",
requestBody = video.toJson().toRequestBody(RequestBodyTypes.JSON.toMediaTypeOrNull()),
headers = headers,
).text
tryParseJson<PreviewResponse>(json)?.data?.map { link ->
res.definitionList?.map { video ->
val body = """[{"category":${res.category},"contentId":"${res.id}","episodeId":${res.epId},"definition":"${video.code}"}]""".toRequestBody(RequestBodyTypes.JSON.toMediaTypeOrNull())
val response = app.post(
"$apiUrl/media/bathGetplayInfo",
requestBody = body,
headers = headers,
).text
val json = tryParseJson<PreviewResponse>(response)?.data?.firstOrNull()
callback.invoke(
ExtractorLink(
this.name,
this.name,
link.mediaUrl ?: return@map null,
json?.mediaUrl ?: return@map null,
"",
getQuality(link.currentDefinition ?: ""),
getQuality(json.currentDefinition ?: ""),
isM3u8 = true,
)
)
@ -280,11 +295,12 @@ class Loklok : MainAPI() {
val subtitlingList: List<Subtitling>? = arrayListOf(),
)
data class MetaData(
val category: Int? = null,
val contentId: Any? = null,
val episodeId: Int? = null,
val definition: String? = null,
data class QuickSearchData(
@JsonProperty("searchResults") val searchResults: ArrayList<Media>? = arrayListOf(),
)
data class QuickSearchRes(
@JsonProperty("data") val data: QuickSearchData? = null,
)
data class PreviewResponse(