start working on messenger

This commit is contained in:
jb-alvarado 2022-02-23 18:06:40 +01:00
parent c7aec5b594
commit 13551a0237
9 changed files with 163 additions and 11 deletions

1
.gitignore vendored
View File

@ -8,3 +8,4 @@
# exclude binarys in examples folder
/examples/*
!/examples/*.rs
*.log

36
Cargo.lock generated
View File

@ -61,9 +61,9 @@ dependencies = [
[[package]]
name = "clap"
version = "3.0.14"
version = "3.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b63edc3f163b3c71ec8aa23f9bd6070f77edbf3d1d198b164afa90ff00e4ec62"
checksum = "6d76c22c9b9b215eeb8d016ad3a90417bd13cb24cf8142756e6472445876cab7"
dependencies = [
"atty",
"bitflags",
@ -78,9 +78,9 @@ dependencies = [
[[package]]
name = "clap_derive"
version = "3.0.14"
version = "3.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a1132dc3944b31c20dd8b906b3a9f0a5d0243e092d59171414969657ac6aa85"
checksum = "5fd1122e63869df2cb309f449da1ad54a7c6dfeb7c7e6ccd8e0825d9eb93bb72"
dependencies = [
"heck",
"proc-macro-error",
@ -96,12 +96,14 @@ dependencies = [
"chrono",
"clap",
"ffprobe",
"log",
"notify",
"rand",
"regex",
"serde",
"serde_json",
"serde_yaml",
"simplelog",
"walkdir",
]
@ -164,9 +166,9 @@ checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7"
[[package]]
name = "getrandom"
version = "0.2.4"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "418d37c8b1d42553c93648be529cb70f920d3baf8ef469b74b9638df426e0b4c"
checksum = "d39cd93900197114fa1fcb7ae84ca742095eed9442088988ae74fa744e930e77"
dependencies = [
"cfg-if 1.0.0",
"libc",
@ -263,9 +265,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
[[package]]
name = "libc"
version = "0.2.117"
version = "0.2.119"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e74d72e0f9b65b5b4ca49a346af3976df0f9c61d550727f349ecd559f251a26c"
checksum = "1bf2e165bb3457c8e098ea76f3e3bc9db55f87aa90d52d0e6be741470916aaa4"
[[package]]
name = "linked-hash-map"
@ -388,6 +390,12 @@ dependencies = [
"memchr",
]
[[package]]
name = "paris"
version = "1.5.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c69d19a208bba8b94bd27d4b7a06ad153cddc6b88cb2149a668e23ce7bdb67d5"
[[package]]
name = "ppv-lite86"
version = "0.2.16"
@ -550,6 +558,18 @@ dependencies = [
"yaml-rust",
]
[[package]]
name = "simplelog"
version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1348164456f72ca0116e4538bdaabb0ddb622c7d9f16387c725af3e96d6001c"
dependencies = [
"chrono",
"log",
"paris",
"termcolor",
]
[[package]]
name = "slab"
version = "0.4.5"

View File

@ -16,6 +16,8 @@ notify = "4.0.0"
walkdir = "2"
rand = "0.8.5"
ffprobe = "0.3"
log = "0.4.14"
simplelog = { version = "^0.11.2", features = ["paris"] }
# tokio = { version = "1.16.1", features = ["full"] }
[[bin]]

View File

@ -1 +1 @@
# ffplayout-engine-rs
# ffplayout-engine-rs

16
docs/developer.md Normal file
View File

@ -0,0 +1,16 @@
### Cross Compile
For cross compiling on fedora linux, you need to install some extra packages:
- mingw compiler:
```
dnf install mingw{32,64}-filesystem mingw{32,64}-binutils mingw{32,64}-gcc{,-c++} mingw{32,64}-crt mingw{32,64}-headers mingw{32,64}-pkg-config mingw32-nsis mingw{32,64}-hamlib mingw{32,64}-libpng mingw{32,64}-libusbx mingw{32,64}-portaudio mingw{32,64}-fltk mingw{32,64}-libgnurx mingw{32,64}-gettext mingw{32,64}-winpthreads-static intltool
```
- rust tools:
```
rustup toolchain install stable-x86_64-pc-windows-gnu
rustup target add x86_64-pc-windows-gnu
```
[Cross](https://github.com/cross-rs/cross#dependencies) could be an option to.

21
examples/logging.rs Normal file
View File

@ -0,0 +1,21 @@
extern crate log;
extern crate simplelog;
use simplelog::*;
use std::fs::File;
fn main() {
TermLogger::init(LevelFilter::Debug, Config::default(), TerminalMode::Mixed, ColorChoice::Auto).unwrap();
//SimpleLogger::init(LevelFilter::Debug, Config::default()).unwrap();
// CombinedLogger::init(
// vec![
// TermLogger::new(LevelFilter::Debug, Config::default(), TerminalMode::Mixed, ColorChoice::Auto),
// WriteLogger::new(LevelFilter::Debug, Config::default(), File::create("my_rust_binary.log").unwrap()),
// ]
// ).unwrap();
error!("Bright red error");
info!("This only appears in <red>the log file</>");
debug!("This level is <b>currently</b> not enabled for any logger");
}

View File

@ -3,10 +3,16 @@ mod output;
mod utils;
use crate::output::desktop;
use crate::utils::get_config;
use crate::utils::{get_config, Messenger};
fn main() {
let config = get_config();
let msg = Messenger::new(&config);
msg.debug("this is a debug");
msg.info("this is a info");
msg.warning("this is a warning");
msg.error("this is a error");
// println!("{:#?}", config);
// folder::walk(&config.storage.path, config.storage.shuffle, &config.storage.extensions);

85
src/utils/messenger.rs Normal file
View File

@ -0,0 +1,85 @@
extern crate log;
extern crate simplelog;
use simplelog::*;
use std::fs::File;
use crate::utils::Config;
pub struct Messenger {
message: String,
log_to_file: bool,
backup_count: u32,
path: String,
level: String,
ffmpeg_level: String,
}
impl Messenger {
pub fn new(config: &Config) -> Self {
let conf = config.logging.clone();
let logger_config = simplelog::ConfigBuilder::new()
.set_level_color(Level::Info, Some(Color::Green))
.build();
if conf.log_to_file {
WriteLogger::init(
LevelFilter::Debug,
simplelog::Config::default(),
File::create("ffplayout.log").unwrap(),
)
.unwrap();
} else {
TermLogger::init(
LevelFilter::Debug,
logger_config,
TerminalMode::Mixed,
ColorChoice::Auto,
)
.unwrap();
}
Messenger {
message: "".to_string(),
log_to_file: conf.log_to_file,
backup_count: conf.backup_count,
path: conf.log_path,
level: conf.log_level,
ffmpeg_level: conf.ffmpeg_level,
}
}
pub fn debug(&self, msg: &str) {
if self.level.to_lowercase() == "debug".to_string() {
debug!("{}", msg)
}
}
pub fn info(&self, msg: &str) {
if self.level.to_lowercase() == "debug".to_string()
|| self.level.to_lowercase() == "info".to_string()
{
info!("{}", msg)
}
}
pub fn warning(&self, msg: &str) {
if self.level.to_lowercase() == "debug".to_string()
|| self.level.to_lowercase() == "info".to_string()
|| self.level.to_lowercase() == "warning".to_string()
{
warn!("{}", msg)
}
}
pub fn error(&self, msg: &str) {
if self.level.to_lowercase() == "debug".to_string()
|| self.level.to_lowercase() == "info".to_string()
|| self.level.to_lowercase() == "warning".to_string()
|| self.level.to_lowercase() == "error".to_string()
{
error!("{}", msg)
}
}
}

View File

@ -6,14 +6,15 @@ use std::{fs::metadata, process, time, time::UNIX_EPOCH};
mod arg_parse;
mod config;
// mod folder;
mod json_reader;
mod messenger;
mod playlist;
pub use arg_parse::get_args;
pub use config::{get_config, Config};
// pub use folder::walk;
pub use json_reader::{read_json, Program};
pub use messenger::Messenger;
pub use playlist::program;
#[derive(Debug, Serialize, Deserialize, Clone)]