feat(de/kool): improve search (#1948)

This commit is contained in:
LuftVerbot
2023-07-24 02:00:50 +02:00
committed by GitHub
parent 86fad85c37
commit 3a58f5b620
2 changed files with 35 additions and 25 deletions

View File

@ -6,7 +6,7 @@ ext {
extName = 'Kool'
pkgNameSuffix = 'de.kool'
extClass = '.Kool'
extVersionCode = 1
extVersionCode = 2
libVersion = '13'
}

View File

@ -19,7 +19,6 @@ import eu.kanade.tachiyomi.lib.filemoonextractor.FilemoonExtractor
import eu.kanade.tachiyomi.lib.streamtapeextractor.StreamTapeExtractor
import eu.kanade.tachiyomi.lib.voeextractor.VoeExtractor
import eu.kanade.tachiyomi.network.POST
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonArray
import kotlinx.serialization.json.JsonObject
@ -618,13 +617,18 @@ class Kool : ConfigurableAnimeSource, AnimeHttpSource() {
// private var animeListS = mutableListOf<SAnime>()
private fun parseSearchAnimeJson(movieJson: String?, url: String): AnimesPage {
// Define the batch size for processing JSON items
val bATCHSIZE = 50
val animeList = mutableListOf<SAnime>()
val movieJsonData = movieJson ?: return AnimesPage(emptyList(), false)
val movieJObject = json.decodeFromString<JsonObject>(movieJsonData)
val movieArray = movieJObject["items"]?.jsonArray ?: return AnimesPage(emptyList(), false)
val searchMovieCursor = movieJObject.jsonObject["nextCursor"]?.jsonPrimitive?.content.orEmpty()
animeList.addAll(
movieArray.mapNotNull { item ->
var hasNextPage = !searchMovieCursor.contains("null")
for (item in movieArray) {
val anime = SAnime.create()
anime.title = item.jsonObject["name"]?.jsonPrimitive?.content.orEmpty()
val idsObject = item.jsonObject["ids"]?.jsonObject
@ -643,11 +647,17 @@ class Kool : ConfigurableAnimeSource, AnimeHttpSource() {
images["poster"]?.jsonPrimitive?.content ?: images["backdrop"]?.jsonPrimitive?.content
}
}
anime
},
)
val animeListS = animeList.filterIndexed { index, _ -> index in 1..9 }
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)
}