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.RunnerManager
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.content.GenreTable
import no.iktdev.streamit.library.db.tables.content.MovieTable
import no.iktdev.streamit.library.db.tables.content.ProgressTable
import no.iktdev.streamit.library.db.tables.content.SerieTable
import no.iktdev.streamit.library.db.tables.content.SubtitleTable
import no.iktdev.streamit.library.db.tables.content.SummaryTable
import no.iktdev.streamit.library.db.tables.content.TitleTable
import no.iktdev.streamit.library.db.tables.other.CastErrorTable
import no.iktdev.streamit.library.db.tables.other.DataAudioTable
import no.iktdev.streamit.library.db.tables.other.DataVideoTable
import no.iktdev.streamit.library.db.tables.user.UserTable
import no.iktdev.streamit.library.db.tables.catalog
import no.iktdev.streamit.library.db.tables.genre
import no.iktdev.streamit.library.db.tables.helper.data_audio
import no.iktdev.streamit.library.db.tables.helper.data_video
import no.iktdev.streamit.library.db.tables.movie
import no.iktdev.streamit.library.db.tables.serie
import no.iktdev.streamit.library.db.tables.subtitle
import no.iktdev.streamit.library.db.tables.summary
import no.iktdev.streamit.library.db.tables.titles
import no.iktdev.streamit.library.db.tables.users
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
import org.springframework.context.annotation.Bean
@ -109,18 +108,16 @@ fun main(args: Array<String>) {
val tables = arrayOf(
CatalogTable,
GenreTable,
MovieTable,
SerieTable,
SubtitleTable,
SummaryTable,
UserTable,
ProgressTable,
DataAudioTable,
DataVideoTable,
CastErrorTable,
TitleTable
catalog,
genre,
movie,
serie,
subtitle,
summary,
users,
data_audio,
data_video,
titles
)
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.streamit.library.db.executeWithStatus
import no.iktdev.streamit.library.db.insertWithSuccess
import no.iktdev.streamit.library.db.tables.content.CatalogTable
import no.iktdev.streamit.library.db.tables.content.MovieTable
import no.iktdev.streamit.library.db.tables.content.SerieTable
import no.iktdev.streamit.library.db.query.MovieQuery
import no.iktdev.streamit.library.db.tables.catalog
import no.iktdev.streamit.library.db.tables.serie
import org.jetbrains.exposed.sql.*
object ContentCatalogStore {
@ -20,56 +20,56 @@ object ContentCatalogStore {
*/
fun getCollectionByTitleAndType(type: String, titles: List<String>): String? {
return withTransaction(getStoreDatabase()) {
CatalogTable.selectAll().where {
(CatalogTable.type eq type) and
((CatalogTable.title inList titles) or
(CatalogTable.collection inList titles))
catalog.select {
(catalog.type eq type) and
((catalog.title inList titles) or
(catalog.collection inList titles))
}.map {
it[CatalogTable.collection]
it[catalog.collection]
}.firstOrNull()
}
}
private fun getCover(collection: String, type: String): String? {
return withTransaction(getStoreDatabase()) {
CatalogTable.selectAll().where {
(CatalogTable.collection eq collection) and
(CatalogTable.type eq type)
}.map { it[CatalogTable.cover] }.firstOrNull()
catalog.select {
(catalog.collection eq collection) and
(catalog.type eq type)
}.map { it[catalog.cover] }.firstOrNull()
}
}
fun storeCatalog(title: String, titles: List<String>, collection: String, type: String, cover: String?, genres: String?): Int? {
val status = executeWithStatus(getStoreDatabase().database, run = {
val existingRow = CatalogTable.selectAll().where {
(CatalogTable.collection eq collection) and
(CatalogTable.type eq type)
val status = executeWithStatus(getStoreDatabase().database, block = {
val existingRow = catalog.select {
(catalog.collection eq collection) and
(catalog.type eq type)
}.firstOrNull()
if (existingRow == null) {
log.info { "$collection does not exist, and will be created" }
CatalogTable.insert {
it[CatalogTable.title] = title
it[CatalogTable.cover] = cover
it[CatalogTable.type] = type
it[CatalogTable.collection] = collection
it[CatalogTable.genres] = genres
catalog.insert {
it[catalog.title] = title
it[catalog.cover] = cover
it[catalog.type] = type
it[catalog.collection] = collection
it[catalog.genres] = genres
}
} else {
val id = existingRow[CatalogTable.id]
val storedTitle = existingRow[CatalogTable.title]
val useCover = existingRow[CatalogTable.cover] ?: cover
val useGenres = existingRow[CatalogTable.genres] ?: genres
val id = existingRow[catalog.id]
val storedTitle = existingRow[catalog.title]
val useCover = existingRow[catalog.cover] ?: cover
val useGenres = existingRow[catalog.genres] ?: genres
CatalogTable.update({
(CatalogTable.id eq id) and
(CatalogTable.collection eq collection)
catalog.update({
(catalog.id eq id) and
(catalog.collection eq collection)
}) {
it[CatalogTable.cover] = useCover
it[CatalogTable.genres] = useGenres
it[catalog.cover] = useCover
it[catalog.genres] = useGenres
}
}
}, onError = {
}, {
log.error { "Failed to store catalog $collection: ${it.message}" }
})
if (status) {
@ -81,17 +81,17 @@ object ContentCatalogStore {
}
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!" }
return
}
val status = executeWithStatus(getStoreDatabase().database, run = {
CatalogTable.update({
(CatalogTable.id eq catalogId)
val status = executeWithStatus(getStoreDatabase().database, block = {
catalog.update({
(catalog.id eq catalogId)
}) {
it[CatalogTable.iid] = iid
it[catalog.iid] = iid
}
}, onError = {
}, {
log.error { "Failed to store movie ${videoDetails.fileName}: ${it.message}" }
})
if (status) {
@ -107,28 +107,28 @@ object ContentCatalogStore {
log.error { "serieInfo in videoDetails is null!" }
return
}
val status = insertWithSuccess(getStoreDatabase().database, run = {
SerieTable.insert {
val status = insertWithSuccess(getStoreDatabase().database, block = {
serie.insert {
it[title] = serieInfo.episodeTitle
it[episode] = serieInfo.episodeNumber
it[season] = serieInfo.seasonNumber
it[video] = videoDetails.fileName
it[SerieTable.collection] = collection
it[serie.collection] = collection
}
}, onError = {
log.error { "Failed to store serie ${videoDetails.fileName}: ${it.message}" }
})
if (!status) {
log.error { "Failed to insert ${videoDetails.fileName} with episode: ${serieInfo.episodeNumber} and season ${serieInfo.seasonNumber}" }
val finalStatus = insertWithSuccess(getStoreDatabase().database, run = {
SerieTable.insert {
val finalStatus = insertWithSuccess(getStoreDatabase().database, block = {
serie.insert {
it[title] = serieInfo.episodeTitle
it[episode] = serieInfo.episodeNumber
it[season] = 0
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) {
log.error { "Failed to insert ${videoDetails.fileName} with fallback season 0" }
} else {
@ -157,12 +157,12 @@ object ContentCatalogStore {
private fun getId(title: String, titles: List<String>, collection: String, type: String): Int? {
val ids = withTransaction(getStoreDatabase().database) {
CatalogTable.selectAll().where {
((CatalogTable.title eq title)
or (CatalogTable.collection eq collection)
or (CatalogTable.title inList titles)) and
(CatalogTable.type eq type)
}.map { it[CatalogTable.id].value }
catalog.select {
((catalog.title eq title)
or (catalog.collection eq collection)
or (catalog.title inList titles)) and
(catalog.type eq type)
}.map { it[catalog.id].value }
} ?: run {
log.warn { "No values found on $title with type $type" }
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.mediaprocessing.coordinator.getStoreDatabase
import no.iktdev.streamit.library.db.tables.content.GenreTable
import org.jetbrains.exposed.sql.insertIgnoreAndGetId
import no.iktdev.streamit.library.db.query.GenreQuery
object ContentGenresStore {
fun storeAndGetIds(genres: List<String>): String? {
return try {
withTransaction(getStoreDatabase()) {
val receivedGenreIdMap = genres.associateWith { genreName ->
GenreTable.insertIgnoreAndGetId { it[GenreTable.genre] = genreName }?.value
}
receivedGenreIdMap.values.filterNotNull()
.joinToString(",")
val gq = GenreQuery( *genres.toTypedArray() )
gq.insertAndGetIds()
gq.getIds().joinToString(",")
}
} catch (e: Exception) {
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.shared.common.contract.reader.SummaryInfo
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 {
fun storeSummary(catalogId: Int, summaryInfo: SummaryInfo) {
val result = executeOrException(getStoreDatabase().database, run = {
SummaryTable.insertIgnore(
catalogId = catalogId,
val result = executeOrException(getStoreDatabase().database, block = {
SummaryQuery(
cid = catalogId,
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 no.iktdev.mediaprocessing.coordinator.getStoreDatabase
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 java.io.File
@ -11,8 +12,8 @@ object ContentSubtitleStore {
val log = KotlinLogging.logger {}
fun storeSubtitles(collection: String, destinationFile: File): Boolean {
return executeWithStatus (getStoreDatabase().database, run = {
SubtitleTable.insert {
return executeWithStatus (getStoreDatabase().database, block = {
subtitle.insert {
it[this.associatedWithVideo] = destinationFile.nameWithoutExtension
it[this.language] = destinationFile.parentFile.nameWithoutExtension
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.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 org.jetbrains.exposed.sql.insertIgnore
import org.jetbrains.exposed.sql.or
import org.jetbrains.exposed.sql.select
import org.jetbrains.exposed.sql.selectAll
object ContentTitleStore {
fun store(mainTitle: String, otherTitles: List<String>) {
try {
withTransaction(getStoreDatabase().database, run = {
withTransaction(getStoreDatabase().database, block = {
val titlesToUse = otherTitles + listOf(
NameHelper.normalize(mainTitle)
).filter { it != mainTitle }
titlesToUse.forEach { t ->
TitleTable.insertIgnore {
titles.insertIgnore {
it[masterTitle] = mainTitle
it[alternativeTitle] = t
}
}
}, {
})
} catch (e: Exception) {
e.printStackTrace()
@ -31,13 +32,15 @@ object ContentTitleStore {
}
fun findMasterTitles(titleList: List<String>): List<String> {
return withTransaction(getStoreDatabase().database, run = {
TitleTable.selectAll().where {
(TitleTable.alternativeTitle inList titleList) or
(TitleTable.masterTitle inList titleList)
return withTransaction(getStoreDatabase().database, block = {
titles.select {
(titles.alternativeTitle inList titleList) or
(titles.masterTitle inList titleList)
}.map {
it[TitleTable.masterTitle]
it[titles.masterTitle]
}.distinctBy { it }
}, {
}) ?: emptyList()
}
}

View File

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