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 166d6c9e..5e7b0dbc 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 @@ -136,42 +136,18 @@ class CompletedTaskListener : CoordinatorEventListener() { } else mediaInfo.fallbackCollection val mover = ContentCompletionMover(usableCollection, events) - val newVideoPath = mover.moveVideo() - val newCoverPath = mover.moveCover() - val newSubtitles = mover.moveSubtitles() + val genreIdsForCatalog = ContentGenresStore.storeAndGetIds(mediaInfo.genres) + val newCoverPath = mover.moveCover() - - val catalogId = ContentCatalogStore.storeCatalog( + ContentCatalogStore.storeCatalog( title = mediaInfo.title, collection = usableCollection, type = mediaInfo.type, cover = newCoverPath?.second?.let { dp -> File(dp).name }, genres = genreIdsForCatalog, - ) - - getVideo(events)?.let { video -> - ContentCatalogStore.storeMedia( - title = mediaInfo.title, - collection = usableCollection, - type = mediaInfo.type, - videoDetails = video - ) - } - - - val storedSubtitles = newSubtitles?.let { subtitles -> - subtitles.mapNotNull { - ContentSubtitleStore.storeSubtitles( - collection = usableCollection, - language = it.language, - destinationFile = File(it.destination) - ) - } - } - - catalogId?.let { cid -> + )?.also { cid -> mediaInfo.summaries.forEach { ContentMetadataStore.storeSummary(cid, it) } @@ -179,6 +155,38 @@ class CompletedTaskListener : CoordinatorEventListener() { } + + val newVideoPath = mover.moveVideo() + try { + getVideo(events)?.let { video -> + ContentCatalogStore.storeMedia( + title = mediaInfo.title, + collection = usableCollection, + type = mediaInfo.type, + videoDetails = video + ) + } + } catch (e: Exception) { + e.printStackTrace() + } + + val newSubtitles = mover.moveSubtitles() + + try { + newSubtitles?.let { subtitles -> + subtitles.map { + ContentSubtitleStore.storeSubtitles( + collection = usableCollection, + language = it.language, + destinationFile = File(it.destination) + ) + } + } + } catch (e: Exception) { + e.printStackTrace() + } + + if (!doNotProduceComplete) { onProduceEvent(MediaProcessCompletedEvent( metadata = event.makeDerivedEventInfo(EventStatus.Success, getProducerName()), diff --git a/apps/coordinator/src/main/kotlin/no/iktdev/mediaprocessing/coordinator/tasksV2/mapping/store/ContentCompletionMover.kt b/apps/coordinator/src/main/kotlin/no/iktdev/mediaprocessing/coordinator/tasksV2/mapping/store/ContentCompletionMover.kt index 0e8edf1c..8f2673a5 100644 --- a/apps/coordinator/src/main/kotlin/no/iktdev/mediaprocessing/coordinator/tasksV2/mapping/store/ContentCompletionMover.kt +++ b/apps/coordinator/src/main/kotlin/no/iktdev/mediaprocessing/coordinator/tasksV2/mapping/store/ContentCompletionMover.kt @@ -38,7 +38,7 @@ class ContentCompletionMover(val collection: String, val events: List) { val result = encodedFile.moveTo(storeFile) { } - return if (result) Pair(encodedFile.absolutePath, storeFile.absolutePath) else null + return if (result) Pair(encodedFile.absolutePath, storeFile.absolutePath) else throw RuntimeException("Unable to movie file ${encodedFile.absolutePath} to ${storeFile.absolutePath}") } fun moveCover(): Pair? {