Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #240

Merged
merged 3 commits into from
Mar 4, 2024
Merged

Dev #240

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/global_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ jobs:
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
run: ./gradlew sonar --info -Dsonar.pullrequest.key=${{ github.event.pull_request.number }} -Dsonar.pullrequest.branch=${{ github.event.pull_request.head.ref }} -Dsonar.pullrequest.base=${{ github.event.pull_request.base.ref }} -Dsonar.qualitygate.wait=true

- name: Test
if: github.event_name == 'pull_request' && github.event.pull_request.base.ref == 'master'
run: ./gradlew clean test --info

- name: Cache gradle dependencies
uses: actions/cache@v4
# If author is dependabot, we don't cache dependencies
Expand Down
2 changes: 2 additions & 0 deletions src/main/kotlin/fr/shikkanime/Application.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ fun initAll(adminPassword: AtomicReference<String>?, port: Int = 37100, wait: Bo
JobManager.scheduleJob("*/10 * * * * ?", MetricJob::class.java)
// Every minute
JobManager.scheduleJob("0 * * * * ?", FetchEpisodesJob::class.java)
// Every 10 minutes
JobManager.scheduleJob("0 */10 * * * ?", GarbageCollectorJob::class.java)
// Every hour
JobManager.scheduleJob("0 0 * * * ?", SavingImageCacheJob::class.java)
JobManager.scheduleJob("0 0 * * * ?", FetchDeprecatedEpisodeJob::class.java)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import fr.shikkanime.platforms.configuration.NetflixConfiguration

data class CountryCodeNetflixSimulcastKeyCache(
val countryCode: CountryCode,
val netflixSimulcast: NetflixConfiguration.NetflixSimulcast
val netflixSimulcast: NetflixConfiguration.NetflixSimulcastDay
) {
override fun equals(other: Any?): Boolean {
if (this === other) return true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ class FetchDeprecatedEpisodeJob : AbstractJob {
if (image != episode.image) {
episode.image = image
ImageService.remove(episode.uuid!!, ImageService.Type.IMAGE)
episodeService.addImage(episode.uuid, image)
needUpdate = true
}

Expand Down Expand Up @@ -179,7 +180,7 @@ class FetchDeprecatedEpisodeJob : AbstractJob {
title = title?.replace("\n", "")
title = title?.replace("\r", "")
title = title?.trim()
return title
return title.takeIf { !it.isNullOrBlank() }
}

fun normalizeDescription(platform: Platform, content: JsonObject): String? {
Expand All @@ -191,7 +192,7 @@ class FetchDeprecatedEpisodeJob : AbstractJob {
description = description?.replace("\n", "")
description = description?.replace("\r", "")
description = description?.trim()
return description
return description.takeIf { !it.isNullOrBlank() }
}

fun normalizeImage(platform: Platform, content: JsonObject): String {
Expand Down
7 changes: 7 additions & 0 deletions src/main/kotlin/fr/shikkanime/jobs/GarbageCollectorJob.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package fr.shikkanime.jobs

class GarbageCollectorJob : AbstractJob {
override fun run() {
System.gc()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,19 @@ package fr.shikkanime.platforms.configuration

import io.ktor.http.*

class NetflixConfiguration : PlatformConfiguration<NetflixConfiguration.NetflixSimulcast>() {
data class NetflixSimulcast(
var releaseDay: Int = 1,
var image: String = "",
var releaseTime: String = "",
class NetflixConfiguration : PlatformConfiguration<NetflixConfiguration.NetflixSimulcastDay>() {
data class NetflixSimulcastDay(
override var releaseDay: Int = 1,
override var image: String = "",
override var releaseTime: String = "",
var season: Int = 1,
) : PlatformSimulcast() {
) : ReleaseDayPlatformSimulcast(releaseDay, image, releaseTime) {
override fun of(parameters: Parameters) {
super.of(parameters)
parameters["releaseDay"]?.let { releaseDay = it.toInt() }
parameters["image"]?.let { image = it }
parameters["releaseTime"]?.let { releaseTime = it }
parameters["season"]?.let { season = it.toInt() }
}

override fun toConfigurationFields() = super.toConfigurationFields().apply {
add(
ConfigurationField(
label = "Release day",
caption = "1 = Monday, 2 = Tuesday, 3 = Wednesday, 4 = Thursday, 5 = Friday, 6 = Saturday, 7 = Sunday",
name = "releaseDay",
type = "number",
value = releaseDay
),
)
add(
ConfigurationField(
label = "Image",
name = "image",
type = "text",
value = image
),
)
add(
ConfigurationField(
label = "Release time",
caption = "Format: HH:mm:ss (In UTC)",
name = "releaseTime",
type = "time",
value = releaseTime
),
)
add(
ConfigurationField(
label = "Season",
Expand All @@ -55,5 +26,5 @@ class NetflixConfiguration : PlatformConfiguration<NetflixConfiguration.NetflixS
}
}

override fun newPlatformSimulcast() = NetflixSimulcast()
override fun newPlatformSimulcast() = NetflixSimulcastDay()
}
Original file line number Diff line number Diff line change
@@ -1,49 +1,11 @@
package fr.shikkanime.platforms.configuration

import io.ktor.http.*

class PrimeVideoConfiguration : PlatformConfiguration<PrimeVideoConfiguration.PrimeVideoSimulcast>() {
data class PrimeVideoSimulcast(
var releaseDay: Int = 1,
var image: String = "",
var releaseTime: String = "",
) : PlatformSimulcast() {
override fun of(parameters: Parameters) {
super.of(parameters)
parameters["releaseDay"]?.let { releaseDay = it.toInt() }
parameters["image"]?.let { image = it }
parameters["releaseTime"]?.let { releaseTime = it }
}

override fun toConfigurationFields() = super.toConfigurationFields().apply {
add(
ConfigurationField(
label = "Release day",
caption = "1 = Monday, 2 = Tuesday, 3 = Wednesday, 4 = Thursday, 5 = Friday, 6 = Saturday, 7 = Sunday",
name = "releaseDay",
type = "number",
value = releaseDay
),
)
add(
ConfigurationField(
label = "Image",
name = "image",
type = "text",
value = image
),
)
add(
ConfigurationField(
label = "Release time",
caption = "Format: HH:mm:ss (In UTC)",
name = "releaseTime",
type = "time",
value = releaseTime
),
)
}
}
override var releaseDay: Int = 1,
override var image: String = "",
override var releaseTime: String = "",
) : ReleaseDayPlatformSimulcast(releaseDay, image, releaseTime)

override fun newPlatformSimulcast() = PrimeVideoSimulcast()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package fr.shikkanime.platforms.configuration

import io.ktor.http.*

open class ReleaseDayPlatformSimulcast(
@Transient
open var releaseDay: Int,
@Transient
open var image: String,
@Transient
open var releaseTime: String,
) : PlatformSimulcast() {
override fun of(parameters: Parameters) {
super.of(parameters)
parameters["releaseDay"]?.let { releaseDay = it.toInt() }
parameters["image"]?.let { image = it }
parameters["releaseTime"]?.let { releaseTime = it }
}

override fun toConfigurationFields() = super.toConfigurationFields().apply {
add(
ConfigurationField(
label = "Release day",
caption = "1 = Monday, 2 = Tuesday, 3 = Wednesday, 4 = Thursday, 5 = Friday, 6 = Saturday, 7 = Sunday",
name = "releaseDay",
type = "number",
value = releaseDay
),
)
add(
ConfigurationField(
label = "Image",
name = "image",
type = "text",
value = image
),
)
add(
ConfigurationField(
label = "Release time",
caption = "Format: HH:mm:ss (In UTC)",
name = "releaseTime",
type = "time",
value = releaseTime
),
)
}
}
4 changes: 2 additions & 2 deletions src/main/kotlin/fr/shikkanime/utils/JobManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ object JobManager {
scheduler.start()
}

fun stop() {
scheduler.shutdown()
fun invalidate() {
scheduler.clear()
}

class JobExecutor : Job {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package fr.shikkanime.controllers.admin
import com.google.inject.Inject
import com.microsoft.playwright.Playwright
import fr.shikkanime.entities.enums.Link
import fr.shikkanime.entities.enums.Platform
import fr.shikkanime.initAll
import fr.shikkanime.services.MemberService
import fr.shikkanime.utils.Constant
Expand Down Expand Up @@ -42,7 +43,7 @@ class AdminControllerTest {

Constant.injector.injectMembers(this)
server = initAll(password, port, false)
JobManager.stop()
JobManager.invalidate()
}

@AfterEach
Expand All @@ -52,7 +53,7 @@ class AdminControllerTest {
}

@Test
fun `test admin login`() {
fun `test admin login and all links`() {
val playwright = Playwright.create()
val browser = playwright.chromium().launch()
val page = browser.newPage()
Expand Down Expand Up @@ -80,4 +81,61 @@ class AdminControllerTest {
browser.close()
playwright.close()
}

@Test
fun `create netflix simulcast`() {
val playwright = Playwright.create()
val browser = playwright.chromium().launch()
val page = browser.newPage()

page.navigate("http://localhost:$port/admin")
assertEquals("Login - Shikkanime", page.title())
page.fill("input[name=username]", "admin")
page.fill("input[name=password]", password.get())
page.click("button[type=submit]")

page.navigate("http://localhost:$port${Link.PLATFORMS.href}")
page.click("button[data-bs-target='#collapse${Platform.NETF.name}']")
page.click("a[href='${Link.PLATFORMS.href}/${Platform.NETF.name}/simulcasts']")

page.fill("input[name=name]", "81564899")
page.fill("input[name=releaseDay]", "4")
page.fill("input[name=image]", "https://cdn.myanimelist.net/images/anime/1938/140374.jpg")
page.fill("input[name=releaseTime]", "13:30")
page.fill("input[name=season]", "2")

page.click("button[type=submit]")

page.close()
browser.close()
playwright.close()
}

@Test
fun `create prime video simulcast`() {
val playwright = Playwright.create()
val browser = playwright.chromium().launch()
val page = browser.newPage()

page.navigate("http://localhost:$port/admin")
assertEquals("Login - Shikkanime", page.title())
page.fill("input[name=username]", "admin")
page.fill("input[name=password]", password.get())
page.click("button[type=submit]")

page.navigate("http://localhost:$port${Link.PLATFORMS.href}")
page.click("button[data-bs-target='#collapse${Platform.PRIM.name}']")
page.click("a[href='${Link.PLATFORMS.href}/${Platform.PRIM.name}/simulcasts']")

page.fill("input[name=name]", "0QN9ZXJ935YBTNK8U9FV5OAX5B")
page.fill("input[name=releaseDay]", "1")
page.fill("input[name=image]", "https://cdn.myanimelist.net/images/anime/1142/141351.jpg")
page.fill("input[name=releaseTime]", "17:01")

page.click("button[type=submit]")

page.close()
browser.close()
playwright.close()
}
}
Loading