Skip to content

Commit

Permalink
Merge pull request #384 from Shikkanime/dev
Browse files Browse the repository at this point in the history
Delete old episode system
  • Loading branch information
Ziedelth authored Apr 18, 2024
2 parents 062e5a2 + 26e6345 commit 81cb603
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 156 deletions.
11 changes: 3 additions & 8 deletions src/main/kotlin/fr/shikkanime/Application.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import fr.shikkanime.jobs.*
import fr.shikkanime.modules.configureHTTP
import fr.shikkanime.modules.configureRouting
import fr.shikkanime.modules.configureSecurity
import fr.shikkanime.services.*
import fr.shikkanime.services.AnimeService
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
Expand All @@ -22,15 +24,8 @@ fun main() {

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

episodeService.findAll().sortedWith(compareBy({ it.releaseDateTime }, { it.image!!.contains("nc/", true) })).forEach {
// Convert to platform episode
episodeMappingService.save(it)
}

ImageService.loadCache()
ImageService.addAll()

Expand Down
66 changes: 0 additions & 66 deletions src/main/kotlin/fr/shikkanime/entities/Episode.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ class AnimationDigitalNetworkPlatform :

private fun getAudioLocale(it: JsonElement): String {
return when (it.asString) {
"vostf" -> "fr-FR"
"vf" -> "ja-JP"
"vostf" -> "ja-JP"
"vf" -> "fr-FR"
else -> throw Exception("Language is null")
}
}
Expand Down

This file was deleted.

79 changes: 21 additions & 58 deletions src/main/kotlin/fr/shikkanime/services/EpisodeMappingService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ package fr.shikkanime.services
import com.google.inject.Inject
import fr.shikkanime.dtos.EpisodeMappingDto
import fr.shikkanime.dtos.enums.Status
import fr.shikkanime.entities.*
import fr.shikkanime.entities.Anime
import fr.shikkanime.entities.EpisodeMapping
import fr.shikkanime.entities.EpisodeVariant
import fr.shikkanime.entities.SortParameter
import fr.shikkanime.entities.enums.CountryCode
import fr.shikkanime.entities.enums.EpisodeType
import fr.shikkanime.entities.enums.Platform
Expand Down Expand Up @@ -52,62 +55,6 @@ class EpisodeMappingService : AbstractService<EpisodeMapping, EpisodeMappingRepo
return save
}

fun save(entity: Episode): EpisodeMapping {
val episodeMapping = findByAnimeEpisodeTypeSeasonNumber(
entity.anime!!,
entity.episodeType!!,
entity.season!!,
entity.number!!
) ?: createEpisodeMapping(entity)

val audioLocale = (if (entity.platform == Platform.CRUN) entity.audioLocale else null) ?: "ja-JP"
val id = ".{2}-.{4}-(.*)-.*".toRegex().find(entity.hash!!)!!.groupValues[1]
val uncensored = entity.image!!.contains("nc/", true)
val identifier = StringUtils.getIdentifier(entity.anime!!.countryCode!!, entity.platform!!, id, audioLocale, uncensored)

if (episodeMapping.variants.none { it.identifier == identifier }) {
episodeVariantRepository.save(getVariant(episodeMapping, entity, audioLocale, identifier, uncensored))
episodeMapping.lastReleaseDateTime = entity.releaseDateTime
episodeMappingRepository.update(episodeMapping)
}

return episodeMapping
}

private fun createEpisodeMapping(entity: Episode) = episodeMappingRepository.save(
EpisodeMapping(
anime = entity.anime!!,
releaseDateTime = entity.releaseDateTime,
lastReleaseDateTime = entity.releaseDateTime,
lastUpdateDateTime = entity.releaseDateTime,
episodeType = entity.episodeType!!,
season = entity.season!!,
number = entity.number!!,
duration = entity.duration,
title = entity.title,
description = entity.description,
image = entity.image,
).apply {
status = StringUtils.getStatus(this)
}
)

private fun getVariant(
episodeMapping: EpisodeMapping,
entity: Episode,
audioLocale: String,
identifier: String,
uncensored: Boolean,
) = EpisodeVariant(
mapping = episodeMapping,
releaseDateTime = entity.releaseDateTime,
platform = entity.platform,
audioLocale = audioLocale,
identifier = identifier,
url = entity.url,
uncensored = uncensored,
)

fun update(uuid: UUID, entity: EpisodeMappingDto): EpisodeMapping? {
val episode = find(uuid) ?: return null

Expand Down Expand Up @@ -178,7 +125,23 @@ class EpisodeMappingService : AbstractService<EpisodeMapping, EpisodeMappingRepo

episode.status = StringUtils.getStatus(episode)
episode.lastUpdateDateTime = ZonedDateTime.now()
val update = super.update(episode)
var update = super.update(episode)

if (!entity.variants.isNullOrEmpty()) {
val oldList = mutableSetOf(*episode.variants.toTypedArray())
episode.variants.clear()

entity.variants.forEach { variantDto ->
val variant = episodeVariantRepository.find(variantDto.uuid) ?: return@forEach
episode.variants.add(variant)
oldList.removeIf { it.uuid == variantDto.uuid }
}

oldList.forEach { episodeVariantRepository.delete(it) }
MapCache.invalidate(EpisodeVariant::class.java)
update = find(uuid)!!
}

MapCache.invalidate(EpisodeMapping::class.java)
return update
}
Expand Down
14 changes: 0 additions & 14 deletions src/main/kotlin/fr/shikkanime/services/EpisodeService.kt

This file was deleted.

18 changes: 18 additions & 0 deletions src/main/resources/db/changelog/2024/04/07-changelog.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?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.27.xsd"
objectQuotingStrategy="QUOTE_ONLY_RESERVED_WORDS">
<property global="false" name="id" value="1713474260621"/>
<property global="false" name="author" value="Ziedelth"/>

<changeSet id="${id}-1" author="${author}">
<preConditions onFail="MARK_RAN">
<tableExists tableName="episode"/>
</preConditions>

<dropTable tableName="episode"/>
</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 @@ -45,4 +45,5 @@
<include file="/db/changelog/2024/04/04-changelog.xml"/>
<include file="/db/changelog/2024/04/05-changelog.xml"/>
<include file="/db/changelog/2024/04/06-changelog.xml"/>
<include file="/db/changelog/2024/04/07-changelog.xml"/>
</databaseChangeLog>
6 changes: 6 additions & 0 deletions src/main/resources/templates/admin/episodes/edit.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,12 @@
<hr>
<template x-for="variant in episode.variants" :id="variant.uuid">
<div class="row g-3 mt-3">
<div class="col-md-auto">
<button type="button" class="btn btn-outline-danger"
@click="episode.variants.splice(episode.variants.indexOf(variant), 1)">
-
</button>
</div>
<div class="col-md-auto">
<label for="variantReleaseDateTime" class="form-label">Release date time</label>
<input type="datetime-local" class="form-control" id="variantReleaseDateTime" name="variantReleaseDateTime"
Expand Down

0 comments on commit 81cb603

Please sign in to comment.