Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
3f71767acb | |||
75d71e9695 | |||
b97a4b1c0f | |||
e092990e17 | |||
9929db6c5b | |||
004c057a2c | |||
0b327f304e | |||
327ec9c62f |
@ -1,13 +1,14 @@
|
||||
[package]
|
||||
name = "zealot"
|
||||
description = "Bit Goblin automated video transcoding service."
|
||||
version = "0.2.0"
|
||||
version = "0.2.1"
|
||||
edition = "2021"
|
||||
readme = "README.md"
|
||||
license = "BSD 2-Clause"
|
||||
authors = ["Gregory Ballantine <gballantine@bitgoblin.tech>"]
|
||||
|
||||
[dependencies]
|
||||
clap = { version = "3.2", features = ['derive'] }
|
||||
config = { version = "0.13", features = ['toml'] }
|
||||
log = "0.4"
|
||||
log4rs = "1.1"
|
||||
@ -24,6 +25,7 @@ section = "video"
|
||||
assets = [
|
||||
["target/release/zealot", "usr/bin/zealot", "755"],
|
||||
["build/etc/example.toml", "etc/zealot/example.toml", "644"],
|
||||
["build/etc/log4rs.yaml", "etc/zealot/log4rs.yaml", "755"],
|
||||
["README.md", "usr/share/doc/zealot/README", "644"]
|
||||
]
|
||||
[package.metadata.deb.systemd-units]
|
||||
|
@ -4,7 +4,7 @@ Description=Zealot video transcoder service
|
||||
[Service]
|
||||
User=zealot
|
||||
Group=zealot
|
||||
ExecStart=/usr/bin/zealot
|
||||
ExecStart=/usr/bin/zealot -l /etc/zealot/log4rs.yaml
|
||||
SuccessExitStatus=143
|
||||
|
||||
[Install]
|
12
build/etc/log4rs.yaml
Normal file
12
build/etc/log4rs.yaml
Normal file
@ -0,0 +1,12 @@
|
||||
appenders:
|
||||
stdout:
|
||||
kind: console
|
||||
encoder:
|
||||
pattern: "{d(%+)(utc)} {h({l})}: {m}{n}"
|
||||
filters:
|
||||
- kind: threshold
|
||||
level: info
|
||||
root:
|
||||
level: info
|
||||
appenders:
|
||||
- stdout
|
@ -5,6 +5,7 @@ GETENT_GROUP=$(getent group zealot)
|
||||
|
||||
# Create the zealot user if it doesn't already exist
|
||||
if [ "$GETENT_USER" = "" ]; then
|
||||
echo "Creating the 'zealot' user."
|
||||
useradd -r zealot
|
||||
else
|
||||
echo "The 'zealot' user already exists, skipping creation."
|
||||
@ -12,6 +13,7 @@ fi
|
||||
|
||||
# Create the zealot group if it doesn't already exist
|
||||
if [ "$GETENT_GROUP" = "" ]; then
|
||||
echo "Creating the 'zealot' group."
|
||||
groupadd zealot
|
||||
usermod -aG zealot zealot
|
||||
else
|
||||
@ -21,6 +23,15 @@ fi
|
||||
# Change the directory ownership of /etc
|
||||
chown -R zealot:zealot /etc/zealot
|
||||
|
||||
# Create the log directory under /var/log
|
||||
if [ ! -d /var/log/zealot ]; then
|
||||
echo "Creating /var/log/zealot to store log files."
|
||||
mkdir /var/log/zealot
|
||||
chown zealot:zealot /var/log/zealot
|
||||
else
|
||||
echo "/var/log/zealot already exists, skipping creation."
|
||||
fi
|
||||
|
||||
#DEBHELPER#
|
||||
|
||||
exit 0
|
||||
|
10
example.config
Normal file
10
example.config
Normal file
@ -0,0 +1,10 @@
|
||||
[transcoder]
|
||||
repo_path = '~/zealot'
|
||||
interval = 15
|
||||
video_format = 'mov'
|
||||
video_codec = 'dnxhd'
|
||||
video_profile = 'dnxhr_hq'
|
||||
video_resolution = '1920x1080'
|
||||
video_framerate = '60'
|
||||
video_color = 'yuv422p'
|
||||
audio_codec = 'pcm_s16le'
|
20
src/cmd/core.rs
Normal file
20
src/cmd/core.rs
Normal file
@ -0,0 +1,20 @@
|
||||
use config::Config;
|
||||
use crate::settings;
|
||||
use crate::transcoder::repository::Repository;
|
||||
|
||||
pub fn setup_command() {
|
||||
// load configuration
|
||||
let c: Config = settings::load_config();
|
||||
|
||||
// resolve repository path
|
||||
let repository_dir_raw: &str = &c.get_string("transcoder.repository").unwrap();
|
||||
let repository_dir: &str = &shellexpand::tilde(repository_dir_raw);
|
||||
|
||||
// alert the user to what's happening
|
||||
println!("Initializing video repository at {}...", repository_dir);
|
||||
|
||||
// create and initialize our repository object
|
||||
let r: Repository = Repository::new(repository_dir);
|
||||
// initialize the video repository
|
||||
r.initialize();
|
||||
}
|
1
src/cmd/mod.rs
Normal file
1
src/cmd/mod.rs
Normal file
@ -0,0 +1 @@
|
||||
pub mod core;
|
37
src/main.rs
37
src/main.rs
@ -1,16 +1,45 @@
|
||||
use clap::{Parser, Subcommand};
|
||||
use log4rs;
|
||||
use config::Config;
|
||||
use transcoder::repository::Repository;
|
||||
use transcoder::transcoder::Transcoder;
|
||||
|
||||
mod cmd;
|
||||
mod settings;
|
||||
mod transcoder;
|
||||
mod util;
|
||||
|
||||
fn main() {
|
||||
// initialize the log4rs logger
|
||||
log4rs::init_file("./log4rs.yaml", Default::default()).unwrap();
|
||||
#[derive(Parser)]
|
||||
#[clap(author, version, about, long_about = None)]
|
||||
struct Cli {
|
||||
/// Number of times to greet
|
||||
#[clap(short = 'l', long, default_value_t = String::from("./log4rs.yaml"))]
|
||||
log_config: String,
|
||||
|
||||
#[clap(subcommand)]
|
||||
command: Option<Commands>,
|
||||
}
|
||||
|
||||
#[derive(Subcommand)]
|
||||
enum Commands {
|
||||
/// displays version info about this program
|
||||
Setup {},
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// initialize the clap CLI
|
||||
let cli = Cli::parse();
|
||||
|
||||
// grab the log4rs config file path, then initialize log4rs
|
||||
let log4rs_config: String = cli.log_config;
|
||||
log4rs::init_file(&log4rs_config, Default::default()).unwrap();
|
||||
|
||||
match &cli.command {
|
||||
// sub-commands will be handled here
|
||||
Some(Commands::Setup {}) => cmd::core::setup_command(),
|
||||
|
||||
// run the main program without any commands
|
||||
None => {
|
||||
// create and initialize our config and repository objects
|
||||
let c: Config = settings::load_config();
|
||||
let r: Repository = Repository::new(&shellexpand::tilde(&c.get_string("transcoder.repository").unwrap()));
|
||||
@ -18,4 +47,6 @@ fn main() {
|
||||
// create and start the video transcoder object
|
||||
let t: Transcoder = Transcoder::new(c, r);
|
||||
t.start();
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,33 @@
|
||||
use config::Config;
|
||||
|
||||
pub fn load_config() -> Config {
|
||||
let global_config_path: String = find_global_config_path();
|
||||
let home_config_path: String = find_home_config_path();
|
||||
|
||||
let settings = Config::builder()
|
||||
// Add in `./Settings.toml`
|
||||
.add_source(config::File::with_name("/etc/zealot/config.toml").required(false))
|
||||
.add_source(config::File::with_name(&shellexpand::tilde("~/.config/zealot.toml")).required(false))
|
||||
.add_source(config::File::with_name(&global_config_path).required(false))
|
||||
.add_source(config::File::with_name(&home_config_path).required(false))
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
return settings;
|
||||
}
|
||||
|
||||
fn find_global_config_path() -> String {
|
||||
if cfg!(windows) {
|
||||
return String::from("C:\\Program Files\\Zealot\\config.toml");
|
||||
}
|
||||
|
||||
return String::from("/etc/zealot/config.toml");
|
||||
}
|
||||
|
||||
fn find_home_config_path() -> String {
|
||||
let home_path: &str = &shellexpand::tilde("~/.config/zealot.toml");
|
||||
|
||||
if cfg!(windows) {
|
||||
return String::from(home_path.replace("/", "\\"));
|
||||
}
|
||||
|
||||
return String::from(home_path);
|
||||
}
|
||||
|
@ -11,16 +11,9 @@ pub struct Repository {
|
||||
|
||||
impl Repository {
|
||||
pub fn new(base_path: &str) -> Repository {
|
||||
// create the base directory path
|
||||
create_directory(base_path);
|
||||
|
||||
// create the needed sub-directories
|
||||
let ingest_path = Path::new(base_path).join("ingest");
|
||||
create_directory(ingest_path.to_str().unwrap());
|
||||
let archive_path = Path::new(base_path).join("archive");
|
||||
create_directory(archive_path.to_str().unwrap());
|
||||
let output_path = Path::new(base_path).join("output");
|
||||
create_directory(output_path.to_str().unwrap());
|
||||
|
||||
return Repository {
|
||||
base_dir: String::from(base_path),
|
||||
@ -30,6 +23,16 @@ impl Repository {
|
||||
};
|
||||
}
|
||||
|
||||
pub fn initialize(&self) {
|
||||
// create the base directory path
|
||||
create_directory(&self.base_dir);
|
||||
|
||||
// create the needed sub-directories
|
||||
create_directory(&self.ingest_dir.as_str());
|
||||
create_directory(&self.archive_dir.as_str());
|
||||
create_directory(&self.output_dir.as_str());
|
||||
}
|
||||
|
||||
pub fn search_ingest(&self) -> Vec<String> {
|
||||
// read file entries from ingest
|
||||
let files = fs::read_dir(&self.ingest_dir).unwrap();
|
||||
|
Reference in New Issue
Block a user