Skip to content

Commit

Permalink
Update implementation and refactor Crunchyroll logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Ziedelth committed Dec 14, 2023
1 parent 6497fb2 commit 020b716
Show file tree
Hide file tree
Showing 61 changed files with 4,299 additions and 592 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ out/
/metrics.json
/.jpb/
/config/
/images-cache.shikk
8 changes: 7 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ dependencies {
implementation("io.ktor:ktor-server-compression-jvm:$ktor_version")
implementation("io.ktor:ktor-server-cors-jvm:$ktor_version")
implementation("io.ktor:ktor-server-content-negotiation-jvm:$ktor_version")
implementation("io.ktor:ktor-serialization-gson:$ktor_version")
implementation("io.ktor:ktor-serialization-jackson:$ktor_version")
implementation("io.ktor:ktor-server-freemarker-jvm:$ktor_version")
implementation("io.ktor:ktor-server-netty-jvm:$ktor_version")
implementation("io.ktor:ktor-client-core:$ktor_version")
Expand All @@ -42,6 +42,12 @@ dependencies {
implementation("org.liquibase:liquibase-core:4.25.0")
implementation("org.quartz-scheduler:quartz:2.5.0-rc1")
implementation("com.google.guava:guava:32.1.3-jre")
implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.16.0")
implementation("com.microsoft.playwright:playwright:1.40.0")
implementation("org.jsoup:jsoup:1.17.1")
implementation("com.google.code.gson:gson:2.10.1")
implementation("org.openpnp:opencv:4.7.0-0")
testImplementation("io.ktor:ktor-server-tests-jvm:$ktor_version")
testImplementation("org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version")
testImplementation("com.h2database:h2:2.2.224")
}
2 changes: 1 addition & 1 deletion hibernate.cfg.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<property name="connection.url">jdbc:postgresql://localhost:5432/shikkanime</property>
<property name="connection.username">postgres</property>
<property name="connection.password">mysecretpassword</property>
<property name="show_sql">true</property>
<property name="show_sql">false</property>
<property name="hibernate.current_session_context_class">org.hibernate.context.internal.ThreadLocalSessionContext</property>
</session-factory>
</hibernate-configuration>
5 changes: 5 additions & 0 deletions src/main/kotlin/fr/shikkanime/Application.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,23 @@ package fr.shikkanime
import fr.shikkanime.jobs.FetchEpisodesJob
import fr.shikkanime.jobs.GCJob
import fr.shikkanime.jobs.MetricJob
import fr.shikkanime.jobs.SavingImageCacheJob
import fr.shikkanime.plugins.configureHTTP
import fr.shikkanime.plugins.configureRouting
import fr.shikkanime.plugins.configureSecurity
import fr.shikkanime.services.ImageService
import fr.shikkanime.utils.JobManager
import io.ktor.server.application.*
import io.ktor.server.engine.*
import io.ktor.server.netty.*

fun main() {
ImageService.loadCache()

JobManager.scheduleJob("*/10 * * * * ?", MetricJob::class.java)
JobManager.scheduleJob("0 */5 * * * ?", GCJob::class.java)
JobManager.scheduleJob("0 * * * * ?", FetchEpisodesJob::class.java)
JobManager.scheduleJob("0 */5 * * * ?", SavingImageCacheJob::class.java)
JobManager.start()

embeddedServer(
Expand Down
26 changes: 26 additions & 0 deletions src/main/kotlin/fr/shikkanime/caches/CountryCodeAnimeIdKeyCache.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package fr.shikkanime.caches

import fr.shikkanime.entities.enums.CountryCode

data class CountryCodeAnimeIdKeyCache(
val countryCode: CountryCode,
val animeId: String,
) {
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false

other as CountryCodeAnimeIdKeyCache

if (countryCode != other.countryCode) return false
if (animeId != other.animeId) return false

return true
}

override fun hashCode(): Int {
var result = countryCode.hashCode()
result = 31 * result + animeId.hashCode()
return result
}
}
6 changes: 4 additions & 2 deletions src/main/kotlin/fr/shikkanime/controllers/AdminController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ class AdminController {
return TemplateResponse(
"admin/platforms.ftl",
"Platforms",
mutableMapOf("platforms" to Constant.abstractPlatforms)
mutableMapOf(
"platforms" to Constant.abstractPlatforms.toList().sortedBy { it.getPlatform().name.lowercase() })
)
}

Expand All @@ -34,7 +35,8 @@ class AdminController {
val redirectResponse = RedirectResponse("/admin/platforms")

val platformName = parameters["platform"] ?: return redirectResponse
val abstractPlatform = Constant.abstractPlatforms.find { it.getPlatform().name == platformName } ?: return redirectResponse
val abstractPlatform =
Constant.abstractPlatforms.find { it.getPlatform().name == platformName } ?: return redirectResponse
abstractPlatform.configuration?.of(parameters)
abstractPlatform.saveConfiguration()
return redirectResponse
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ abstract class AbstractConverter<F, T> {
return try {
method.invoke(abstractConverter, `object`) as T
} catch (e: Exception) {
throw IllegalStateException("Can not convert \"${`object`.javaClass.simpleName}\" to \"${to.simpleName}\"", e)
throw IllegalStateException(
"Can not convert \"${`object`.javaClass.simpleName}\" to \"${to.simpleName}\"",
e
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ class MetricToMetricDtoConverter : AbstractConverter<Metric, MetricDto>() {
return MetricDto(
uuid = from.uuid,
cpuLoad = (from.cpuLoad * 100).toString().replace(',', '.'),
averageCpuLoad = metricService.getAverageCpuLoad(minusHours, from.date)?.times(100)?.toString()?.replace(',', '.') ?: "0",
averageCpuLoad = metricService.getAverageCpuLoad(minusHours, from.date)?.times(100)?.toString()
?.replace(',', '.') ?: "0",
memoryUsage = (from.memoryUsage / 1024.0 / 1024.0).toString().replace(',', '.'),
averageMemoryUsage = metricService.getAverageMemoryUsage(minusHours, from.date)?.div(1024)?.div(1024)?.toString()?.replace(',', '.') ?: "0",
averageMemoryUsage = metricService.getAverageMemoryUsage(minusHours, from.date)?.div(1024)?.div(1024)
?.toString()?.replace(',', '.') ?: "0",
databaseSize = (from.databaseSize / 1024.0 / 1024.0).toDoublePoint(),
date = from.date.withZoneSameInstant(europeParisZone).format(dateFormatter)
)
Expand Down

This file was deleted.

This file was deleted.

11 changes: 0 additions & 11 deletions src/main/kotlin/fr/shikkanime/dtos/PlatformDto.kt

This file was deleted.

10 changes: 6 additions & 4 deletions src/main/kotlin/fr/shikkanime/entities/Anime.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package fr.shikkanime.entities

import fr.shikkanime.entities.enums.CountryCode
import jakarta.persistence.*
import java.time.ZonedDateTime
import java.util.*
Expand All @@ -8,14 +9,15 @@ import java.util.*
@Table(name = "anime")
data class Anime(
override val uuid: UUID? = null,
@ManyToOne(optional = false, fetch = FetchType.LAZY)
val country: Country? = null,
@Column(nullable = false, name = "country_code")
@Enumerated(EnumType.STRING)
val countryCode: CountryCode? = null,
@Column(nullable = false)
val name: String? = null,
@Column(nullable = false, name = "release_date")
val releaseDate: ZonedDateTime = ZonedDateTime.now(),
@Column(nullable = false)
@Column(nullable = false, columnDefinition = "VARCHAR(1000)")
var image: String? = null,
@Column(nullable = true, columnDefinition = "TEXT")
@Column(nullable = true, columnDefinition = "VARCHAR(1000)")
var description: String? = null,
) : ShikkEntity(uuid)
16 changes: 0 additions & 16 deletions src/main/kotlin/fr/shikkanime/entities/Country.kt

This file was deleted.

12 changes: 7 additions & 5 deletions src/main/kotlin/fr/shikkanime/entities/Episode.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package fr.shikkanime.entities

import fr.shikkanime.entities.enums.EpisodeType
import fr.shikkanime.entities.enums.LangType
import fr.shikkanime.entities.enums.Platform
import jakarta.persistence.*
import java.time.ZonedDateTime
import java.util.*
Expand All @@ -10,7 +11,8 @@ import java.util.*
@Table(name = "episode")
data class Episode(
override val uuid: UUID? = null,
@ManyToOne(optional = false, fetch = FetchType.LAZY)
@Column(nullable = false)
@Enumerated(EnumType.STRING)
var platform: Platform? = null,
@ManyToOne(optional = false, fetch = FetchType.LAZY)
var anime: Anime? = null,
Expand All @@ -20,19 +22,19 @@ data class Episode(
@Column(nullable = false, name = "lang_type")
@Enumerated(EnumType.STRING)
val langType: LangType? = null,
@Column(nullable = false)
@Column(nullable = false, unique = true)
val hash: String? = null,
@Column(nullable = false, name = "release_date")
val releaseDate: ZonedDateTime = ZonedDateTime.now(),
@Column(nullable = false)
var season: Int? = null,
@Column(nullable = false)
var number: Int? = null,
@Column(nullable = true, columnDefinition = "TEXT")
@Column(nullable = true, columnDefinition = "VARCHAR(1000)")
var title: String? = null,
@Column(nullable = false, columnDefinition = "TEXT")
@Column(nullable = false, columnDefinition = "VARCHAR(1000)")
var url: String? = null,
@Column(nullable = false, columnDefinition = "TEXT")
@Column(nullable = false, columnDefinition = "VARCHAR(1000)")
var image: String? = null,
@Column(nullable = false)
var duration: Long = -1
Expand Down
18 changes: 0 additions & 18 deletions src/main/kotlin/fr/shikkanime/entities/Platform.kt

This file was deleted.

13 changes: 13 additions & 0 deletions src/main/kotlin/fr/shikkanime/entities/enums/CountryCode.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package fr.shikkanime.entities.enums


enum class CountryCode(val locale: String? = null, val voice: String? = null) {
FR("fr-FR", "VF"),
;

companion object {
fun from(collection: Collection<String>): Set<CountryCode> {
return collection.map { valueOf(it.uppercase()) }.toSet()
}
}
}
12 changes: 12 additions & 0 deletions src/main/kotlin/fr/shikkanime/entities/enums/Platform.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package fr.shikkanime.entities.enums

enum class Platform(
val platformName: String,
var url: String,
var image: String
) {
ANIM("Animation Digital Network", "https://animationdigitalnetwork.fr/", "animation_digital_network.png"),
CRUN("Crunchyroll", "https://www.crunchyroll.com/", "crunchyroll.png"),
DISN("Disney+", "https://www.disneyplus.com/", "disneyplus.png"),
;
}
3 changes: 3 additions & 0 deletions src/main/kotlin/fr/shikkanime/exceptions/AnimeException.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package fr.shikkanime.exceptions

open class AnimeException(override val message: String? = null) : Exception(message)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package fr.shikkanime.exceptions

data class AnimeNotSimulcastedException(override val message: String? = null) : AnimeException(message)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package fr.shikkanime.exceptions

data class EpisodeAlreadyReleasedException(override val message: String? = null) : EpisodeException(message)
3 changes: 3 additions & 0 deletions src/main/kotlin/fr/shikkanime/exceptions/EpisodeException.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package fr.shikkanime.exceptions

open class EpisodeException(override val message: String? = null) : Exception(message)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package fr.shikkanime.exceptions

data class EpisodeNoSubtitlesOrVoiceException(override val message: String? = null) : EpisodeException(message)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package fr.shikkanime.exceptions

data class EpisodeNotAvailableInCountryException(override val message: String? = null) : EpisodeException(message)
Loading

0 comments on commit 020b716

Please sign in to comment.