Got a basic working structure in place
This commit is contained in:
		
							
								
								
									
										5
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										5
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							| @@ -14,3 +14,8 @@ Cargo.lock | |||||||
| # MSVC Windows builds of rustc generate these, which store debugging information | # MSVC Windows builds of rustc generate these, which store debugging information | ||||||
| *.pdb | *.pdb | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  | # Added by cargo | ||||||
|  |  | ||||||
|  | /target | ||||||
|   | |||||||
							
								
								
									
										12
									
								
								Cargo.toml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								Cargo.toml
									
									
									
									
									
										Normal file
									
								
							| @@ -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" | ||||||
							
								
								
									
										34
									
								
								src/config.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								src/config.rs
									
									
									
									
									
										Normal file
									
								
							| @@ -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, | ||||||
|  | } | ||||||
							
								
								
									
										17
									
								
								src/main.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								src/main.rs
									
									
									
									
									
										Normal file
									
								
							| @@ -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(); | ||||||
|  | } | ||||||
							
								
								
									
										39
									
								
								src/repository.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								src/repository.rs
									
									
									
									
									
										Normal file
									
								
							| @@ -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); | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | } | ||||||
							
								
								
									
										20
									
								
								src/transcoder.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								src/transcoder.rs
									
									
									
									
									
										Normal file
									
								
							| @@ -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..."); | ||||||
|  | 	} | ||||||
|  | } | ||||||
		Reference in New Issue
	
	Block a user