Using existing if found

This commit is contained in:
Brage 2023-07-31 01:05:25 +02:00
parent 6c253e4349
commit 145be49e92

View File

@ -85,25 +85,30 @@ class VideoConsumer: DefaultKafkaReader("collectorConsumerEncodedVideo"), IColle
} }
val coverUrl = metadata?.cover val coverUrl = metadata?.cover
val coverFile: File? = if (coverUrl != null) { val currentCover = getExistingCover(outDir)
logger.info { "Downloading Cover: $coverUrl" } val coverFile = if (currentCover == null || !currentCover.exists()) {
runBlocking { if (coverUrl != null) {
try { logger.info { "Downloading Cover: $coverUrl" }
val _file = Downloader(coverUrl, outDir, fileData.title).download() runBlocking {
if (_file == null || !_file.exists()) { try {
logger.info { "Failed to download the file" } 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 { } else currentCover
logger.info { "No cover url received" }
null
}
// Serie må alltid fullføres før catalog. dette i tilfelle catalog allerede eksisterer og den thrower slik at transaskjonen blir versertert! // 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) 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()
}
} }