From e4e972f36beaf01360ef51c24c701558daab51d9 Mon Sep 17 00:00:00 2001 From: bskjon Date: Mon, 24 Feb 2025 02:12:54 +0100 Subject: [PATCH] Multiple checks --- .../tasksV2/listeners/CompletedTaskListener.kt | 2 ++ .../tasksV2/mapping/store/ContentCatalogStore.kt | 16 +++++++++------- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/apps/coordinator/src/main/kotlin/no/iktdev/mediaprocessing/coordinator/tasksV2/listeners/CompletedTaskListener.kt b/apps/coordinator/src/main/kotlin/no/iktdev/mediaprocessing/coordinator/tasksV2/listeners/CompletedTaskListener.kt index eff430e2..fb4de14b 100644 --- a/apps/coordinator/src/main/kotlin/no/iktdev/mediaprocessing/coordinator/tasksV2/listeners/CompletedTaskListener.kt +++ b/apps/coordinator/src/main/kotlin/no/iktdev/mediaprocessing/coordinator/tasksV2/listeners/CompletedTaskListener.kt @@ -154,6 +154,7 @@ class CompletedTaskListener : CoordinatorEventListener() { completedData.metadataStored.let { meta -> val catalogId = ContentCatalogStore.storeCatalog( title = meta.title, + titles = mediaInfo.titles, collection = meta.collection, type = meta.type, cover = meta.cover, @@ -172,6 +173,7 @@ class CompletedTaskListener : CoordinatorEventListener() { if (videoInfo != null) { ContentCatalogStore.storeMedia( title = completedData.metadataStored.title, + titles = mediaInfo.titles, collection = completedData.metadataStored.collection, type = completedData.metadataStored.type, videoDetails = videoInfo diff --git a/apps/coordinator/src/main/kotlin/no/iktdev/mediaprocessing/coordinator/tasksV2/mapping/store/ContentCatalogStore.kt b/apps/coordinator/src/main/kotlin/no/iktdev/mediaprocessing/coordinator/tasksV2/mapping/store/ContentCatalogStore.kt index c5bb0899..a2a985d0 100644 --- a/apps/coordinator/src/main/kotlin/no/iktdev/mediaprocessing/coordinator/tasksV2/mapping/store/ContentCatalogStore.kt +++ b/apps/coordinator/src/main/kotlin/no/iktdev/mediaprocessing/coordinator/tasksV2/mapping/store/ContentCatalogStore.kt @@ -39,7 +39,7 @@ object ContentCatalogStore { } } - fun storeCatalog(title: String, collection: String, type: String, cover: String?, genres: String?): Int? { + fun storeCatalog(title: String, titles: List, collection: String, type: String, cover: String?, genres: String?): Int? { val status = executeWithStatus(getStoreDatabase().database, block = { val existingRow = catalog.select { (catalog.collection eq collection) and @@ -77,7 +77,7 @@ object ContentCatalogStore { } else { log.error { "Unable to store catalog $collection..." } } - return getId(title, type) + return getId(title, titles, collection, type) } private fun storeMovie(catalogId: Int, videoDetails: VideoDetails) { @@ -139,8 +139,8 @@ object ContentCatalogStore { } } - fun storeMedia(title: String, collection: String, type: String, videoDetails: VideoDetails) { - val catalogId = getId(title, type) ?: run { + fun storeMedia(title: String, titles: List, collection: String, type: String, videoDetails: VideoDetails) { + val catalogId = getId(title, titles, collection, type) ?: run { log.warn { "Could not find id for $title with type $type" } return } @@ -155,11 +155,13 @@ object ContentCatalogStore { } } - private fun getId(title: String, type: String): Int? { + private fun getId(title: String, titles: List, collection: String, type: String): Int? { val ids = withTransaction(getStoreDatabase().database) { catalog.select { - (catalog.title eq title) - .and(catalog.type eq type) + ((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" }