Multiple checks

This commit is contained in:
bskjon 2025-02-24 02:12:54 +01:00
parent db333920a1
commit e4e972f36b
2 changed files with 11 additions and 7 deletions

View File

@ -154,6 +154,7 @@ class CompletedTaskListener : CoordinatorEventListener() {
completedData.metadataStored.let { meta -> completedData.metadataStored.let { meta ->
val catalogId = ContentCatalogStore.storeCatalog( val catalogId = ContentCatalogStore.storeCatalog(
title = meta.title, title = meta.title,
titles = mediaInfo.titles,
collection = meta.collection, collection = meta.collection,
type = meta.type, type = meta.type,
cover = meta.cover, cover = meta.cover,
@ -172,6 +173,7 @@ class CompletedTaskListener : CoordinatorEventListener() {
if (videoInfo != null) { if (videoInfo != null) {
ContentCatalogStore.storeMedia( ContentCatalogStore.storeMedia(
title = completedData.metadataStored.title, title = completedData.metadataStored.title,
titles = mediaInfo.titles,
collection = completedData.metadataStored.collection, collection = completedData.metadataStored.collection,
type = completedData.metadataStored.type, type = completedData.metadataStored.type,
videoDetails = videoInfo videoDetails = videoInfo

View File

@ -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<String>, collection: String, type: String, cover: String?, genres: String?): Int? {
val status = executeWithStatus(getStoreDatabase().database, block = { val status = executeWithStatus(getStoreDatabase().database, block = {
val existingRow = catalog.select { val existingRow = catalog.select {
(catalog.collection eq collection) and (catalog.collection eq collection) and
@ -77,7 +77,7 @@ object ContentCatalogStore {
} else { } else {
log.error { "Unable to store catalog $collection..." } log.error { "Unable to store catalog $collection..." }
} }
return getId(title, type) return getId(title, titles, collection, type)
} }
private fun storeMovie(catalogId: Int, videoDetails: VideoDetails) { private fun storeMovie(catalogId: Int, videoDetails: VideoDetails) {
@ -139,8 +139,8 @@ object ContentCatalogStore {
} }
} }
fun storeMedia(title: String, collection: String, type: String, videoDetails: VideoDetails) { fun storeMedia(title: String, titles: List<String>, collection: String, type: String, videoDetails: VideoDetails) {
val catalogId = getId(title, type) ?: run { val catalogId = getId(title, titles, collection, type) ?: run {
log.warn { "Could not find id for $title with type $type" } log.warn { "Could not find id for $title with type $type" }
return return
} }
@ -155,11 +155,13 @@ object ContentCatalogStore {
} }
} }
private fun getId(title: 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) {
catalog.select { catalog.select {
(catalog.title eq title) ((catalog.title eq title)
.and(catalog.type eq type) or (catalog.collection eq collection)
or (catalog.title inList titles)) and
(catalog.type eq type)
}.map { it[catalog.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" }