Skip to content

Commit

Permalink
Merge pull request #312 from Shikkanime/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Ziedelth authored Mar 26, 2024
2 parents abaa7e9 + c0d27d9 commit 206faf2
Show file tree
Hide file tree
Showing 13 changed files with 5,164 additions and 44 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ val junitVersion = "5.10.2"
val h2Version = "2.2.224"

plugins {
kotlin("jvm") version "1.9.23"
kotlin("jvm") version "2.0.0-Beta5"
id("io.ktor.plugin") version "2.3.9"
jacoco
id("org.sonarqube") version "4.4.1.3373"
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/fr/shikkanime/entities/Anime.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Anime(
var banner: String? = null,
@Column(nullable = true, columnDefinition = "VARCHAR(2000)")
var description: String? = null,
@ManyToMany
@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(
name = "anime_simulcast",
joinColumns = [JoinColumn(name = "anime_uuid")],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ enum class ConfigPropertyKey(val key: String) {
ANALYTICS_API("analytics_api"),
ANALYTICS_SCRIPT("analytics_script"),
CRUNCHYROLL_FETCH_API_SIZE("crunchyroll_fetch_api_size"),
ANIMATION_DITIGAL_NETWORK_SIMULCAST_DETECTION_REGEX("animation_digital_network_simulcast_detection_regex"),
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ package fr.shikkanime.platforms

import com.google.gson.JsonArray
import com.google.gson.JsonObject
import com.google.inject.Inject
import fr.shikkanime.entities.Anime
import fr.shikkanime.entities.Episode
import fr.shikkanime.entities.enums.CountryCode
import fr.shikkanime.entities.enums.EpisodeType
import fr.shikkanime.entities.enums.LangType
import fr.shikkanime.entities.enums.Platform
import fr.shikkanime.entities.enums.*
import fr.shikkanime.exceptions.AnimeException
import fr.shikkanime.exceptions.AnimeNotSimulcastedException
import fr.shikkanime.platforms.configuration.AnimationDigitalNetworkConfiguration
import fr.shikkanime.services.caches.ConfigCacheService
import fr.shikkanime.utils.ObjectParser
import fr.shikkanime.utils.ObjectParser.getAsBoolean
import fr.shikkanime.utils.ObjectParser.getAsInt
import fr.shikkanime.utils.ObjectParser.getAsLong
Expand All @@ -23,6 +23,9 @@ import java.util.logging.Level

class AnimationDigitalNetworkPlatform :
AbstractPlatform<AnimationDigitalNetworkConfiguration, CountryCode, List<JsonObject>>() {
@Inject
private lateinit var configCacheService: ConfigCacheService

override fun getPlatform(): Platform = Platform.ANIM

override fun getConfigurationClass() = AnimationDigitalNetworkConfiguration::class.java
Expand All @@ -31,11 +34,24 @@ class AnimationDigitalNetworkPlatform :
return AnimationDigitalNetworkWrapper.getLatestVideos(zonedDateTime.toLocalDate())
}

private fun parseAPIContent(
bypassFileContent: File?,
countryCode: CountryCode,
zonedDateTime: ZonedDateTime
): List<JsonObject> {
return if (bypassFileContent != null && bypassFileContent.exists()) {
ObjectParser.fromJson(bypassFileContent.readText()).getAsJsonArray("videos").map { it.asJsonObject }
} else getApiContent(
countryCode,
zonedDateTime
)
}

override fun fetchEpisodes(zonedDateTime: ZonedDateTime, bypassFileContent: File?): List<Episode> {
val list = mutableListOf<Episode>()

configuration!!.availableCountries.forEach { countryCode ->
val api = getApiContent(countryCode, zonedDateTime)
val api = parseAPIContent(bypassFileContent, countryCode, zonedDateTime)

api.forEach {
try {
Expand Down Expand Up @@ -86,10 +102,10 @@ class AnimationDigitalNetworkPlatform :

val descriptionLowercase = animeDescription.lowercase()

isSimulcasted = isSimulcasted || descriptionLowercase.startsWith("(premier épisode ") ||
descriptionLowercase.startsWith("(diffusion des ") ||
descriptionLowercase.startsWith("(diffusion du premier épisode") ||
descriptionLowercase.startsWith("(diffusion de l'épisode 1 le")
isSimulcasted = isSimulcasted ||
configCacheService.getValueAsString(ConfigPropertyKey.ANIMATION_DITIGAL_NETWORK_SIMULCAST_DETECTION_REGEX)?.let {
Regex(it).containsMatchIn(descriptionLowercase)
} == true

if (!isSimulcasted) throw AnimeNotSimulcastedException("Anime is not simulcasted")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,22 +162,20 @@ class EpisodeRepository : AbstractRepository<Episode>() {
countryCode: CountryCode,
start: ZonedDateTime,
end: ZonedDateTime,
blacklisted: List<UUID>,
): List<Episode> {
return inTransaction { entityManager ->
createReadOnlyQuery(
entityManager,
"""
FROM Episode e
WHERE e.anime.countryCode = :countryCode AND e.releaseDateTime BETWEEN :start AND :end AND e.anime.uuid NOT IN :blacklisted
ORDER BY e.releaseDateTime ASC
FROM Episode e
WHERE e.anime.countryCode = :countryCode AND e.releaseDateTime BETWEEN :start AND :end
ORDER BY e.releaseDateTime ASC, LOWER(e.anime.name) ASC
""".trimIndent(),
getEntityClass()
)
.setParameter("countryCode", countryCode)
.setParameter("start", start)
.setParameter("end", end)
.setParameter("blacklisted", blacklisted)
.resultList
.initialize()
}
Expand Down
30 changes: 14 additions & 16 deletions src/main/kotlin/fr/shikkanime/services/AnimeService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,31 +51,29 @@ class AnimeService : AbstractService<Anime, AnimeRepository>() {
fun findAllUUIDAndImage() = animeRepository.findAllUUIDAndImage()

fun getWeeklyAnimes(startOfWeekDay: LocalDate, countryCode: CountryCode): List<WeeklyAnimesDto> {
return startOfWeekDay.datesUntil(startOfWeekDay.plusDays(7)).map {
val start = ZonedDateTime.parse("${it}T00:00:00Z")
val end = ZonedDateTime.parse("${it}T23:59:59Z")
val dateTitle =
it.format(DateTimeFormatter.ofPattern("EEEE", Locale.of(countryCode.locale.split("-")[0], countryCode.locale.split("-")[1]))).capitalizeWords()
val list = episodeService.findAllByDateRange(countryCode, start, end, emptyList()).toMutableList()

list.addAll(
episodeService.findAllByDateRange(
countryCode,
start.minusDays(7),
end.minusDays(7),
list.mapNotNull { anime -> anime.uuid })
)
val start = ZonedDateTime.parse("${startOfWeekDay.minusDays(7)}T00:00:00Z")
val end = ZonedDateTime.parse("${startOfWeekDay.plusDays(7)}T23:59:59Z")
val list = episodeService.findAllByDateRange(countryCode, start, end).toMutableList()

return startOfWeekDay.datesUntil(startOfWeekDay.plusDays(7)).map { date ->
val dateTitle = date.format(
DateTimeFormatter.ofPattern(
"EEEE",
Locale.of(countryCode.locale.split("-")[0], countryCode.locale.split("-")[1])
)
).capitalizeWords()
val episodes = list.filter { it.releaseDateTime.dayOfWeek == date.dayOfWeek }

WeeklyAnimesDto(
dateTitle,
AbstractConverter.convert(
list.distinctBy { episode -> episode.anime?.uuid },
episodes.distinctBy { episode -> episode.anime?.uuid },
EpisodeDto::class.java
).map { episodeDto ->
WeeklyAnimeDto(
episodeDto.anime,
episodeDto.releaseDateTime,
AbstractConverter.convert(list.filter { episode -> episode.anime?.uuid == episodeDto.anime.uuid }
AbstractConverter.convert(episodes.filter { episode -> episode.anime?.uuid == episodeDto.anime.uuid }
.map { episode -> episode.platform!! }
.distinct(), PlatformDto::class.java)
)
Expand Down
5 changes: 2 additions & 3 deletions src/main/kotlin/fr/shikkanime/services/EpisodeService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,8 @@ class EpisodeService : AbstractService<Episode, EpisodeRepository>() {
fun findAllByDateRange(
countryCode: CountryCode,
start: ZonedDateTime,
end: ZonedDateTime,
blacklisted: List<UUID>
) = episodeRepository.findAllByDateRange(countryCode, start, end, blacklisted)
end: ZonedDateTime
) = episodeRepository.findAllByDateRange(countryCode, start, end)

fun addImage(uuid: UUID, image: String, bypass: Boolean = false) {
ImageService.add(uuid, ImageService.Type.IMAGE, image, 640, 360, bypass)
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/assets/css/purged/bootstrap.min.css

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions src/main/resources/db/changelog/2024/03/06-changelog.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
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">
<property global="false" name="id" value="1711448390991"/>
<property global="false" name="author" value="Ziedelth"/>

<changeSet id="${id}-1" author="${author}" dbms="postgresql">
<preConditions onFail="MARK_RAN">
<sqlCheck expectedResult="0">SELECT COUNT(*)
FROM config
WHERE property_key = 'animation_digital_network_simulcast_detection_regex'</sqlCheck>
</preConditions>

<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)"/>
</insert>
</changeSet>
</databaseChangeLog>
1 change: 1 addition & 0 deletions src/main/resources/db/changelog/db.changelog-master.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@
<include file="/db/changelog/2024/03/03-changelog.xml"/>
<include file="/db/changelog/2024/03/04-changelog.xml"/>
<include file="/db/changelog/2024/03/05-changelog.xml"/>
<include file="/db/changelog/2024/03/06-changelog.xml"/>
</databaseChangeLog>
14 changes: 6 additions & 8 deletions src/main/resources/templates/site/calendar.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
class="img-fluid" width="640"
height="360">

<div class="position-absolute top-0 start-0 p-1">
<div class="position-absolute top-0 end-0 p-1">
<div class="d-flex">
<#list release.platforms as platform>
<img src="https://www.shikkanime.fr/assets/img/platforms/${platform.image}"
Expand All @@ -38,15 +38,13 @@
</#list>
</div>
</div>

<div class="position-absolute bottom-0 start-0 p-1 px-md-3 bg-black"
data-release-date-time="${release.releaseDateTime}">
</div>
</div>

<span class="h6 mt-1 mb-3 text-truncate-2">
${release.anime.shortName}
</span>
<div class="mt-1 mb-2">
<span class="h6 text-truncate-2 mb-0">${release.anime.shortName}</span>
<span class="text-muted mt-0"
data-release-date-time="${release.releaseDateTime}"></span>
</div>

<div class="bg-black bg-opacity-75 position-absolute top-0 start-0 w-100 h-100 mh-100 p-3"
x-show="hover">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,30 @@
package fr.shikkanime.platforms

import fr.shikkanime.entities.Config
import fr.shikkanime.entities.enums.ConfigPropertyKey
import fr.shikkanime.entities.enums.CountryCode
import fr.shikkanime.entities.enums.LangType
import fr.shikkanime.platforms.configuration.PlatformSimulcast
import fr.shikkanime.services.ConfigService
import fr.shikkanime.utils.Constant
import fr.shikkanime.utils.MapCache
import jakarta.inject.Inject
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertNotNull
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import java.io.File
import java.time.ZonedDateTime
import java.util.*

class AnimationDigitalNetworkPlatformTest {
@Inject
lateinit var platform: AnimationDigitalNetworkPlatform

@Inject
lateinit var configService: ConfigService

@BeforeEach
fun setUp() {
Constant.injector.injectMembers(this)
Expand All @@ -31,6 +39,8 @@ class AnimationDigitalNetworkPlatformTest {
platform.configuration!!.availableCountries.remove(CountryCode.FR)
platform.configuration!!.simulcasts.removeIf { it.name == "Pon no Michi" }
platform.reset()
configService.deleteAll()
MapCache.invalidate(Config::class.java)
}

@Test
Expand Down Expand Up @@ -117,4 +127,28 @@ class AnimationDigitalNetworkPlatformTest {
assertEquals("Urusei Yatsura", episodes[2].anime?.name)
assertNotNull(episodes[2].description)
}

@Test
fun `fetchEpisodes for 2024-04-10`() {
configService.save(
Config(
propertyKey = ConfigPropertyKey.ANIMATION_DITIGAL_NETWORK_SIMULCAST_DETECTION_REGEX.key,
propertyValue = "\\((premier épisode |diffusion des épisodes |diffusion du premier épisode|diffusion de l'épisode 1 le)"
)
)
MapCache.invalidate(Config::class.java)

val s = "2024-04-10T08:00:00Z"
val zonedDateTime = ZonedDateTime.parse(s)

val episodes = platform.fetchEpisodes(
zonedDateTime,
File(
ClassLoader.getSystemClassLoader().getResource("animation_digital_network/api-${s.replace(':', '-')}.json")?.file
?: throw Exception("File not found")
)
)

assertEquals(true, episodes.isEmpty())
}
}
Loading

0 comments on commit 206faf2

Please sign in to comment.