Downgraded stremait lib to alpha14 - inner code

This commit is contained in:
Brage Skjønborg 2025-10-19 04:14:00 +02:00
parent b5ae862812
commit ef9aeb1dd2
7 changed files with 109 additions and 110 deletions

View File

@ -11,18 +11,17 @@ import no.iktdev.eventi.database.MySqlDataSource
import no.iktdev.mediaprocessing.shared.common.database.cal.EventsManager import no.iktdev.mediaprocessing.shared.common.database.cal.EventsManager
import no.iktdev.mediaprocessing.shared.common.database.cal.RunnerManager import no.iktdev.mediaprocessing.shared.common.database.cal.RunnerManager
import no.iktdev.mediaprocessing.shared.common.database.cal.TasksManager import no.iktdev.mediaprocessing.shared.common.database.cal.TasksManager
import no.iktdev.streamit.library.db.tables.content.CatalogTable import no.iktdev.streamit.library.db.tables.catalog
import no.iktdev.streamit.library.db.tables.content.GenreTable import no.iktdev.streamit.library.db.tables.genre
import no.iktdev.streamit.library.db.tables.content.MovieTable import no.iktdev.streamit.library.db.tables.helper.data_audio
import no.iktdev.streamit.library.db.tables.content.ProgressTable import no.iktdev.streamit.library.db.tables.helper.data_video
import no.iktdev.streamit.library.db.tables.content.SerieTable import no.iktdev.streamit.library.db.tables.movie
import no.iktdev.streamit.library.db.tables.content.SubtitleTable import no.iktdev.streamit.library.db.tables.serie
import no.iktdev.streamit.library.db.tables.content.SummaryTable import no.iktdev.streamit.library.db.tables.subtitle
import no.iktdev.streamit.library.db.tables.content.TitleTable import no.iktdev.streamit.library.db.tables.summary
import no.iktdev.streamit.library.db.tables.other.CastErrorTable import no.iktdev.streamit.library.db.tables.titles
import no.iktdev.streamit.library.db.tables.other.DataAudioTable import no.iktdev.streamit.library.db.tables.users
import no.iktdev.streamit.library.db.tables.other.DataVideoTable
import no.iktdev.streamit.library.db.tables.user.UserTable
import org.springframework.boot.autoconfigure.SpringBootApplication import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication import org.springframework.boot.runApplication
import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Bean
@ -109,18 +108,16 @@ fun main(args: Array<String>) {
val tables = arrayOf( val tables = arrayOf(
CatalogTable, catalog,
GenreTable, genre,
MovieTable, movie,
SerieTable, serie,
SubtitleTable, subtitle,
SummaryTable, summary,
UserTable, users,
ProgressTable, data_audio,
DataAudioTable, data_video,
DataVideoTable, titles
CastErrorTable,
TitleTable
) )
storeDatabase.createTables(*tables) storeDatabase.createTables(*tables)

View File

@ -6,9 +6,9 @@ import no.iktdev.mediaprocessing.coordinator.getStoreDatabase
import no.iktdev.mediaprocessing.shared.common.contract.reader.VideoDetails import no.iktdev.mediaprocessing.shared.common.contract.reader.VideoDetails
import no.iktdev.streamit.library.db.executeWithStatus import no.iktdev.streamit.library.db.executeWithStatus
import no.iktdev.streamit.library.db.insertWithSuccess import no.iktdev.streamit.library.db.insertWithSuccess
import no.iktdev.streamit.library.db.tables.content.CatalogTable import no.iktdev.streamit.library.db.query.MovieQuery
import no.iktdev.streamit.library.db.tables.content.MovieTable import no.iktdev.streamit.library.db.tables.catalog
import no.iktdev.streamit.library.db.tables.content.SerieTable import no.iktdev.streamit.library.db.tables.serie
import org.jetbrains.exposed.sql.* import org.jetbrains.exposed.sql.*
object ContentCatalogStore { object ContentCatalogStore {
@ -20,56 +20,56 @@ object ContentCatalogStore {
*/ */
fun getCollectionByTitleAndType(type: String, titles: List<String>): String? { fun getCollectionByTitleAndType(type: String, titles: List<String>): String? {
return withTransaction(getStoreDatabase()) { return withTransaction(getStoreDatabase()) {
CatalogTable.selectAll().where { catalog.select {
(CatalogTable.type eq type) and (catalog.type eq type) and
((CatalogTable.title inList titles) or ((catalog.title inList titles) or
(CatalogTable.collection inList titles)) (catalog.collection inList titles))
}.map { }.map {
it[CatalogTable.collection] it[catalog.collection]
}.firstOrNull() }.firstOrNull()
} }
} }
private fun getCover(collection: String, type: String): String? { private fun getCover(collection: String, type: String): String? {
return withTransaction(getStoreDatabase()) { return withTransaction(getStoreDatabase()) {
CatalogTable.selectAll().where { catalog.select {
(CatalogTable.collection eq collection) and (catalog.collection eq collection) and
(CatalogTable.type eq type) (catalog.type eq type)
}.map { it[CatalogTable.cover] }.firstOrNull() }.map { it[catalog.cover] }.firstOrNull()
} }
} }
fun storeCatalog(title: String, titles: List<String>, collection: String, type: String, cover: String?, genres: String?): Int? { fun storeCatalog(title: String, titles: List<String>, collection: String, type: String, cover: String?, genres: String?): Int? {
val status = executeWithStatus(getStoreDatabase().database, run = { val status = executeWithStatus(getStoreDatabase().database, block = {
val existingRow = CatalogTable.selectAll().where { val existingRow = catalog.select {
(CatalogTable.collection eq collection) and (catalog.collection eq collection) and
(CatalogTable.type eq type) (catalog.type eq type)
}.firstOrNull() }.firstOrNull()
if (existingRow == null) { if (existingRow == null) {
log.info { "$collection does not exist, and will be created" } log.info { "$collection does not exist, and will be created" }
CatalogTable.insert { catalog.insert {
it[CatalogTable.title] = title it[catalog.title] = title
it[CatalogTable.cover] = cover it[catalog.cover] = cover
it[CatalogTable.type] = type it[catalog.type] = type
it[CatalogTable.collection] = collection it[catalog.collection] = collection
it[CatalogTable.genres] = genres it[catalog.genres] = genres
} }
} else { } else {
val id = existingRow[CatalogTable.id] val id = existingRow[catalog.id]
val storedTitle = existingRow[CatalogTable.title] val storedTitle = existingRow[catalog.title]
val useCover = existingRow[CatalogTable.cover] ?: cover val useCover = existingRow[catalog.cover] ?: cover
val useGenres = existingRow[CatalogTable.genres] ?: genres val useGenres = existingRow[catalog.genres] ?: genres
CatalogTable.update({ catalog.update({
(CatalogTable.id eq id) and (catalog.id eq id) and
(CatalogTable.collection eq collection) (catalog.collection eq collection)
}) { }) {
it[CatalogTable.cover] = useCover it[catalog.cover] = useCover
it[CatalogTable.genres] = useGenres it[catalog.genres] = useGenres
} }
} }
}, onError = { }, {
log.error { "Failed to store catalog $collection: ${it.message}" } log.error { "Failed to store catalog $collection: ${it.message}" }
}) })
if (status) { if (status) {
@ -81,17 +81,17 @@ object ContentCatalogStore {
} }
private fun storeMovie(catalogId: Int, videoDetails: VideoDetails) { private fun storeMovie(catalogId: Int, videoDetails: VideoDetails) {
val iid = MovieTable.insertAndGetId(videoDetails.fileName)?.value ?: run { val iid = MovieQuery(videoDetails.fileName).insertAndGetId() ?: run {
log.error { "Movie id was not returned!" } log.error { "Movie id was not returned!" }
return return
} }
val status = executeWithStatus(getStoreDatabase().database, run = { val status = executeWithStatus(getStoreDatabase().database, block = {
CatalogTable.update({ catalog.update({
(CatalogTable.id eq catalogId) (catalog.id eq catalogId)
}) { }) {
it[CatalogTable.iid] = iid it[catalog.iid] = iid
} }
}, onError = { }, {
log.error { "Failed to store movie ${videoDetails.fileName}: ${it.message}" } log.error { "Failed to store movie ${videoDetails.fileName}: ${it.message}" }
}) })
if (status) { if (status) {
@ -107,28 +107,28 @@ object ContentCatalogStore {
log.error { "serieInfo in videoDetails is null!" } log.error { "serieInfo in videoDetails is null!" }
return return
} }
val status = insertWithSuccess(getStoreDatabase().database, run = { val status = insertWithSuccess(getStoreDatabase().database, block = {
SerieTable.insert { serie.insert {
it[title] = serieInfo.episodeTitle it[title] = serieInfo.episodeTitle
it[episode] = serieInfo.episodeNumber it[episode] = serieInfo.episodeNumber
it[season] = serieInfo.seasonNumber it[season] = serieInfo.seasonNumber
it[video] = videoDetails.fileName it[video] = videoDetails.fileName
it[SerieTable.collection] = collection it[serie.collection] = collection
} }
}, onError = { }, onError = {
log.error { "Failed to store serie ${videoDetails.fileName}: ${it.message}" } log.error { "Failed to store serie ${videoDetails.fileName}: ${it.message}" }
}) })
if (!status) { if (!status) {
log.error { "Failed to insert ${videoDetails.fileName} with episode: ${serieInfo.episodeNumber} and season ${serieInfo.seasonNumber}" } log.error { "Failed to insert ${videoDetails.fileName} with episode: ${serieInfo.episodeNumber} and season ${serieInfo.seasonNumber}" }
val finalStatus = insertWithSuccess(getStoreDatabase().database, run = { val finalStatus = insertWithSuccess(getStoreDatabase().database, block = {
SerieTable.insert { serie.insert {
it[title] = serieInfo.episodeTitle it[title] = serieInfo.episodeTitle
it[episode] = serieInfo.episodeNumber it[episode] = serieInfo.episodeNumber
it[season] = 0 it[season] = 0
it[video] = videoDetails.fileName it[video] = videoDetails.fileName
it[SerieTable.collection] = collection it[serie.collection] = collection
} }
}, onError = { log.error { "Failed to store serie: ${it.message}" } }) }, { log.error { "Failed to store serie: ${it.message}" } })
if (!finalStatus) { if (!finalStatus) {
log.error { "Failed to insert ${videoDetails.fileName} with fallback season 0" } log.error { "Failed to insert ${videoDetails.fileName} with fallback season 0" }
} else { } else {
@ -157,12 +157,12 @@ object ContentCatalogStore {
private fun getId(title: String, titles: List<String>, collection: String, type: String): Int? { private fun getId(title: String, titles: List<String>, collection: String, type: String): Int? {
val ids = withTransaction(getStoreDatabase().database) { val ids = withTransaction(getStoreDatabase().database) {
CatalogTable.selectAll().where { catalog.select {
((CatalogTable.title eq title) ((catalog.title eq title)
or (CatalogTable.collection eq collection) or (catalog.collection eq collection)
or (CatalogTable.title inList titles)) and or (catalog.title inList titles)) and
(CatalogTable.type eq type) (catalog.type eq type)
}.map { it[CatalogTable.id].value } }.map { it[catalog.id].value }
} ?: run { } ?: run {
log.warn { "No values found on $title with type $type" } log.warn { "No values found on $title with type $type" }
return null return null

View File

@ -2,18 +2,15 @@ package no.iktdev.mediaprocessing.coordinator.tasksV2.mapping.store
import no.iktdev.eventi.database.withTransaction import no.iktdev.eventi.database.withTransaction
import no.iktdev.mediaprocessing.coordinator.getStoreDatabase import no.iktdev.mediaprocessing.coordinator.getStoreDatabase
import no.iktdev.streamit.library.db.tables.content.GenreTable import no.iktdev.streamit.library.db.query.GenreQuery
import org.jetbrains.exposed.sql.insertIgnoreAndGetId
object ContentGenresStore { object ContentGenresStore {
fun storeAndGetIds(genres: List<String>): String? { fun storeAndGetIds(genres: List<String>): String? {
return try { return try {
withTransaction(getStoreDatabase()) { withTransaction(getStoreDatabase()) {
val receivedGenreIdMap = genres.associateWith { genreName -> val gq = GenreQuery( *genres.toTypedArray() )
GenreTable.insertIgnoreAndGetId { it[GenreTable.genre] = genreName }?.value gq.insertAndGetIds()
} gq.getIds().joinToString(",")
receivedGenreIdMap.values.filterNotNull()
.joinToString(",")
} }
} catch (e: Exception) { } catch (e: Exception) {
e.printStackTrace() e.printStackTrace()

View File

@ -3,17 +3,17 @@ package no.iktdev.mediaprocessing.coordinator.tasksV2.mapping.store
import no.iktdev.mediaprocessing.coordinator.getStoreDatabase import no.iktdev.mediaprocessing.coordinator.getStoreDatabase
import no.iktdev.mediaprocessing.shared.common.contract.reader.SummaryInfo import no.iktdev.mediaprocessing.shared.common.contract.reader.SummaryInfo
import no.iktdev.streamit.library.db.executeOrException import no.iktdev.streamit.library.db.executeOrException
import no.iktdev.streamit.library.db.tables.content.SummaryTable import no.iktdev.streamit.library.db.query.SummaryQuery
object ContentMetadataStore { object ContentMetadataStore {
fun storeSummary(catalogId: Int, summaryInfo: SummaryInfo) { fun storeSummary(catalogId: Int, summaryInfo: SummaryInfo) {
val result = executeOrException(getStoreDatabase().database, run = { val result = executeOrException(getStoreDatabase().database, block = {
SummaryTable.insertIgnore( SummaryQuery(
catalogId = catalogId, cid = catalogId,
language = summaryInfo.language, language = summaryInfo.language,
content = summaryInfo.summary description = summaryInfo.summary
) ).insert()
}) })
} }
} }

View File

@ -3,7 +3,8 @@ package no.iktdev.mediaprocessing.coordinator.tasksV2.mapping.store
import mu.KotlinLogging import mu.KotlinLogging
import no.iktdev.mediaprocessing.coordinator.getStoreDatabase import no.iktdev.mediaprocessing.coordinator.getStoreDatabase
import no.iktdev.streamit.library.db.executeWithStatus import no.iktdev.streamit.library.db.executeWithStatus
import no.iktdev.streamit.library.db.tables.content.SubtitleTable import no.iktdev.streamit.library.db.query.SubtitleQuery
import no.iktdev.streamit.library.db.tables.subtitle
import org.jetbrains.exposed.sql.insert import org.jetbrains.exposed.sql.insert
import java.io.File import java.io.File
@ -11,8 +12,8 @@ object ContentSubtitleStore {
val log = KotlinLogging.logger {} val log = KotlinLogging.logger {}
fun storeSubtitles(collection: String, destinationFile: File): Boolean { fun storeSubtitles(collection: String, destinationFile: File): Boolean {
return executeWithStatus (getStoreDatabase().database, run = { return executeWithStatus (getStoreDatabase().database, block = {
SubtitleTable.insert { subtitle.insert {
it[this.associatedWithVideo] = destinationFile.nameWithoutExtension it[this.associatedWithVideo] = destinationFile.nameWithoutExtension
it[this.language] = destinationFile.parentFile.nameWithoutExtension it[this.language] = destinationFile.parentFile.nameWithoutExtension
it[this.collection] = collection it[this.collection] = collection

View File

@ -2,28 +2,29 @@ package no.iktdev.mediaprocessing.coordinator.tasksV2.mapping.store
import no.iktdev.mediaprocessing.coordinator.getStoreDatabase import no.iktdev.mediaprocessing.coordinator.getStoreDatabase
import no.iktdev.mediaprocessing.shared.common.parsing.NameHelper import no.iktdev.mediaprocessing.shared.common.parsing.NameHelper
import no.iktdev.streamit.library.db.tables.content.TitleTable import no.iktdev.streamit.library.db.tables.titles
import no.iktdev.streamit.library.db.withTransaction import no.iktdev.streamit.library.db.withTransaction
import org.jetbrains.exposed.sql.insertIgnore import org.jetbrains.exposed.sql.insertIgnore
import org.jetbrains.exposed.sql.or import org.jetbrains.exposed.sql.or
import org.jetbrains.exposed.sql.select import org.jetbrains.exposed.sql.select
import org.jetbrains.exposed.sql.selectAll
object ContentTitleStore { object ContentTitleStore {
fun store(mainTitle: String, otherTitles: List<String>) { fun store(mainTitle: String, otherTitles: List<String>) {
try { try {
withTransaction(getStoreDatabase().database, run = { withTransaction(getStoreDatabase().database, block = {
val titlesToUse = otherTitles + listOf( val titlesToUse = otherTitles + listOf(
NameHelper.normalize(mainTitle) NameHelper.normalize(mainTitle)
).filter { it != mainTitle } ).filter { it != mainTitle }
titlesToUse.forEach { t -> titlesToUse.forEach { t ->
TitleTable.insertIgnore { titles.insertIgnore {
it[masterTitle] = mainTitle it[masterTitle] = mainTitle
it[alternativeTitle] = t it[alternativeTitle] = t
} }
} }
}, {
}) })
} catch (e: Exception) { } catch (e: Exception) {
e.printStackTrace() e.printStackTrace()
@ -31,13 +32,15 @@ object ContentTitleStore {
} }
fun findMasterTitles(titleList: List<String>): List<String> { fun findMasterTitles(titleList: List<String>): List<String> {
return withTransaction(getStoreDatabase().database, run = { return withTransaction(getStoreDatabase().database, block = {
TitleTable.selectAll().where { titles.select {
(TitleTable.alternativeTitle inList titleList) or (titles.alternativeTitle inList titleList) or
(TitleTable.masterTitle inList titleList) (titles.masterTitle inList titleList)
}.map { }.map {
it[TitleTable.masterTitle] it[titles.masterTitle]
}.distinctBy { it } }.distinctBy { it }
}, {
}) ?: emptyList() }) ?: emptyList()
} }
} }

View File

@ -18,15 +18,16 @@ object ProcessedFileStore {
val checksum = getChecksum(inputFilePath) val checksum = getChecksum(inputFilePath)
withTransaction(eventDatabase.database.database, run = { withTransaction(eventDatabase.database.database, block = {
filesProcessed.insert { filesProcessed.insert {
it[this.title] = title it[this.title] = title
it[this.inputFile] = inputFilePath it[this.inputFile] = inputFilePath
it[this.data] = Gson().toJson(summary) it[this.data] = Gson().toJson(summary)
it[this.checksum] = checksum it[this.checksum] = checksum
} }
}, onError = { }) {
it.printStackTrace() it.printStackTrace()
}) }
} }
} }