Push
This commit is contained in:
parent
fd468520d5
commit
fc29b57cbe
@ -79,6 +79,12 @@ dependencies {
|
||||
testImplementation(platform("org.junit:junit-bom:5.10.1"))
|
||||
testImplementation("org.junit.platform:junit-platform-runner:1.10.1")*/
|
||||
|
||||
testImplementation(platform("org.junit:junit-bom:5.9.1"))
|
||||
testImplementation("org.junit.jupiter:junit-jupiter")
|
||||
testImplementation("junit:junit:4.13.2")
|
||||
testImplementation("org.mockito:mockito-core:3.+")
|
||||
testImplementation("org.assertj:assertj-core:3.4.1")
|
||||
|
||||
}
|
||||
|
||||
tasks.withType<Test> {
|
||||
|
||||
@ -0,0 +1,24 @@
|
||||
package no.iktdev.mediaprocessing.shared.common.parsing
|
||||
|
||||
import no.iktdev.mediaprocessing.shared.kafka.dto.events_result.EpisodeInfo
|
||||
import org.assertj.core.api.Assertions
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.junit.jupiter.api.Assertions.*
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
class FileNameDeterminateTest {
|
||||
|
||||
@Test
|
||||
fun testThatCorrectNumberIsSelected() {
|
||||
val title = "Fancy Name Test 99"
|
||||
val baseName = "Fancy Name Test 99 - 01"
|
||||
val fnd = FileNameDeterminate(title, baseName, FileNameDeterminate.ContentType.UNDEFINED)
|
||||
val result = fnd.getDeterminedVideoInfo()
|
||||
assertNotNull(result)
|
||||
assertThat(result!!.type).isEqualTo("serie")
|
||||
assertThat(result).isInstanceOf(EpisodeInfo::class.java)
|
||||
val ei = result as EpisodeInfo
|
||||
assertThat(ei.episode).isEqualTo(1)
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,18 @@
|
||||
package no.iktdev.mediaprocessing.shared.common.parsing
|
||||
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.assertDoesNotThrow
|
||||
|
||||
|
||||
class FileNameParserTest {
|
||||
|
||||
@Test
|
||||
fun serieNameWithNumbers() {
|
||||
val name = "[TST] Fancy Name Test 99 - 01 [Nans][#00A8E6]"
|
||||
val parser = FileNameParser(name)
|
||||
val result = parser.guessDesiredTitle()
|
||||
assertThat(result).isEqualTo("Fancy Name Test 99")
|
||||
assertThat(parser.guessDesiredFileName()).isEqualTo("Fancy Name Test 99 - 01") }
|
||||
|
||||
}
|
||||
@ -6,26 +6,38 @@ import no.iktdev.exfl.coroutines.Coroutines
|
||||
import no.iktdev.mediaprocessing.shared.common.datasource.MySqlDataSource
|
||||
import no.iktdev.mediaprocessing.shared.common.persistance.processerEvents
|
||||
import no.iktdev.mediaprocessing.shared.common.socket.SocketImplementation
|
||||
import org.jetbrains.exposed.sql.transactions.TransactionManager
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication
|
||||
import org.springframework.boot.runApplication
|
||||
import org.springframework.scheduling.annotation.EnableScheduling
|
||||
import org.springframework.scheduling.annotation.Scheduled
|
||||
|
||||
private val logger = KotlinLogging.logger {}
|
||||
|
||||
@SpringBootApplication
|
||||
class ProcesserApplication {
|
||||
}
|
||||
|
||||
lateinit var dataSource: MySqlDataSource
|
||||
fun main(args: Array<String>) {
|
||||
val dataSource = MySqlDataSource.fromDatabaseEnv()
|
||||
Coroutines.default().launch {
|
||||
dataSource.createDatabase()
|
||||
dataSource.createTables(
|
||||
processerEvents
|
||||
)
|
||||
}
|
||||
dataSource = MySqlDataSource.fromDatabaseEnv()
|
||||
dataSource.createDatabase()
|
||||
dataSource.createTables(
|
||||
processerEvents
|
||||
)
|
||||
val context = runApplication<ProcesserApplication>(*args)
|
||||
}
|
||||
|
||||
class SocketImplemented: SocketImplementation() {
|
||||
|
||||
}
|
||||
@EnableScheduling
|
||||
class DatabaseReconnect() {
|
||||
var lostConnectionCount = 0
|
||||
@Scheduled(fixedDelay = (100_000))
|
||||
fun checkIfConnected() {
|
||||
if (TransactionManager.currentOrNull() == null) {
|
||||
lostConnectionCount++
|
||||
dataSource.toDatabase()
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -11,6 +11,9 @@ import org.jetbrains.exposed.sql.transactions.transaction
|
||||
|
||||
open class MySqlDataSource(databaseName: String, address: String, port: String = "", username: String, password: String): DataSource(databaseName = databaseName, address = address, port = port, username = username, password = password) {
|
||||
val log = KotlinLogging.logger {}
|
||||
var database: Database? = null
|
||||
private set
|
||||
|
||||
companion object {
|
||||
fun fromDatabaseEnv(): MySqlDataSource {
|
||||
if (DatabaseConfig.database.isNullOrBlank()) throw RuntimeException("Database name is not defined in 'DATABASE_NAME'")
|
||||
@ -50,7 +53,10 @@ open class MySqlDataSource(databaseName: String, address: String, port: String =
|
||||
}
|
||||
}
|
||||
|
||||
return if (ok) toDatabase() else null
|
||||
return if (ok) toDatabase() else {
|
||||
log.error { "No database to create or connect to" }
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
override fun createTables(vararg tables: Table) {
|
||||
@ -65,19 +71,21 @@ open class MySqlDataSource(databaseName: String, address: String, port: String =
|
||||
}
|
||||
|
||||
protected fun toDatabaseServerConnection(): Database {
|
||||
return Database.connect(
|
||||
database = Database.connect(
|
||||
toConnectionUrl(),
|
||||
user = username,
|
||||
password = password
|
||||
)
|
||||
return database!!
|
||||
}
|
||||
|
||||
fun toDatabase(): Database {
|
||||
return Database.connect(
|
||||
database = Database.connect(
|
||||
"${toConnectionUrl()}/$databaseName",
|
||||
user = username,
|
||||
password = password
|
||||
)
|
||||
return database!!
|
||||
}
|
||||
|
||||
override fun toConnectionUrl(): String {
|
||||
|
||||
@ -137,8 +137,13 @@ class FileNameDeterminate(val title: String, val sanitizedName: String, val ctyp
|
||||
|
||||
fun findEpisodeNumber(): String? {
|
||||
val regex = Regex("\\b(\\d+)\\b")
|
||||
val matchResult = regex.find(sanitizedName)
|
||||
return matchResult?.value?.trim()
|
||||
val matchResult = regex.findAll(sanitizedName)
|
||||
val usabeNumber = if (matchResult.toList().size > 1) {
|
||||
Regex("[-_] \\b(\\d+)\\b").find(sanitizedName)?.groups?.lastOrNull()?.value
|
||||
} else {
|
||||
matchResult.lastOrNull()?.value
|
||||
}
|
||||
return usabeNumber?.trim()
|
||||
}
|
||||
|
||||
fun findEpisodeTitle(): String? {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user