Updated file watcher

This commit is contained in:
Brage 2023-07-30 21:12:43 +02:00
parent 614e2111f1
commit ea281c9e3f

View File

@ -41,7 +41,14 @@ class FileWatcher: FileWatcherEvents {
} }
KWatchEvent.Kind.Created, KWatchEvent.Kind.Initialized -> { KWatchEvent.Kind.Created, KWatchEvent.Kind.Initialized -> {
if (validVideoFiles().contains(it.file.extension)) {
queue.addToQueue(it.file, this@FileWatcher::onFilePending, this@FileWatcher::onFileAvailable) queue.addToQueue(it.file, this@FileWatcher::onFilePending, this@FileWatcher::onFileAvailable)
} else if (it.file.isFile) {
logger.warn { "${it.file.name} is not a valid file type" }
} else if (it.file.isDirectory) {
val valid = it.file.walkTopDown().filter { f -> f.isFile && f.extension in validVideoFiles() }
logger.warn { "${it.file.name} ignoring directory" }
}
} }
else -> { else -> {
@ -69,6 +76,15 @@ class FileWatcher: FileWatcherEvents {
} }
} }
fun validVideoFiles(): List<String> = listOf(
"mkv",
"avi",
"mp4",
"wmv",
"webm",
"mov"
)
override fun onFileAvailable(file: PendingFile) { override fun onFileAvailable(file: PendingFile) {
logger.debug { "onFileAvailable har mottatt pendingFile ${file.file.name}" } logger.debug { "onFileAvailable har mottatt pendingFile ${file.file.name}" }