add matching time parsing and formatting routines

* add a --ts subcommand to convert between numeric and human-readable
  representations. This is handy when directly inspecting the SQLite database
  or API output.
* also take the human-readable form in the web interface's camera view.
* to reduce confusion, when using trim=true on the web interface's camera
  view, trim the displayed starting and ending times as well as the actual
  .mp4 file links.
This commit is contained in:
Scott Lamb
2017-01-12 23:09:02 -08:00
parent c96f306e18
commit a6ec68027a
5 changed files with 205 additions and 19 deletions

View File

@@ -93,6 +93,7 @@ const USAGE: &'static str = "
Usage: moonfire-nvr [options]
moonfire-nvr --upgrade [options]
moonfire-nvr --check [options]
moonfire-nvr --ts <ts>...
moonfire-nvr (--help | --version)
Options:
@@ -127,8 +128,10 @@ struct Args {
flag_read_only: bool,
flag_check: bool,
flag_upgrade: bool,
flag_ts: bool,
flag_no_vacuum: bool,
flag_preset_journal: String,
arg_ts: Vec<String>,
}
fn main() {
@@ -171,11 +174,21 @@ fn main() {
upgrade::run(conn, &args.flag_preset_journal, args.flag_no_vacuum).unwrap();
} else if args.flag_check {
check::run(conn, &args.flag_sample_file_dir).unwrap();
} else if args.flag_ts {
run_ts(args.arg_ts).unwrap();
} else {
run(args, conn, &signal);
}
}
fn run_ts(timestamps: Vec<String>) -> Result<(), error::Error> {
for timestamp in &timestamps {
let t = recording::Time::parse(timestamp)?;
println!("{} == {}", t, t.0);
}
Ok(())
}
fn run(args: Args, conn: rusqlite::Connection, signal: &chan::Receiver<chan_signal::Signal>) {
let db = Arc::new(db::Database::new(conn).unwrap());
let dir = dir::SampleFileDir::new(&args.flag_sample_file_dir, db.clone()).unwrap();