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!"
|
// 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 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 processing = use_state(cx, || false);
|
||||||
let analysis = use_state(cx, || Analysis::new());
|
let analysis = use_state(cx, || Analysis::new());
|
||||||
let a_css = String::from_utf8_lossy(include_bytes!("./style.css"));
|
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 |_| {
|
input { r#type: "button", value: "analyze", disabled: file.get().len() == 0 || *processing.get(), onclick: move |_| {
|
||||||
cx.spawn({
|
cx.spawn({
|
||||||
let file = file.to_owned();
|
let file = file.to_owned();
|
||||||
let status = status.to_owned();
|
let analyze_status = analyze_status.to_owned();
|
||||||
let processing = processing.to_owned();
|
let processing = processing.to_owned();
|
||||||
let analysis = analysis.to_owned();
|
let analysis = analysis.to_owned();
|
||||||
|
|
||||||
async move {
|
async move {
|
||||||
processing.set(true);
|
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;
|
let analyzed = analyze(file.get().clone()).await;
|
||||||
if analyzed.err.len() > 0 {
|
if analyzed.err.len() > 0 {
|
||||||
status.set(analyzed.err.clone());
|
analyze_status.set(analyzed.err.clone());
|
||||||
} else {
|
} else {
|
||||||
status.set(format!(
|
analyze_status.set(format!(
|
||||||
"found {} clips to keep and {} clips to drop",
|
"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(),
|
||||||
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 {}
|
br {}
|
||||||
|
div { analyze_status.get().clone() }
|
||||||
}
|
}
|
||||||
div {
|
div {
|
||||||
form {
|
form {
|
||||||
|
|
@ -88,14 +86,14 @@ fn App(cx: Scope) -> Element {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
status.set(format!("clipifying {:?}...", content_spans));
|
clipify_status.set(format!("clipifying {:?}...", content_spans));
|
||||||
let file = file.get().clone();
|
let file = file.get().clone();
|
||||||
to_owned![status];
|
to_owned![clipify_status];
|
||||||
to_owned![processing];
|
to_owned![processing];
|
||||||
async move {
|
async move {
|
||||||
processing.set(true);
|
processing.set(true);
|
||||||
let f = clipify(file, content_spans).await;
|
let f = clipify(file, content_spans).await;
|
||||||
status.set(f);
|
clipify_status.set(f);
|
||||||
processing.set(false);
|
processing.set(false);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
@ -119,6 +117,8 @@ fn App(cx: Scope) -> Element {
|
||||||
})
|
})
|
||||||
hr {}
|
hr {}
|
||||||
h3 { "4. Submit your re-clip" }
|
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 }
|
input { r#type: "submit", value: "clipify selected spans", disabled: file.get().len() == 0 || *processing.get() || analysis.get().result.len() == 0 }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -205,23 +205,24 @@ async fn analyze(file: String) -> Analysis {
|
||||||
|
|
||||||
async fn clipify(file: String, content_spans: Vec<lib::video::ContentSpan>) -> String {
|
async fn clipify(file: String, content_spans: Vec<lib::video::ContentSpan>) -> String {
|
||||||
let d = format!("{}.d", &file);
|
let d = format!("{}.d", &file);
|
||||||
let mut last_err = None;
|
let mut statuses = vec![];
|
||||||
for content_span in content_spans.iter() {
|
for content_span in content_spans.iter() {
|
||||||
let output = format!("{}/{}.mp4", &d, content_span.start);
|
let output = format!("{}/{}.mp4", &d, content_span.start);
|
||||||
|
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;
|
let cur = lib::video::clip_async(&output, &file, *content_span).await;
|
||||||
if cur.is_err() {
|
if cur.is_err() {
|
||||||
last_err = Some(format!("failed to clipify {} at {}..{}: {}", &file, &content_span.start, &content_span.stop, cur.err().unwrap()));
|
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,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const a_png: &str = r"iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==";
|
const a_png: &str = r"iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==";
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue