feat(de/kool): improve search (#1948)
This commit is contained in:
@ -6,7 +6,7 @@ ext {
|
|||||||
extName = 'Kool'
|
extName = 'Kool'
|
||||||
pkgNameSuffix = 'de.kool'
|
pkgNameSuffix = 'de.kool'
|
||||||
extClass = '.Kool'
|
extClass = '.Kool'
|
||||||
extVersionCode = 1
|
extVersionCode = 2
|
||||||
libVersion = '13'
|
libVersion = '13'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,7 +19,6 @@ import eu.kanade.tachiyomi.lib.filemoonextractor.FilemoonExtractor
|
|||||||
import eu.kanade.tachiyomi.lib.streamtapeextractor.StreamTapeExtractor
|
import eu.kanade.tachiyomi.lib.streamtapeextractor.StreamTapeExtractor
|
||||||
import eu.kanade.tachiyomi.lib.voeextractor.VoeExtractor
|
import eu.kanade.tachiyomi.lib.voeextractor.VoeExtractor
|
||||||
import eu.kanade.tachiyomi.network.POST
|
import eu.kanade.tachiyomi.network.POST
|
||||||
import kotlinx.serialization.decodeFromString
|
|
||||||
import kotlinx.serialization.json.Json
|
import kotlinx.serialization.json.Json
|
||||||
import kotlinx.serialization.json.JsonArray
|
import kotlinx.serialization.json.JsonArray
|
||||||
import kotlinx.serialization.json.JsonObject
|
import kotlinx.serialization.json.JsonObject
|
||||||
@ -618,36 +617,47 @@ class Kool : ConfigurableAnimeSource, AnimeHttpSource() {
|
|||||||
// private var animeListS = mutableListOf<SAnime>()
|
// private var animeListS = mutableListOf<SAnime>()
|
||||||
|
|
||||||
private fun parseSearchAnimeJson(movieJson: String?, url: String): AnimesPage {
|
private fun parseSearchAnimeJson(movieJson: String?, url: String): AnimesPage {
|
||||||
|
// Define the batch size for processing JSON items
|
||||||
|
val bATCHSIZE = 50
|
||||||
|
|
||||||
val animeList = mutableListOf<SAnime>()
|
val animeList = mutableListOf<SAnime>()
|
||||||
val movieJsonData = movieJson ?: return AnimesPage(emptyList(), false)
|
val movieJsonData = movieJson ?: return AnimesPage(emptyList(), false)
|
||||||
val movieJObject = json.decodeFromString<JsonObject>(movieJsonData)
|
val movieJObject = json.decodeFromString<JsonObject>(movieJsonData)
|
||||||
val movieArray = movieJObject["items"]?.jsonArray ?: return AnimesPage(emptyList(), false)
|
val movieArray = movieJObject["items"]?.jsonArray ?: return AnimesPage(emptyList(), false)
|
||||||
val searchMovieCursor = movieJObject.jsonObject["nextCursor"]?.jsonPrimitive?.content.orEmpty()
|
val searchMovieCursor = movieJObject.jsonObject["nextCursor"]?.jsonPrimitive?.content.orEmpty()
|
||||||
animeList.addAll(
|
|
||||||
movieArray.mapNotNull { item ->
|
var hasNextPage = !searchMovieCursor.contains("null")
|
||||||
val anime = SAnime.create()
|
|
||||||
anime.title = item.jsonObject["name"]?.jsonPrimitive?.content.orEmpty()
|
for (item in movieArray) {
|
||||||
val idsObject = item.jsonObject["ids"]?.jsonObject
|
val anime = SAnime.create()
|
||||||
val animeId = idsObject?.get("urlId")?.jsonPrimitive?.content ?: idsObject?.get("tmdb_id")?.jsonPrimitive?.content
|
anime.title = item.jsonObject["name"]?.jsonPrimitive?.content.orEmpty()
|
||||||
val type = item.jsonObject["type"]?.jsonPrimitive?.content.orEmpty()
|
val idsObject = item.jsonObject["ids"]?.jsonObject
|
||||||
when {
|
val animeId = idsObject?.get("urlId")?.jsonPrimitive?.content ?: idsObject?.get("tmdb_id")?.jsonPrimitive?.content
|
||||||
type == "iptv" -> {
|
val type = item.jsonObject["type"]?.jsonPrimitive?.content.orEmpty()
|
||||||
anime.setUrlWithoutDomain(item.jsonObject["url"]?.jsonPrimitive?.content.orEmpty())
|
when {
|
||||||
}
|
type == "iptv" -> {
|
||||||
else -> {
|
anime.setUrlWithoutDomain(item.jsonObject["url"]?.jsonPrimitive?.content.orEmpty())
|
||||||
anime.url = item.jsonObject["url"]?.jsonPrimitive?.content ?: "$baseUrl/data/watch/?_id=$animeId&type=$type"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (!url.contains("kool-cluster")) {
|
else -> {
|
||||||
anime.thumbnail_url = item.jsonObject["images"]?.jsonObject?.let { images ->
|
anime.url = item.jsonObject["url"]?.jsonPrimitive?.content ?: "$baseUrl/data/watch/?_id=$animeId&type=$type"
|
||||||
images["poster"]?.jsonPrimitive?.content ?: images["backdrop"]?.jsonPrimitive?.content
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
anime
|
}
|
||||||
},
|
if (!url.contains("kool-cluster")) {
|
||||||
)
|
anime.thumbnail_url = item.jsonObject["images"]?.jsonObject?.let { images ->
|
||||||
val animeListS = animeList.filterIndexed { index, _ -> index in 1..9 }
|
images["poster"]?.jsonPrimitive?.content ?: images["backdrop"]?.jsonPrimitive?.content
|
||||||
val hasNextPage = !searchMovieCursor.contains("null")
|
}
|
||||||
|
}
|
||||||
|
animeList.add(anime)
|
||||||
|
|
||||||
|
// If the list size reaches a certain limit, return a batch of results to prevent crashes
|
||||||
|
if (animeList.size >= bATCHSIZE) {
|
||||||
|
val animeListS = animeList.filterIndexed { index, _ -> index in 1..50 }
|
||||||
|
return AnimesPage(animeListS.takeIf { it.isNotEmpty() } ?: animeList, hasNextPage)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the entire JSON response has been processed, return the remaining results
|
||||||
|
val animeListS = animeList.filterIndexed { index, _ -> index in 1..50 }
|
||||||
return AnimesPage(animeListS.takeIf { it.isNotEmpty() } ?: animeList, hasNextPage)
|
return AnimesPage(animeListS.takeIf { it.isNotEmpty() } ?: animeList, hasNextPage)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user