Skip to content

Commit

Permalink
Merge pull request #426 from Shikkanime/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Ziedelth committed Apr 29, 2024
2 parents 4705c0f + 366af02 commit 1b4eacb
Show file tree
Hide file tree
Showing 28 changed files with 175 additions and 73 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ val h2Version = "2.2.224"
val mockitoVersion = "5.11.0"

plugins {
kotlin("jvm") version "2.0.0-RC1"
kotlin("jvm") version "2.0.0-RC2"
kotlin("kapt") version "1.9.23"
id("io.ktor.plugin") version "2.3.10"
jacoco
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import fr.shikkanime.dtos.variants.EpisodeVariantWithoutMappingDto
import fr.shikkanime.entities.EpisodeVariant
import fr.shikkanime.utils.withUTCString

class EpisodeVariantToEpisodeVariantWithoutMappingDtoConverter : AbstractConverter<EpisodeVariant, EpisodeVariantWithoutMappingDto>() {
class EpisodeVariantToEpisodeVariantWithoutMappingDtoConverter :
AbstractConverter<EpisodeVariant, EpisodeVariantWithoutMappingDto>() {
override fun convert(from: EpisodeVariant): EpisodeVariantWithoutMappingDto {
return EpisodeVariantWithoutMappingDto(
uuid = from.uuid!!,
Expand Down
6 changes: 5 additions & 1 deletion src/main/kotlin/fr/shikkanime/entities/EpisodeMapping.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ import java.util.*
@Table(
name = "episode_mapping",
indexes = [
Index(name = "idx_episode_mapping_anime_episode_type_season_number", columnList = "anime_uuid, episode_type, season, number", unique = true),
Index(
name = "idx_episode_mapping_anime_episode_type_season_number",
columnList = "anime_uuid, episode_type, season, number",
unique = true
),
]
)
@Cacheable
Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/fr/shikkanime/jobs/FetchCalendarJob.kt
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,8 @@ class FetchCalendarJob : AbstractJob {

if (configCacheService.getValueAsBoolean(ConfigPropertyKey.TRANSLATE_CALENDAR)) {
val alternativeTitles =
list.find { it.text().contains("Titre alternatif") }?.text()?.replace("Titre alternatif :", "")?.split("/")
list.find { it.text().contains("Titre alternatif") }?.text()?.replace("Titre alternatif :", "")
?.split("/")
?: emptyList()
val detectedLanguage = languageCacheService.detectLanguage(title)

Expand Down
10 changes: 9 additions & 1 deletion src/main/kotlin/fr/shikkanime/jobs/FetchEpisodesJob.kt
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,15 @@ class FetchEpisodesJob : AbstractJob {
}

val savedEpisodes = episodes
.sortedWith(compareBy({ it.releaseDateTime }, { it.anime }, { it.season }, { it.episodeType }, { it.number }, { it.audioLocale }))
.sortedWith(
compareBy(
{ it.releaseDateTime },
{ it.anime },
{ it.season },
{ it.episodeType },
{ it.number },
{ it.audioLocale })
)
.filter { (zonedDateTime.isEqualOrAfter(it.releaseDateTime)) && !identifiers.contains(it.getIdentifier()) }
.mapNotNull {
try {
Expand Down
46 changes: 35 additions & 11 deletions src/main/kotlin/fr/shikkanime/jobs/FetchOldEpisodesJob.kt
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ class FetchOldEpisodesJob : AbstractJob {
val to = LocalDate.parse(config.propertyValue!!)
val from = to.minusDays(range.toLong())
val dates = from.datesUntil(to.plusDays(1), Period.ofDays(1)).toList().sorted()
val simulcasts = dates.map { "${Constant.seasons[(it.monthValue - 1) / 3]}-${it.year}".lowercase().replace("autumn", "fall") }.toSet()
val simulcasts = dates.map {
"${Constant.seasons[(it.monthValue - 1) / 3]}-${it.year}".lowercase().replace("autumn", "fall")
}.toSet()
val episodes = mutableListOf<AbstractPlatform.Episode>()
val start = System.currentTimeMillis()
logger.info("Fetching old episodes... (From ${dates.first()} to ${dates.last()})")
Expand Down Expand Up @@ -118,14 +120,22 @@ class FetchOldEpisodesJob : AbstractJob {

logger.info("Updating simulcasts...")
animeService.recalculateSimulcasts()
MapCache.invalidate(Anime::class.java, EpisodeMapping::class.java, EpisodeVariant::class.java, Simulcast::class.java)
MapCache.invalidate(
Anime::class.java,
EpisodeMapping::class.java,
EpisodeVariant::class.java,
Simulcast::class.java
)
logger.info("Updating config to the next fetch date...")
config.propertyValue = from.toString()
configService.update(config)
logger.info("Take ${(System.currentTimeMillis() - start) / 1000}s to check ${dates.size} dates")
}

private fun fetchAnimationDigitalNetwork(countryCode: CountryCode, dates: List<LocalDate>): List<AbstractPlatform.Episode> {
private fun fetchAnimationDigitalNetwork(
countryCode: CountryCode,
dates: List<LocalDate>
): List<AbstractPlatform.Episode> {
val episodes = mutableListOf<AbstractPlatform.Episode>()

dates.forEachIndexed { _, date ->
Expand All @@ -140,14 +150,18 @@ class FetchOldEpisodesJob : AbstractJob {
try {
episodes.addAll(
animationDigitalNetworkPlatform.convertEpisode(
countryCode,
episodeJson.asJsonObject,
zonedDateTime,
false
countryCode,
episodeJson.asJsonObject,
zonedDateTime,
false
)
)
} catch (e: Exception) {
logger.log(Level.SEVERE, "Error while converting episode (Episode ID: ${episodeJson.getAsString("id")})", e)
logger.log(
Level.SEVERE,
"Error while converting episode (Episode ID: ${episodeJson.getAsString("id")})",
e
)
}
}
}
Expand Down Expand Up @@ -181,8 +195,14 @@ class FetchOldEpisodesJob : AbstractJob {
series.forEach {
val postersTall = it.getAsJsonObject("images").getAsJsonArray("poster_tall")[0].asJsonArray
val postersWide = it.getAsJsonObject("images").getAsJsonArray("poster_wide")[0].asJsonArray
val image = postersTall?.maxByOrNull { poster -> poster.asJsonObject.getAsInt("width")!! }?.asJsonObject?.getAsString("source")!!
val banner = postersWide?.maxByOrNull { poster -> poster.asJsonObject.getAsInt("width")!! }?.asJsonObject?.getAsString("source")!!
val image =
postersTall?.maxByOrNull { poster -> poster.asJsonObject.getAsInt("width")!! }?.asJsonObject?.getAsString(
"source"
)!!
val banner =
postersWide?.maxByOrNull { poster -> poster.asJsonObject.getAsInt("width")!! }?.asJsonObject?.getAsString(
"source"
)!!
val description = it.getAsString("description")

crunchyrollPlatform.animeInfoCache[CountryCodeIdKeyCache(countryCode, it.getAsString("id")!!)] =
Expand Down Expand Up @@ -228,7 +248,11 @@ class FetchOldEpisodesJob : AbstractJob {
)
)
} catch (e: Exception) {
logger.log(Level.SEVERE, "Error while converting episode (Episode ID: ${episodeJson.getAsString("id")})", e)
logger.log(
Level.SEVERE,
"Error while converting episode (Episode ID: ${episodeJson.getAsString("id")})",
e
)
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/main/kotlin/fr/shikkanime/modules/Routing.kt
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ private fun handleQueryParam(kParameter: KParameter, call: ApplicationCall): Any
null
}
}

else -> throw Exception("Unknown type ${kParameter.type}")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,10 @@ class CrunchyrollPlatform : AbstractPlatform<CrunchyrollConfiguration, CountryCo
configCacheService.getValueAsBoolean(ConfigPropertyKey.CHECK_CRUNCHYROLL_SIMULCASTS, true)
val isConfigurationSimulcast = configuration!!.simulcasts.any { it.name.lowercase() == animeName.lowercase() }

if (needSimulcast && checkCrunchyrollSimulcasts && !(isConfigurationSimulcast || simulcasts[countryCode]!!.contains(animeName.lowercase())))
if (needSimulcast && checkCrunchyrollSimulcasts && !(isConfigurationSimulcast || simulcasts[countryCode]!!.contains(
animeName.lowercase()
))
)
throw AnimeNotSimulcastedException("\"$animeName\" is not simulcasted")

val description = jsonObject.getAsString("description")?.replace('\n', ' ')?.takeIf { it.isNotBlank() }
Expand Down
23 changes: 15 additions & 8 deletions src/main/kotlin/fr/shikkanime/platforms/DisneyPlusPlatform.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,25 @@ class DisneyPlusPlatform :

override fun getConfigurationClass() = DisneyPlusConfiguration::class.java

private val identifiers = MapCache<CountryCode, String>(Duration.ofHours(3).plusMinutes(30), listOf(Config::class.java)) {
return@MapCache runBlocking {
DisneyPlusWrapper.getAccessToken(
configCacheService.getValueAsString(ConfigPropertyKey.DISNEY_PLUS_AUTHORIZATION),
configCacheService.getValueAsString(ConfigPropertyKey.DISNEY_PLUS_REFRESH_TOKEN)
)
private val identifiers =
MapCache<CountryCode, String>(Duration.ofHours(3).plusMinutes(30), listOf(Config::class.java)) {
return@MapCache runBlocking {
DisneyPlusWrapper.getAccessToken(
configCacheService.getValueAsString(ConfigPropertyKey.DISNEY_PLUS_AUTHORIZATION),
configCacheService.getValueAsString(ConfigPropertyKey.DISNEY_PLUS_REFRESH_TOKEN)
)
}
}
}

private val seasons = MapCache<CountryCodeDisneyPlusSimulcastKeyCache, List<String>>(Duration.ofDays(1)) {
val accessToken = identifiers[it.countryCode]!!
return@MapCache runBlocking { DisneyPlusWrapper.getSeasons(accessToken, it.countryCode, it.disneyPlusSimulcast.name) }
return@MapCache runBlocking {
DisneyPlusWrapper.getSeasons(
accessToken,
it.countryCode,
it.disneyPlusSimulcast.name
)
}
}

override suspend fun fetchApiContent(
Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/fr/shikkanime/platforms/NetflixPlatform.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import java.time.LocalTime
import java.time.ZonedDateTime
import java.time.format.DateTimeFormatter

class NetflixPlatform : AbstractPlatform<NetflixConfiguration, CountryCodeNetflixSimulcastKeyCache, Set<AbstractPlatform.Episode>>() {
class NetflixPlatform :
AbstractPlatform<NetflixConfiguration, CountryCodeNetflixSimulcastKeyCache, Set<AbstractPlatform.Episode>>() {
override fun getPlatform(): Platform = Platform.NETF

override fun getConfigurationClass() = NetflixConfiguration::class.java
Expand Down
36 changes: 20 additions & 16 deletions src/main/kotlin/fr/shikkanime/services/EpisodeVariantService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ class EpisodeVariantService : AbstractService<EpisodeVariant, EpisodeVariantRepo
val previousEpisode = animeEpisodes.lastOrNull {
it.releaseDateTime.isBefore(entity.releaseDateTime) &&
it.episodeType == entity.episodeType &&
it.variants.map { variant -> variant.audioLocale }.any { audioLocale -> audioLocale != anime.countryCode!!.locale }
it.variants.map { variant -> variant.audioLocale }
.any { audioLocale -> audioLocale != anime.countryCode!!.locale }
}

val diff = previousEpisode?.releaseDateTime?.until(entity.releaseDateTime, ChronoUnit.MONTHS) ?: -1
Expand All @@ -81,24 +82,27 @@ class EpisodeVariantService : AbstractService<EpisodeVariant, EpisodeVariantRepo
else -> currentSimulcast
}

return simulcastService.findBySeasonAndYear(choosenSimulcast.season!!, choosenSimulcast.year!!) ?: choosenSimulcast
return simulcastService.findBySeasonAndYear(choosenSimulcast.season!!, choosenSimulcast.year!!)
?: choosenSimulcast
}

fun save(episode: AbstractPlatform.Episode): EpisodeVariant {
val anime = animeService.findBySlug(episode.countryCode, StringUtils.toSlug(StringUtils.getShortName(episode.anime))) ?: animeService.save(
Anime(
countryCode = episode.countryCode,
name = episode.anime,
releaseDateTime = episode.releaseDateTime,
lastReleaseDateTime = episode.releaseDateTime,
image = episode.animeImage,
banner = episode.animeBanner,
description = episode.animeDescription,
slug = StringUtils.toSlug(StringUtils.getShortName(episode.anime))
).apply {
status = StringUtils.getStatus(this)
}
)
val anime =
animeService.findBySlug(episode.countryCode, StringUtils.toSlug(StringUtils.getShortName(episode.anime)))
?: animeService.save(
Anime(
countryCode = episode.countryCode,
name = episode.anime,
releaseDateTime = episode.releaseDateTime,
lastReleaseDateTime = episode.releaseDateTime,
image = episode.animeImage,
banner = episode.animeBanner,
description = episode.animeDescription,
slug = StringUtils.toSlug(StringUtils.getShortName(episode.anime))
).apply {
status = StringUtils.getStatus(this)
}
)

val mapping = getEpisodeMapping(anime, episode)
mapping.lastReleaseDateTime = episode.releaseDateTime
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/fr/shikkanime/services/ImageService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ object ImageService {
val image = ImageIO.read(this).resize(32, 32)
close()
image
}
}

return Tuple(backgroundImage, bannerImage, font, animeImage, platformImage)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@ class AnimeCacheService : AbstractCacheService {
}

private val weeklyCache =
MapCache<CountryCodeLocalDateKeyCache, List<WeeklyAnimesDto>>(classes = listOf(EpisodeMapping::class.java, EpisodeVariant::class.java)) {
MapCache<CountryCodeLocalDateKeyCache, List<WeeklyAnimesDto>>(
classes = listOf(
EpisodeMapping::class.java,
EpisodeVariant::class.java
)
) {
animeService.getWeeklyAnimes(it.localDate, it.countryCode)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,18 @@ abstract class AbstractSocialNetwork {

fun getEpisodeMessage(episodeDto: EpisodeVariantDto, baseMessage: String): String {
val uncensored = if (episodeDto.uncensored) " non censuré" else ""
val isVoice = if (LangType.fromAudioLocale(episodeDto.mapping.anime.countryCode, episodeDto.audioLocale) == LangType.VOICE) " en VF " else " "
val isVoice = if (LangType.fromAudioLocale(
episodeDto.mapping.anime.countryCode,
episodeDto.audioLocale
) == LangType.VOICE
) " en VF " else " "

var configMessage = baseMessage
configMessage = configMessage.replace("{SHIKKANIME_URL}", getShikkanimeUrl(episodeDto))
configMessage = configMessage.replace("{URL}", episodeDto.url)
configMessage = configMessage.replace("{PLATFORM_ACCOUNT}", platformAccount(episodeDto.platform))
configMessage =
configMessage.replace("{ANIME_HASHTAG}", "#${StringUtils.getHashtag(episodeDto.mapping.anime.shortName)}")
configMessage = configMessage.replace("{PLATFORM_NAME}", episodeDto.platform.name)
configMessage = configMessage.replace("{ANIME_HASHTAG}", "#${StringUtils.getHashtag(episodeDto.mapping.anime.shortName)}")
configMessage = configMessage.replace("{ANIME_TITLE}", episodeDto.mapping.anime.shortName)
configMessage = configMessage.replace("{EPISODE_INFORMATION}", "${information(episodeDto)}${uncensored}")
configMessage = configMessage.replace("{VOICE}", isVoice)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,13 @@ class DiscordSocialNetwork : AbstractSocialNetwork() {
)
embedMessage.setTitle(episodeDto.mapping.anime.shortName, getShikkanimeUrl(episodeDto))
embedMessage.setThumbnail(episodeDto.mapping.anime.image)
embedMessage.setDescription("**${episodeDto.mapping.title ?: "Untitled"}**\n${StringUtils.toEpisodeString(episodeDto)}")
embedMessage.setDescription(
"**${episodeDto.mapping.title ?: "Untitled"}**\n${
StringUtils.toEpisodeString(
episodeDto
)
}"
)
embedMessage.setImage(episodeDto.mapping.image)
embedMessage.setFooter(Constant.NAME, "${Constant.baseUrl}/assets/img/favicons/favicon-64x64.png")
embedMessage.setTimestamp(ZonedDateTime.parse(episodeDto.releaseDateTime).toInstant())
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/db/changelog/2024/03/02-changelog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.26.xsd" objectQuotingStrategy="QUOTE_ONLY_RESERVED_WORDS">
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.26.xsd"
objectQuotingStrategy="QUOTE_ONLY_RESERVED_WORDS">
<property global="false" name="id" value="1709800525900"/>
<property global="false" name="author" value="Ziedelth"/>

Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/db/changelog/2024/03/03-changelog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.26.xsd" objectQuotingStrategy="QUOTE_ONLY_RESERVED_WORDS">
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.26.xsd"
objectQuotingStrategy="QUOTE_ONLY_RESERVED_WORDS">
<property global="false" name="id" value="1710164378809"/>
<property global="false" name="author" value="Ziedelth"/>

Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/db/changelog/2024/03/06-changelog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
<insert tableName="config">
<column name="uuid" valueComputed="gen_random_uuid()"/>
<column name="property_key" value="animation_digital_network_simulcast_detection_regex"/>
<column name="property_value" value="\((premier épisode |diffusion des épisodes |diffusion du premier épisode|diffusion de l'épisode 1 le)"/>
<column name="property_value"
value="\((premier épisode |diffusion des épisodes |diffusion du premier épisode|diffusion de l'épisode 1 le)"/>
</insert>
</changeSet>
</databaseChangeLog>
3 changes: 2 additions & 1 deletion src/main/resources/db/changelog/2024/04/01-changelog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.27.xsd" objectQuotingStrategy="QUOTE_ONLY_RESERVED_WORDS">
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.27.xsd"
objectQuotingStrategy="QUOTE_ONLY_RESERVED_WORDS">
<property global="false" name="id" value="1712236123260"/>
<property global="false" name="author" value="Ziedelth"/>

Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/db/changelog/2024/04/03-changelog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.27.xsd" objectQuotingStrategy="QUOTE_ONLY_RESERVED_WORDS">
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.27.xsd"
objectQuotingStrategy="QUOTE_ONLY_RESERVED_WORDS">
<property global="false" name="id" value="1712664794374"/>
<property global="false" name="author" value="Ziedelth"/>

Expand Down
Loading

0 comments on commit 1b4eacb

Please sign in to comment.