Skip to content

Commit

Permalink
fix: crunchyroll update episode job
Browse files Browse the repository at this point in the history
  • Loading branch information
Ziedelth committed Sep 17, 2024
1 parent 950238d commit 119ef92
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
14 changes: 13 additions & 1 deletion src/main/kotlin/fr/shikkanime/jobs/UpdateEpisodeJob.kt
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,19 @@ class UpdateEpisodeJob : AbstractJob {
countryCode: CountryCode,
crunchyrollId: String,
): List<Episode> {
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 }
Expand Down
11 changes: 10 additions & 1 deletion src/main/kotlin/fr/shikkanime/wrappers/CrunchyrollWrapper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,16 @@ object CrunchyrollWrapper {
val versions: List<Version>?,
@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,
Expand Down

0 comments on commit 119ef92

Please sign in to comment.