Skip to content

Commit

Permalink
Add stacktrace on animeInfoCache in CrunchyrollPlatform.kt
Browse files Browse the repository at this point in the history
  • Loading branch information
Ziedelth committed Jul 2, 2024
1 parent 9c741ce commit c1b9ff7
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 deletions src/main/kotlin/fr/shikkanime/platforms/CrunchyrollPlatform.kt
Original file line number Diff line number Diff line change
Expand Up @@ -61,26 +61,31 @@ class CrunchyrollPlatform :
return@MapCache simulcastSeries
}

private val animeInfoCache = MapCache<CountryCodeIdKeyCache, CrunchyrollAnimeContent>(Duration.ofDays(1)) {
val token = identifiers[it.countryCode]!!
val series = runBlocking {
CrunchyrollWrapper.getSeries(
it.countryCode.locale,
token,
it.id
)
}
private val animeInfoCache = MapCache<CountryCodeIdKeyCache, CrunchyrollAnimeContent?>(Duration.ofDays(1)) {
try {
val token = identifiers[it.countryCode]!!
val series = runBlocking {
CrunchyrollWrapper.getSeries(
it.countryCode.locale,
token,
it.id
)
}

val image = series.images.posterTall.first().maxByOrNull { poster -> poster.width }?.source
val banner = series.images.posterWide.first().maxByOrNull { poster -> poster.width }?.source
val image = series.images.posterTall.first().maxByOrNull { poster -> poster.width }?.source
val banner = series.images.posterWide.first().maxByOrNull { poster -> poster.width }?.source

if (image.isNullOrEmpty())
throw Exception("Image is null or empty")
if (image.isNullOrEmpty())
throw Exception("Image is null or empty")

if (banner.isNullOrEmpty())
throw Exception("Banner is null or empty")
if (banner.isNullOrEmpty())
throw Exception("Banner is null or empty")

return@MapCache CrunchyrollAnimeContent(image, banner, series.description, series.isSimulcast)
return@MapCache CrunchyrollAnimeContent(image, banner, series.description, series.isSimulcast)
} catch (e: Exception) {
logger.log(Level.SEVERE, "Error on fetching anime info", e)
return@MapCache null
}
}

override fun getPlatform(): Platform = Platform.CRUN
Expand Down Expand Up @@ -166,7 +171,7 @@ class CrunchyrollPlatform :
throw AnimeNotSimulcastedException("\"$animeName\" is not simulcasted")

val crunchyrollAnimeContent =
animeInfoCache[CountryCodeIdKeyCache(countryCode, browseObject.episodeMetadata.seriesId)]!!
animeInfoCache[CountryCodeIdKeyCache(countryCode, browseObject.episodeMetadata.seriesId)] ?: throw AnimeException("Anime not found")

if (needSimulcast && !checkCrunchyrollSimulcasts && !(isConfigurationSimulcast || crunchyrollAnimeContent.simulcast))
throw AnimeNotSimulcastedException("\"$animeName\" is not simulcasted")
Expand Down

0 comments on commit c1b9ff7

Please sign in to comment.