From 119ef929c39178364091d289841489528cc7db0f Mon Sep 17 00:00:00 2001 From: Ziedelth Date: Fri, 13 Sep 2024 16:41:24 +0200 Subject: [PATCH] fix: crunchyroll update episode job --- .../kotlin/fr/shikkanime/jobs/UpdateEpisodeJob.kt | 14 +++++++++++++- .../fr/shikkanime/wrappers/CrunchyrollWrapper.kt | 11 ++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/fr/shikkanime/jobs/UpdateEpisodeJob.kt b/src/main/kotlin/fr/shikkanime/jobs/UpdateEpisodeJob.kt index ff44b0b3..21820eac 100644 --- a/src/main/kotlin/fr/shikkanime/jobs/UpdateEpisodeJob.kt +++ b/src/main/kotlin/fr/shikkanime/jobs/UpdateEpisodeJob.kt @@ -227,7 +227,19 @@ class UpdateEpisodeJob : AbstractJob { countryCode: CountryCode, crunchyrollId: String, ): List { - val crunchyrollEpisode = CrunchyrollWrapper.getObjects(countryCode.locale, crunchyrollPlatform.identifiers[countryCode]!!, crunchyrollId).first() + val crunchyrollEpisode = runCatching { + CrunchyrollWrapper.getObjects(countryCode.locale, crunchyrollPlatform.identifiers[countryCode]!!, crunchyrollId).first() + }.getOrElse { e -> + logger.warning("Error while fetching Crunchyroll Browse Object: ${e.message}") + + runCatching { + CrunchyrollWrapper.getEpisode(countryCode.locale, crunchyrollPlatform.identifiers[countryCode]!!, crunchyrollId) + .convertToBrowseObject() + }.getOrElse { e2 -> + logger.warning("Error while fetching Crunchyroll Episode: ${e2.message}") + return emptyList() + } + } val versionIds = crunchyrollEpisode.episodeMetadata!!.versions?.toMutableList() ?: mutableListOf(CrunchyrollWrapper.Version(crunchyrollEpisode.id, true)) versionIds.removeIf { it.guid.isBlank() || it.guid == crunchyrollId } diff --git a/src/main/kotlin/fr/shikkanime/wrappers/CrunchyrollWrapper.kt b/src/main/kotlin/fr/shikkanime/wrappers/CrunchyrollWrapper.kt index 52a0b548..795dade2 100644 --- a/src/main/kotlin/fr/shikkanime/wrappers/CrunchyrollWrapper.kt +++ b/src/main/kotlin/fr/shikkanime/wrappers/CrunchyrollWrapper.kt @@ -95,7 +95,16 @@ object CrunchyrollWrapper { val versions: List?, @SerializedName("next_episode_id") val nextEpisodeId: String?, - ) + ) { + fun convertToBrowseObject() = BrowseObject( + id = id!!, + images = images, + description = description, + title = title, + episodeMetadata = this, + slugTitle = slugTitle, + ) + } data class BrowseObject( val id: String,