Skip to content

Commit

Permalink
Merge pull request #434 from Shikkanime/dev
Browse files Browse the repository at this point in the history
Remove duplicate lang types and delete some data
  • Loading branch information
Ziedelth authored May 3, 2024
2 parents 7538e46 + a47e0da commit a432a50
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 7 deletions.
30 changes: 30 additions & 0 deletions src/main/kotlin/fr/shikkanime/Application.kt
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
package fr.shikkanime

import fr.shikkanime.entities.enums.EpisodeType
import fr.shikkanime.jobs.*
import fr.shikkanime.modules.configureHTTP
import fr.shikkanime.modules.configureRouting
import fr.shikkanime.modules.configureSecurity
import fr.shikkanime.services.AnimeService
import fr.shikkanime.services.EpisodeMappingService
import fr.shikkanime.services.ImageService
import fr.shikkanime.services.MemberService
import fr.shikkanime.utils.Constant
import fr.shikkanime.utils.JobManager
import fr.shikkanime.utils.LoggerFactory
import fr.shikkanime.utils.StringUtils
import io.ktor.server.application.*
import io.ktor.server.engine.*
import io.ktor.server.netty.*
Expand All @@ -24,8 +27,11 @@ fun main() {

fun initAll(adminPassword: AtomicReference<String>?, port: Int = 37100, wait: Boolean = true): NettyApplicationEngine {
val animeService = Constant.injector.getInstance(AnimeService::class.java)
val episodeMappingService = Constant.injector.getInstance(EpisodeMappingService::class.java)
animeService.preIndex()

updateAndDeleteData(episodeMappingService, animeService)

ImageService.loadCache()
ImageService.addAll()

Expand Down Expand Up @@ -64,6 +70,30 @@ fun initAll(adminPassword: AtomicReference<String>?, port: Int = 37100, wait: Bo
).start(wait = wait)
}

private fun updateAndDeleteData(episodeMappingService: EpisodeMappingService, animeService: AnimeService) {
episodeMappingService.findAllByEpisodeType(EpisodeType.FILM).forEach {
episodeMappingService.delete(it)
}

animeService.findAll().forEach {
val mappings = episodeMappingService.findAllByAnime(it)

if (mappings.isEmpty()) {
logger.info("Deleting anime ${StringUtils.getShortName(it.name!!)} because it has no episodes")
animeService.delete(it)
return@forEach
}

it.status = StringUtils.getStatus(it)
animeService.update(it)
}

episodeMappingService.findAll().forEach {
it.status = StringUtils.getStatus(it)
episodeMappingService.update(it)
}
}

fun Application.module() {
configureSecurity()
configureHTTP()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class AnimeToAnimeDtoConverter : AbstractConverter<Anime, AnimeDto>() {
SimulcastDto::class.java
)?.toList(),
audioLocales = audioLocales,
langTypes = audioLocales.map { LangType.fromAudioLocale(from.countryCode, it) }.sorted(),
langTypes = audioLocales.map { LangType.fromAudioLocale(from.countryCode, it) }.distinct().sorted(),
status = from.status,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ class EpisodeMappingToEpisodeMappingDtoConverter : AbstractConverter<EpisodeMapp
platforms = convert(
variants.mapNotNull { it.platform }.sortedBy { it.name }.toSet(),
PlatformDto::class.java
),
)?.toList(),
langTypes = variants.map { LangType.fromAudioLocale(from.anime!!.countryCode!!, it.audioLocale!!) }
.sorted()
.toSet(),
.distinct()
.sorted(),
status = from.status
)
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/fr/shikkanime/dtos/EpisodeMappingDto.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ data class EpisodeMappingDto(
val description: String?,
val image: String,
val variants: List<EpisodeVariantWithoutMappingDto>?,
val platforms: Set<PlatformDto>? = null,
val langTypes: Set<LangType>? = null,
val platforms: List<PlatformDto>? = null,
val langTypes: List<LangType>? = null,
val status: Status,
)
3 changes: 2 additions & 1 deletion src/main/kotlin/fr/shikkanime/jobs/FetchOldEpisodesJob.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import fr.shikkanime.entities.EpisodeVariant
import fr.shikkanime.entities.Simulcast
import fr.shikkanime.entities.enums.ConfigPropertyKey
import fr.shikkanime.entities.enums.CountryCode
import fr.shikkanime.entities.enums.EpisodeType
import fr.shikkanime.platforms.AbstractPlatform
import fr.shikkanime.platforms.AnimationDigitalNetworkPlatform
import fr.shikkanime.platforms.CrunchyrollPlatform
Expand Down Expand Up @@ -81,7 +82,7 @@ class FetchOldEpisodesJob : AbstractJob {
episodes.addAll(fetchAnimationDigitalNetwork(CountryCode.FR, dates))
episodes.addAll(fetchCrunchyroll(CountryCode.FR, simulcasts))

episodes.removeIf { it.releaseDateTime.toLocalDate() !in dates }
episodes.removeIf { it.releaseDateTime.toLocalDate() !in dates || it.episodeType == EpisodeType.FILM }

val limit = configCacheService.getValueAsInt(ConfigPropertyKey.FETCH_OLD_EPISODES_LIMIT, 5)
episodes.groupBy { it.anime + it.releaseDateTime.toLocalDate().toString() }.forEach { (_, animeDayEpisodes) ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,19 @@ class EpisodeMappingRepository : AbstractRepository<EpisodeMapping>() {
}
}

fun findAllByEpisodeType(episodeType: EpisodeType): List<EpisodeMapping> {
return inTransaction {
val cb = it.criteriaBuilder
val query = cb.createQuery(getEntityClass())
val root = query.from(getEntityClass())

query.where(cb.equal(root[EpisodeMapping_.episodeType], episodeType))

it.createQuery(query)
.resultList
}
}

fun findByAnimeEpisodeTypeSeasonNumber(
anime: Anime,
episodeType: EpisodeType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ class EpisodeMappingService : AbstractService<EpisodeMapping, EpisodeMappingRepo

fun findAllByAnime(anime: Anime) = episodeMappingRepository.findAllByAnime(anime)

fun findAllByEpisodeType(episodeType: EpisodeType) = episodeMappingRepository.findAllByEpisodeType(episodeType)

fun findLastNumber(anime: Anime, episodeType: EpisodeType, season: Int, platform: Platform, audioLocale: String) =
episodeMappingRepository.findLastNumber(anime, episodeType, season, platform, audioLocale)

Expand Down
1 change: 1 addition & 0 deletions src/main/kotlin/fr/shikkanime/utils/StringUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ object StringUtils {
episodeMapping.anime!!.countryCode!!,
languageCacheService
) ||
episodeMapping.title.isNullOrBlank() ||
episodeMapping.image == Constant.DEFAULT_IMAGE_PREVIEW
) Status.INVALID else Status.VALID
}
Expand Down

0 comments on commit a432a50

Please sign in to comment.