Skip to content

Commit

Permalink
fix configuration simulcast last usage
Browse files Browse the repository at this point in the history
  • Loading branch information
Ziedelth committed Dec 27, 2024
1 parent 462212b commit 65d4d48
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 24 deletions.
8 changes: 6 additions & 2 deletions src/main/kotlin/fr/shikkanime/jobs/FetchEpisodesJob.kt
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ class FetchEpisodesJob : AbstractJob {
try {
val savedEpisode = episodeVariantService.save(it)
identifiers.add(it.getIdentifier())

if (it.isConfigurationSimulcasted == true && it.isSimulcasted == false)
Constant.abstractPlatforms.forEach { abstractPlatform -> abstractPlatform.updateAnimeSimulcastConfiguration(it.anime) }

savedEpisode
} catch (e: Exception) {
logger.log(Level.SEVERE, "Error while saving episode ${it.getIdentifier()} (${it.anime})", e)
Expand Down Expand Up @@ -149,8 +153,8 @@ class FetchEpisodesJob : AbstractJob {
episodes.filter { typeIdentifiers.add(getTypeIdentifier(it)) }
.takeIf { it.size < sizeLimit }
?.groupBy { it.mapping?.uuid }
?.forEach { _, episodes ->
val dtos = AbstractConverter.convert(episodes, EpisodeVariantDto::class.java)!!
?.forEach { (_, groupedEpisodes) ->
val dtos = AbstractConverter.convert(groupedEpisodes, EpisodeVariantDto::class.java)!!
sendToSocialNetworks(dtos)
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/main/kotlin/fr/shikkanime/platforms/AbstractPlatform.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ abstract class AbstractPlatform<C : PlatformConfiguration<*>, K : Any, V> {
val url: String,
val uncensored: Boolean,
val original: Boolean,
val isConfigurationSimulcasted: Boolean? = null,
val isSimulcasted: Boolean? = null,
) {
fun getIdentifier() = StringUtils.getIdentifier(countryCode, platform, id, audioLocale, uncensored)
}
Expand Down Expand Up @@ -98,7 +100,9 @@ abstract class AbstractPlatform<C : PlatformConfiguration<*>, K : Any, V> {
private fun getConfigurationFile() =
File(Constant.configFolder, "${getPlatform().platformName.lowercase().replace(" ", "-")}.json")

fun updateAnimeSimulcast(name: String) {
fun containsAnimeSimulcastConfiguration(name: String) = configuration!!.simulcasts.any { it.name.lowercase() == name.lowercase() }

fun updateAnimeSimulcastConfiguration(name: String) {
configuration!!.simulcasts.find { it.name.lowercase() == name.lowercase() }?.let {
it.lastUsageDateTime = ZonedDateTime.now().withUTCString()
saveConfiguration()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,15 @@ class AnimationDigitalNetworkPlatform :
if (configuration!!.blacklistedSimulcasts.contains(animeName.lowercase())) throw AnimeException("\"$animeName\" is blacklisted")

val genres = video.show.genres
val isConfigurationSimulcast = configuration!!.containsAnimeSimulcast(animeName)
val isConfigurationSimulcasted = containsAnimeSimulcastConfiguration(animeName)

if ((genres.isEmpty() || !genres.any { it.startsWith("Animation ", true) }) && !isConfigurationSimulcast && checkAnimation)
if ((genres.isEmpty() || !genres.any { it.startsWith("Animation ", true) }) && !isConfigurationSimulcasted && checkAnimation)
throw Exception("Anime is not an animation")

if (needSimulcast) {
val isSimulcasted = video.show.simulcast ||
video.show.firstReleaseYear in (0..1).map { (zonedDateTime.year - it).toString() } ||
isConfigurationSimulcast ||
configCacheService.getValueAsString(ConfigPropertyKey.ANIMATION_DITIGAL_NETWORK_SIMULCAST_DETECTION_REGEX)
?.let { Regex(it).containsMatchIn((video.show.summary.normalize() ?: "").lowercase()) } == true
val isSimulcasted = video.show.simulcast || video.show.firstReleaseYear in (0..1).map { (zonedDateTime.year - it).toString() } || configCacheService.getValueAsString(ConfigPropertyKey.ANIMATION_DITIGAL_NETWORK_SIMULCAST_DETECTION_REGEX)?.let { Regex(it).containsMatchIn((video.show.summary.normalize() ?: "").lowercase()) } == true

if (!isSimulcasted) throw AnimeNotSimulcastedException("Anime is not simulcasted")
}
if (needSimulcast && !(isConfigurationSimulcasted || isSimulcasted))
throw AnimeNotSimulcastedException("Anime is not simulcasted")

val trailerIndicators = listOf("Bande-annonce", "Bande annonce", "Court-métrage", "Opening", "Making-of")
val specialShowTypes = listOf("PV", "BONUS")
Expand All @@ -99,9 +94,6 @@ class AnimationDigitalNetworkPlatform :

val (number, episodeType) = getNumberAndEpisodeType(video.shortNumber, video.type)

if (needSimulcast)
updateAnimeSimulcast(animeName)

return video.languages.map {
Episode(
countryCode = countryCode,
Expand All @@ -110,6 +102,8 @@ class AnimationDigitalNetworkPlatform :
animeImage = video.show.image2x,
animeBanner = video.show.imageHorizontal2x,
animeDescription = video.show.summary.normalize(),
isConfigurationSimulcasted = isConfigurationSimulcasted,
isSimulcasted = isSimulcasted,
releaseDateTime = video.releaseDate,
episodeType = episodeType,
seasonId = video.season ?: "1",
Expand Down
11 changes: 6 additions & 5 deletions src/main/kotlin/fr/shikkanime/platforms/CrunchyrollPlatform.kt
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,14 @@ class CrunchyrollPlatform : AbstractPlatform<CrunchyrollConfiguration, CountryCo
throw EpisodeNoSubtitlesOrVoiceException("Episode is not available in ${countryCode.name} with subtitles or voice")

val crunchyrollAnimeContent = runBlocking { CrunchyrollCachedWrapper.getSeries(countryCode.locale, browseObject.episodeMetadata.seriesId) }
val isConfigurationSimulcast = configuration!!.containsAnimeSimulcast(animeName)
val isConfigurationSimulcasted = containsAnimeSimulcastConfiguration(animeName)
val season = runBlocking { CrunchyrollCachedWrapper.getSeason(countryCode.locale, browseObject.episodeMetadata.seasonId) }

val (number, episodeType) = getNumberAndEpisodeType(browseObject.episodeMetadata, season)

if (needSimulcast && !(isConfigurationSimulcast || crunchyrollAnimeContent.isSimulcast || isDubbed || episodeType == EpisodeType.FILM))
val isSimulcasted = crunchyrollAnimeContent.isSimulcast || isDubbed || episodeType == EpisodeType.FILM

if (needSimulcast && !(isConfigurationSimulcasted || isSimulcasted))
throw AnimeNotSimulcastedException("\"$animeName\" is not simulcasted")

var original = true
Expand All @@ -202,16 +204,15 @@ class CrunchyrollPlatform : AbstractPlatform<CrunchyrollConfiguration, CountryCo
original = currentVersion?.original != false
}

if (needSimulcast)
updateAnimeSimulcast(animeName)

return Episode(
countryCode = countryCode,
animeId = browseObject.episodeMetadata.seriesId,
anime = animeName,
animeImage = crunchyrollAnimeContent.fullHDImage!!,
animeBanner = crunchyrollAnimeContent.fullHDBanner!!,
animeDescription = crunchyrollAnimeContent.description.normalize(),
isConfigurationSimulcasted = isConfigurationSimulcasted,
isSimulcasted = isSimulcasted,
releaseDateTime = browseObject.episodeMetadata.premiumAvailableDate,
episodeType = episodeType,
seasonId = browseObject.episodeMetadata.seasonId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ abstract class PlatformConfiguration<S : PlatformSimulcast>(
@Suppress("UNCHECKED_CAST")
fun addPlatformSimulcast(simulcast: PlatformSimulcast) = simulcasts.add(simulcast as S)

fun containsAnimeSimulcast(name: String) = simulcasts.any { it.name.lowercase() == name.lowercase() }

open fun of(parameters: Parameters) {
parameters["availableCountries"]?.let {
availableCountries = if (it.isNotBlank()) CountryCode.from(it.split(",")) else emptySet()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ class CrunchyrollPlatformTest : AbstractTest() {
assertEquals("Metallic Rouge", episodes[1].anime)
assertEquals("ja-JP", episodes[1].audioLocale)
assertNotNull(episodes[1].description)
assertNotNull(platform.configuration?.simulcasts?.first()?.lastUsageDateTime)
}

@Test
Expand Down

0 comments on commit 65d4d48

Please sign in to comment.