Added a simple program loop to repeatedly check for new video files

This commit is contained in:
Gregory Ballantine 2022-09-01 15:29:24 -04:00
parent e3eb54720c
commit e14795c493
3 changed files with 141 additions and 129 deletions

View File

@ -1,5 +1,6 @@
use std::path::Path;
use std::process;
use std::{thread, time};
use crate::config::Config;
use crate::repository::Repository;
@ -20,9 +21,14 @@ impl Transcoder {
pub fn start(self) {
println!("Starting transcoder...");
loop {
// search for files in ingest
let ingest_files = self.repository.search_ingest();
// check if we found any files to transcode
if ingest_files.len() < 1 {
println!("There were no files found in ingest to transcode; skipping run.");
} else {
for i in ingest_files {
// copy the file to the archive
self.repository.archive_file(&i);
@ -35,6 +41,12 @@ impl Transcoder {
}
}
// put the loop to sleep for X minutes
let sleep_minutes = time::Duration::from_secs((self.config.transcoder.interval * 60).into());
thread::sleep(sleep_minutes);
}
}
fn transcode(&self, file: &str) {
let ingest_file = Path::new(&self.repository.ingest_dir).join(file);
let output_file = Path::new(&self.repository.output_dir).join(file);