[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 // use an integer for version numbers
version = 10 version = 11
cloudstream { cloudstream {

View file

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