analysis with screenshots is k WOO

main
Bel LaPointe 2023-12-27 22:04:25 -05:00
parent 01887f061a
commit 5033c4016f
3 changed files with 2129 additions and 171 deletions

2266
src/Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -7,7 +7,6 @@ edition = "2021"
[dependencies] [dependencies]
dioxus = "0.4.3" dioxus = "0.4.3"
rfd = "0.12.1"
lib = { path = "../src-lib" } lib = { path = "../src-lib" }
base64 = "0.21.5" base64 = "0.21.5"
#dioxus-web = "0.4.3" #dioxus-web = "0.4.3"

View File

@ -1,14 +1,13 @@
#![allow(non_snake_case)] #![allow(non_snake_case)]
// import the prelude to get access to the `rsx!` macro and the `Scope` and `Element` types // import the prelude to get access to the `rsx!` macro and the `Scope` and `Element` types
use dioxus::prelude::*; use dioxus::prelude::*;
use rfd::AsyncFileDialog;
use lib; use lib;
use base64::{engine::general_purpose, Engine as _}; use base64::{engine::general_purpose, Engine as _};
fn main() { fn main() {
// launch the dioxus app in a webview // launch the dioxus app in a webview
// dioxus_desktop::launch(App); dioxus_desktop::launch(App); // TODO desktop
dioxus_web::launch(App); //dioxus_web::launch(App);
} }
// define a component that renders a div with the text "Hello, world!" // define a component that renders a div with the text "Hello, world!"
@ -23,33 +22,32 @@ fn App(cx: Scope) -> Element {
rsx! { rsx! {
div { div {
input { input {
r#type: "button", r#type: "file",
value: "pick file", onclick: move |evt| { onchange: |evt| {
to_owned![file]; to_owned![file];
async move { async move {
match AsyncFileDialog::new() if let Some(file_engine) = &evt.files {
.pick_file() for f in &file_engine.files() {
.await { file.set(f.clone()); // TODO swap to .path() on desktop
Some(f) => { //file.set(f.path().clone()); // TODO swap to .path() on desktop
//file.set(f.file_name().clone()); // TODO swap to .path() on desktop }
file.set(f.path().clone()); // TODO swap to .path() on desktop }
},
None => { file.set(format!("<<failed to pick a file>>")); },
};
} }
}, },
}, },
p { file.get().clone() } p { file.get().clone() }
} }
div { div {
input { r#type: "button", value: "analyze", onclick: move |evt| { input { r#type: "button", value: "analyze", disabled: file.get().len() == 0, onclick: move |evt| {
to_owned![file]; to_owned![file];
to_owned![analysis]; to_owned![analysis];
async move { async move {
analysis.set(analyze(file.get().clone())); analysis.set(analyze(file.get().clone()));
} }
}} }}
input { r#type: "button", value: "clipify", onclick: move |evt| { clipify(file.get().clone()); } } input { r#type: "button", value: "clipify", disabled: file.get().len() == 0, onclick: move |evt| {
clipify(file.get().clone());
}}
} }
div { div {
analysis.get().iter().map(|a| { analysis.get().iter().map(|a| {
@ -86,7 +84,6 @@ fn analyze(file: String) -> Vec<Analyzed> {
let content_spans = content_spans.unwrap(); let content_spans = content_spans.unwrap();
head.iter().chain(content_spans.iter()) head.iter().chain(content_spans.iter())
.map(|content_span| { .map(|content_span| {
eprintln!("analyze");
let mut result = Analyzed{ let mut result = Analyzed{
start: content_span.start.to_string(), start: content_span.start.to_string(),
stop: content_span.stop.to_string(), stop: content_span.stop.to_string(),
@ -94,7 +91,7 @@ fn analyze(file: String) -> Vec<Analyzed> {
}; };
match lib::video::screenshot_png( match lib::video::screenshot_png(
&file, &file,
content_span.start, (content_span.start + content_span.stop) / 2.0,
) { ) {
Ok(png) => { result.screenshot = general_purpose::STANDARD.encode(&png); }, Ok(png) => { result.screenshot = general_purpose::STANDARD.encode(&png); },
Err(msg) => { result.stop = format!("{} <<failed to screenshot {}: {}>>", result.stop, file, msg); }, Err(msg) => { result.stop = format!("{} <<failed to screenshot {}: {}>>", result.stop, file, msg); },