From 6c2e2588e77d210395651bb9b44a9a8b2be9ed39 Mon Sep 17 00:00:00 2001 From: Ziedelth Date: Wed, 24 Jan 2024 20:05:23 +0100 Subject: [PATCH] Fix Crunchyroll API --- .../platforms/CrunchyrollPlatform.kt | 30 ++++++++----- .../platforms/CrunchyrollPlatformTest.kt | 43 ++++++++++++++++++- .../crunchyroll/api-2024-01-24T18-45-00Z.json | 1 + 3 files changed, 63 insertions(+), 11 deletions(-) create mode 100644 src/test/resources/crunchyroll/api-2024-01-24T18-45-00Z.json diff --git a/src/main/kotlin/fr/shikkanime/platforms/CrunchyrollPlatform.kt b/src/main/kotlin/fr/shikkanime/platforms/CrunchyrollPlatform.kt index 22dc5aa8..05edd4dd 100644 --- a/src/main/kotlin/fr/shikkanime/platforms/CrunchyrollPlatform.kt +++ b/src/main/kotlin/fr/shikkanime/platforms/CrunchyrollPlatform.kt @@ -16,7 +16,6 @@ import fr.shikkanime.utils.ConfigPropertyKey import fr.shikkanime.utils.HttpRequest import fr.shikkanime.utils.MapCache import fr.shikkanime.utils.ObjectParser -import fr.shikkanime.utils.ObjectParser.getAsBoolean import fr.shikkanime.utils.ObjectParser.getAsInt import fr.shikkanime.utils.ObjectParser.getAsLong import fr.shikkanime.utils.ObjectParser.getAsString @@ -190,17 +189,28 @@ class CrunchyrollPlatform : AbstractPlatform { + return if (bypassFileContent != null && bypassFileContent.exists()) { + if (configCacheService.getValueAsBoolean(ConfigPropertyKey.USE_CRUNCHYROLL_API)) { + ObjectParser.fromJson(bypassFileContent.readText()).getAsJsonArray("items").map { it.asJsonObject } + } else { + jsonObjects(bypassFileContent.readText()) + } + } else getApiContent( + countryCode, + zonedDateTime + ) + } + override fun fetchEpisodes(zonedDateTime: ZonedDateTime, bypassFileContent: File?): List { val list = mutableListOf() configuration!!.availableCountries.forEach { countryCode -> - val api = - if (bypassFileContent != null && bypassFileContent.exists()) { - jsonObjects(bypassFileContent.readText()) - } else getApiContent( - countryCode, - zonedDateTime - ) + val api = parseAPIContent(bypassFileContent, countryCode, zonedDateTime) api.forEach { try { @@ -243,11 +253,11 @@ class CrunchyrollPlatform : AbstractPlatform