From 145be49e92edffcbb1cb5d28557ca0577867bab8 Mon Sep 17 00:00:00 2001 From: Brage Date: Mon, 31 Jul 2023 01:05:25 +0200 Subject: [PATCH] Using existing if found --- .../content/reader/collector/VideoConsumer.kt | 50 +++++++++++++------ 1 file changed, 34 insertions(+), 16 deletions(-) diff --git a/Reader/src/main/kotlin/no/iktdev/streamit/content/reader/collector/VideoConsumer.kt b/Reader/src/main/kotlin/no/iktdev/streamit/content/reader/collector/VideoConsumer.kt index 089000ea..e1c56381 100644 --- a/Reader/src/main/kotlin/no/iktdev/streamit/content/reader/collector/VideoConsumer.kt +++ b/Reader/src/main/kotlin/no/iktdev/streamit/content/reader/collector/VideoConsumer.kt @@ -85,25 +85,30 @@ class VideoConsumer: DefaultKafkaReader("collectorConsumerEncodedVideo"), IColle } val coverUrl = metadata?.cover - val coverFile: File? = if (coverUrl != null) { - logger.info { "Downloading Cover: $coverUrl" } - runBlocking { - try { - val _file = Downloader(coverUrl, outDir, fileData.title).download() - if (_file == null || !_file.exists()) { - logger.info { "Failed to download the file" } + val currentCover = getExistingCover(outDir) + val coverFile = if (currentCover == null || !currentCover.exists()) { + if (coverUrl != null) { + logger.info { "Downloading Cover: $coverUrl" } + runBlocking { + try { + val _file = Downloader(coverUrl, outDir, fileData.title).download() + if (_file == null || !_file.exists()) { + logger.info { "Failed to download the file" } + } + _file + } catch (e: Exception) { + // No cover + e.printStackTrace() + null } - _file - } catch (e: Exception) { - // No cover - e.printStackTrace() - null } + } else { + logger.info { "No cover url received" } + null } - } else { - logger.info { "No cover url received" } - null - } + } else currentCover + + // Serie må alltid fullføres før catalog. dette i tilfelle catalog allerede eksisterer og den thrower slik at transaskjonen blir versertert! @@ -162,4 +167,17 @@ class VideoConsumer: DefaultKafkaReader("collectorConsumerEncodedVideo"), IColle return SerieQuery(data.episodeTitle, data.episode, data.season, data.title, baseName) } + val validCoverFormat = listOf( + "png", + "jpg", + "jpeg", + "webp", + "bmp", + "tiff" + ) + fun getExistingCover(contentDir: File): File? { + val possibleCovers = contentDir.walkTopDown().filter { it.isFile && validCoverFormat.contains(it.extension)} + return possibleCovers.firstOrNull() + } + } \ No newline at end of file