From 7ee31320ed4853cbc670cd204dd38fc81f1928a1 Mon Sep 17 00:00:00 2001 From: hexated Date: Tue, 7 Feb 2023 20:10:00 +0700 Subject: [PATCH] fixed Loklok --- Loklok/build.gradle.kts | 2 +- Loklok/src/main/kotlin/com/hexated/Loklok.kt | 27 ++++++++++++-------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/Loklok/build.gradle.kts b/Loklok/build.gradle.kts index 7ac9fc4f..e3bf2933 100644 --- a/Loklok/build.gradle.kts +++ b/Loklok/build.gradle.kts @@ -1,5 +1,5 @@ // use an integer for version numbers -version = 14 +version = 15 cloudstream { diff --git a/Loklok/src/main/kotlin/com/hexated/Loklok.kt b/Loklok/src/main/kotlin/com/hexated/Loklok.kt index 85dbf6c7..a9782061 100644 --- a/Loklok/src/main/kotlin/com/hexated/Loklok.kt +++ b/Loklok/src/main/kotlin/com/hexated/Loklok.kt @@ -7,7 +7,6 @@ import com.lagradost.cloudstream3.LoadResponse.Companion.addMalId import com.lagradost.cloudstream3.utils.* import com.lagradost.cloudstream3.utils.AppUtils.parseJson import com.lagradost.cloudstream3.utils.AppUtils.toJson -import com.lagradost.cloudstream3.utils.AppUtils.tryParseJson import com.lagradost.nicehttp.RequestBodyTypes import okhttp3.MediaType.Companion.toMediaTypeOrNull import okhttp3.RequestBody.Companion.toRequestBody @@ -25,10 +24,10 @@ class Loklok : MainAPI() { TvType.AsianDrama, ) - private val headers = mapOf( + private val headers = mutableMapOf( "lang" to "en", - "versioncode" to "11", - "clienttype" to "ios_jike_default" + "versioncode" to "32", + "clienttype" to "android_tem3", ) // no license found @@ -132,6 +131,8 @@ class Loklok : MainAPI() { headers = headers ).parsedSafe()?.data ?: throw ErrorLoadingException("Invalid Json Reponse") + headers["deviceid"] = getDevideId(16) + val episodes = res.episodeVo?.map { eps -> val definition = eps.definitionList?.map { Definition( @@ -218,13 +219,10 @@ class Loklok : MainAPI() { val res = parseJson(data) res.definitionList?.apmap { 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, + val json = app.get( + "$apiUrl/media/previewInfo?category=${res.category}&contentId=${res.id}&episodeId=${res.epId}&definition=${video.code}", headers = headers, - ).text - val json = tryParseJson(response)?.data?.firstOrNull() + ).parsedSafe()?.data callback.invoke( ExtractorLink( this.name, @@ -259,6 +257,13 @@ class Loklok : MainAPI() { } } + private fun getDevideId(length: Int): String { + val allowedChars = ('a'..'f') + ('0'..'9') + return (1..length) + .map { allowedChars.random() } + .joinToString("") + } + private suspend fun getTracker(title: String?, type: String?, year: Int?): Tracker { val res = app.get("https://api.consumet.org/meta/anilist/$title") .parsedSafe()?.results?.find { media -> @@ -329,7 +334,7 @@ class Loklok : MainAPI() { ) data class PreviewResponse( - @JsonProperty("data") val data: ArrayList? = arrayListOf(), + @JsonProperty("data") val data: PreviewVideos? = null, ) data class PreviewVideos(