progression

main
Bel LaPointe 2023-12-27 21:53:08 -05:00
parent f3b960c2f5
commit 49d811fc65
3 changed files with 74 additions and 5 deletions

12
src/Cargo.lock generated
View File

@ -89,6 +89,12 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]]
name = "base64"
version = "0.21.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "35636a1494ede3b646cc98f74f8e62c773a38a659ebc777a2cf26b9b74171df9"
[[package]] [[package]]
name = "bitflags" name = "bitflags"
version = "2.4.1" version = "2.4.1"
@ -696,6 +702,10 @@ dependencies = [
"unicode-segmentation", "unicode-segmentation",
] ]
[[package]]
name = "lib"
version = "0.1.0"
[[package]] [[package]]
name = "libc" name = "libc"
version = "0.2.151" version = "0.2.151"
@ -1065,8 +1075,10 @@ dependencies = [
name = "src" name = "src"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"base64",
"dioxus", "dioxus",
"dioxus-web", "dioxus-web",
"lib",
"rfd", "rfd",
] ]

View File

@ -9,4 +9,6 @@ edition = "2021"
dioxus = "0.4.3" dioxus = "0.4.3"
dioxus-web = "0.4.3" dioxus-web = "0.4.3"
rfd = "0.12.1" rfd = "0.12.1"
lib = { path = "../src-lib" }
base64 = "0.21.5"
#dioxus-desktop = "0.4.3" #dioxus-desktop = "0.4.3"

View File

@ -2,6 +2,8 @@
// 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 rfd::AsyncFileDialog;
use lib;
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
@ -12,6 +14,7 @@ fn main() {
// define a component that renders a div with the text "Hello, world!" // define a component that renders a div with the text "Hello, world!"
fn App(cx: Scope) -> Element { fn App(cx: Scope) -> Element {
let file = use_state(cx, String::new); let file = use_state(cx, String::new);
let analysis = use_state(cx, Vec::<Analyzed>::new);
cx.render(rsx! { cx.render(rsx! {
header { header {
h1 { "home-video-blue-extractinator" } h1 { "home-video-blue-extractinator" }
@ -38,18 +41,70 @@ fn App(cx: Scope) -> Element {
p { file.get().clone() } p { file.get().clone() }
} }
div { div {
input { r#type: "button", value: "analyze", onclick: move |evt| { analyze(evt); } } input { r#type: "button", value: "analyze", onclick: move |evt| {
input { r#type: "button", value: "clipify", onclick: move |evt| { clipify(evt); } } to_owned![file];
to_owned![analysis];
async move {
analysis.set(analyze(file.get().clone()));
}
}}
input { r#type: "button", value: "clipify", onclick: move |evt| { clipify(file.get().clone()); } }
}
div {
analysis.get().iter().map(|a| {
rsx! {
p {
"{a.start}..{a.stop}: "
img { src: "data:image/png;base64, {a.screenshot}" }
}
}
})
} }
} }
} }
}) })
} }
fn analyze(evt: Event<MouseData>) { struct Analyzed {
eprintln!("analyze"); start: String,
stop: String,
screenshot: String,
} }
fn clipify(evt: Event<MouseData>) { fn analyze(file: String) -> Vec<Analyzed> {
//let content_spans = lib::video::inspect(&file); // TODO
let content_spans: Result<Vec<lib::video::ContentSpan>, String> = Ok(vec![lib::video::ContentSpan{start: 0.5, stop: 20.2}]);
if content_spans.is_err() {
return vec![Analyzed{
start: format!("<<err analyzing {}", file),
stop: format!("{}>>", content_spans.err().unwrap()),
screenshot: a_png.to_string(),
}];
}
let head: Vec<lib::video::ContentSpan> = vec![lib::video::ContentSpan{start: 0.0, stop: 0.0}];
let content_spans = content_spans.unwrap();
head.iter().chain(content_spans.iter())
.map(|content_span| {
eprintln!("analyze");
let mut result = Analyzed{
start: content_span.start.to_string(),
stop: content_span.stop.to_string(),
screenshot: a_png.to_string(),
};
match lib::video::screenshot_png(
&file,
content_span.start,
) {
Ok(png) => { result.screenshot = general_purpose::STANDARD.encode(&png); },
Err(msg) => { result.stop = format!("{} <<failed to screenshot {}: {}>>", result.stop, file, msg); },
};
result
})
.collect()
}
fn clipify(file: String) {
eprintln!("clipify"); eprintln!("clipify");
} }
const a_png: &str = "iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==";