statuses per-event because scrolling stinks
parent
a8ba8fc97d
commit
32a652519a
|
|
@ -14,7 +14,8 @@ fn main() {
|
|||
// define a component that renders a div with the text "Hello, world!"
|
||||
fn App(cx: Scope) -> Element {
|
||||
let file = use_state(cx, || String::new());
|
||||
let status = use_state(cx, || String::new());
|
||||
let analyze_status = use_state(cx, || String::new());
|
||||
let clipify_status = use_state(cx, || String::new());
|
||||
let processing = use_state(cx, || false);
|
||||
let analysis = use_state(cx, || Analysis::new());
|
||||
let a_css = String::from_utf8_lossy(include_bytes!("./style.css"));
|
||||
|
|
@ -46,18 +47,18 @@ fn App(cx: Scope) -> Element {
|
|||
input { r#type: "button", value: "analyze", disabled: file.get().len() == 0 || *processing.get(), onclick: move |_| {
|
||||
cx.spawn({
|
||||
let file = file.to_owned();
|
||||
let status = status.to_owned();
|
||||
let analyze_status = analyze_status.to_owned();
|
||||
let processing = processing.to_owned();
|
||||
let analysis = analysis.to_owned();
|
||||
|
||||
async move {
|
||||
processing.set(true);
|
||||
status.set(format!("analyzing {file}... (this may take a while, like 5 minutes, but I promise I'm working on it)"));
|
||||
analyze_status.set(format!("analyzing {file}... (this may take a while, like 5 minutes, but I promise I'm working on it)"));
|
||||
let analyzed = analyze(file.get().clone()).await;
|
||||
if analyzed.err.len() > 0 {
|
||||
status.set(analyzed.err.clone());
|
||||
analyze_status.set(analyzed.err.clone());
|
||||
} else {
|
||||
status.set(format!(
|
||||
analyze_status.set(format!(
|
||||
"found {} clips to keep and {} clips to drop",
|
||||
analyzed.result.iter().filter(|x| x.has_content).count(),
|
||||
analyzed.result.iter().filter(|x| !x.has_content).count(),
|
||||
|
|
@ -68,11 +69,8 @@ fn App(cx: Scope) -> Element {
|
|||
}
|
||||
});
|
||||
}}
|
||||
}
|
||||
div {
|
||||
br {}
|
||||
status.get().clone()
|
||||
br {}
|
||||
div { analyze_status.get().clone() }
|
||||
}
|
||||
div {
|
||||
form {
|
||||
|
|
@ -88,14 +86,14 @@ fn App(cx: Scope) -> Element {
|
|||
}
|
||||
})
|
||||
.collect();
|
||||
status.set(format!("clipifying {:?}...", content_spans));
|
||||
clipify_status.set(format!("clipifying {:?}...", content_spans));
|
||||
let file = file.get().clone();
|
||||
to_owned![status];
|
||||
to_owned![clipify_status];
|
||||
to_owned![processing];
|
||||
async move {
|
||||
processing.set(true);
|
||||
let f = clipify(file, content_spans).await;
|
||||
status.set(f);
|
||||
clipify_status.set(f);
|
||||
processing.set(false);
|
||||
}
|
||||
},
|
||||
|
|
@ -119,6 +117,8 @@ fn App(cx: Scope) -> Element {
|
|||
})
|
||||
hr {}
|
||||
h3 { "4. Submit your re-clip" }
|
||||
div { clipify_status.get().clone() }
|
||||
br {}
|
||||
input { r#type: "submit", value: "clipify selected spans", disabled: file.get().len() == 0 || *processing.get() || analysis.get().result.len() == 0 }
|
||||
}
|
||||
}
|
||||
|
|
@ -205,22 +205,23 @@ async fn analyze(file: String) -> Analysis {
|
|||
|
||||
async fn clipify(file: String, content_spans: Vec<lib::video::ContentSpan>) -> String {
|
||||
let d = format!("{}.d", &file);
|
||||
let mut last_err = None;
|
||||
let mut statuses = vec![];
|
||||
for content_span in content_spans.iter() {
|
||||
let output = format!("{}/{}.mp4", &d, content_span.start);
|
||||
let cur = lib::video::clip_async(&output, &file, *content_span).await;
|
||||
if cur.is_err() {
|
||||
last_err = Some(format!("failed to clipify {} at {}..{}: {}", &file, &content_span.start, &content_span.stop, cur.err().unwrap()));
|
||||
match std::path::Path::new(&output).exists() {
|
||||
true => { statuses.push(format!("skipping {} as it already exists", &output)); },
|
||||
false => {
|
||||
let cur = lib::video::clip_async(&output, &file, *content_span).await;
|
||||
if cur.is_err() {
|
||||
statuses.push(format!("failed to clipify {} at {}..{}: {}", &file, &content_span.start, &content_span.stop, cur.err().unwrap()));
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
match last_err {
|
||||
Some(msg) => msg,
|
||||
None => {
|
||||
match opener::open(d.clone()) {
|
||||
Ok(_) => d,
|
||||
Err(msg) => format!("failed to open clipify result: {}", msg),
|
||||
}
|
||||
},
|
||||
let _ = opener::open(d.clone());
|
||||
match statuses.len() {
|
||||
_ => statuses.join(", "),
|
||||
0 => d,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue