diff --git a/.gitignore b/.gitignore index 3ca43ae..193d30e 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,8 @@ Cargo.lock # MSVC Windows builds of rustc generate these, which store debugging information *.pdb + + +# Added by cargo + +/target diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..6fb1618 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "adept" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +toml = "0.5" +serde = "1.0" +serde_derive = "1.0" +shellexpand = "2.1" diff --git a/src/config.rs b/src/config.rs new file mode 100644 index 0000000..b465140 --- /dev/null +++ b/src/config.rs @@ -0,0 +1,34 @@ +use serde_derive::Deserialize; +use std::fs; + +#[derive(Deserialize)] +pub struct Config { + pub transcoder: Transcoder, +} + +impl Config { + pub fn new(config_path: &str) -> Config { + let resolved_path = shellexpand::tilde(config_path); + let config_text = fs::read_to_string(&*resolved_path).unwrap(); + let c: Config = toml::from_str(&config_text).unwrap(); + return c; + } + + pub fn get_repository(&self) -> String { + let resolved_path = shellexpand::tilde(&self.transcoder.repository); + return String::from(&*resolved_path); + } +} + +#[derive(Deserialize)] +pub struct Transcoder { + pub repository: String, + pub interval: u16, + pub video_format: String, + pub video_codec: String, + pub video_profile: String, + pub video_resolution: String, + pub video_framerate: u8, + pub video_color: String, + pub audio_codec: String, +} diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..5fffdcf --- /dev/null +++ b/src/main.rs @@ -0,0 +1,17 @@ +use config::Config; +use repository::Repository; +use transcoder::Transcoder; + +mod config; +mod repository; +mod transcoder; + +fn main() { + // create and initialize our config and repository objects + let c: Config = Config::new("~/.config/adept.toml"); + let r: Repository = Repository::new(&c.get_repository()); + + // create and start the video transcoder object + let t: Transcoder = Transcoder::new(c, r); + t.start(); +} diff --git a/src/repository.rs b/src/repository.rs new file mode 100644 index 0000000..40b755d --- /dev/null +++ b/src/repository.rs @@ -0,0 +1,39 @@ +use std::fs; +use std::path::Path; + +pub struct Repository { + base_path: String, +} + +impl Repository { + pub fn new(base_path: &str) -> Repository { + // create the base directory path + create_directory(base_path); + + let sub_dirs: Vec<&str> = vec!["ingest", "archive", "output"]; + for s in sub_dirs { + create_directory(Path::new(base_path).join(s).to_str().unwrap()); + } + + return Repository { + base_path: String::from(base_path), + }; + } +} + +fn create_directory(path: &str) { + let d = Path::new(path); + if d.is_dir() { + println!("Directory {} already exists.", path); + } else { + match fs::create_dir(path) { + Ok(_) => { + println!("Creating directory {}.", path); + }, + Err(e) => { + eprintln!("Error creating {}: {}", path, e); + std::process::exit(1); + } + } + } +} diff --git a/src/transcoder.rs b/src/transcoder.rs new file mode 100644 index 0000000..894efb7 --- /dev/null +++ b/src/transcoder.rs @@ -0,0 +1,20 @@ +use crate::config::Config; +use crate::repository::Repository; + +pub struct Transcoder { + config: Config, + repository: Repository, +} + +impl Transcoder { + pub fn new(config: Config, repository: Repository) -> Transcoder { + return Transcoder{ + config: config, + repository: repository, + } + } + + pub fn start(self) { + println!("Starting transcoder..."); + } +}