show drops woo
parent
a7581da4d1
commit
3f7004cc06
123
src/src/main.rs
123
src/src/main.rs
|
|
@ -13,7 +13,7 @@ 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 analysis = use_state(cx, Vec::<Analyzed>::new);
|
||||
let analysis = use_state(cx, Analysis::new);
|
||||
let status = use_state(cx, String::new);
|
||||
cx.render(rsx! {
|
||||
header {
|
||||
|
|
@ -41,8 +41,19 @@ fn App(cx: Scope) -> Element {
|
|||
input { r#type: "button", value: "analyze", disabled: file.get().len() == 0, onclick: move |evt| {
|
||||
to_owned![file];
|
||||
to_owned![analysis];
|
||||
to_owned![status];
|
||||
async move {
|
||||
analysis.set(analyze(file.get().clone()));
|
||||
let analyzed = analyze(file.get().clone());
|
||||
if analyzed.err.len() > 0 {
|
||||
status.set(analyzed.err.clone());
|
||||
} else {
|
||||
status.set(format!(
|
||||
"found {} clips to keep and {} clips to drop",
|
||||
analyzed.with_content.len(),
|
||||
analyzed.without_content.len(),
|
||||
));
|
||||
}
|
||||
analysis.set(analyzed);
|
||||
}
|
||||
}}
|
||||
input { r#type: "button", value: "clipify", disabled: file.get().len() == 0, onclick: move |evt| {
|
||||
|
|
@ -59,54 +70,100 @@ fn App(cx: Scope) -> Element {
|
|||
br {}
|
||||
}
|
||||
div {
|
||||
analysis.get().iter().map(|a| {
|
||||
rsx! {
|
||||
p {
|
||||
"{a.start}..{a.stop}: "
|
||||
br {}
|
||||
img { src: "data:image/png;base64, {a.screenshot}" }
|
||||
h3 { "Clips to Keep" }
|
||||
div {
|
||||
analysis.get().with_content.iter().map(|a| {
|
||||
rsx! {
|
||||
p {
|
||||
"{a.start}..{a.stop}: "
|
||||
br {}
|
||||
img { src: "data:image/png;base64, {a.screenshot}" }
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
div {
|
||||
h3 { "Clips to Remove" }
|
||||
div {
|
||||
analysis.get().without_content.iter().map(|a| {
|
||||
rsx! {
|
||||
p {
|
||||
"{a.start}..{a.stop}: "
|
||||
br {}
|
||||
img { src: "data:image/png;base64, {a.screenshot}" }
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
struct Analysis {
|
||||
with_content: Vec<Analyzed>,
|
||||
without_content: Vec<Analyzed>,
|
||||
err: String,
|
||||
}
|
||||
|
||||
impl Analysis {
|
||||
fn new() -> Self {
|
||||
Self{
|
||||
with_content: vec![],
|
||||
without_content: vec![],
|
||||
err: "".to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct Analyzed {
|
||||
start: String,
|
||||
stop: String,
|
||||
screenshot: String,
|
||||
}
|
||||
|
||||
fn analyze(file: String) -> Vec<Analyzed> {
|
||||
fn analyze(file: String) -> Analysis {
|
||||
let content_spans = lib::video::inspect(&file); // TODO desktop
|
||||
//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(),
|
||||
}];
|
||||
return Analysis{
|
||||
with_content: vec![],
|
||||
without_content: vec![],
|
||||
err: format!("failed to analyze {}: {}", file, content_spans.err().unwrap()),
|
||||
};
|
||||
}
|
||||
let content_spans = content_spans.unwrap();
|
||||
|
||||
let mut non_content_spans = vec![];
|
||||
if let Some(first_content_span) = content_spans.iter().nth(0) {
|
||||
non_content_spans.push(lib::video::ContentSpan{start: 0.0, stop: first_content_span.start});
|
||||
}
|
||||
for i in 1..content_spans.len() {
|
||||
non_content_spans.push(lib::video::ContentSpan{
|
||||
start: content_spans[i-1].stop,
|
||||
stop: content_spans[i].start,
|
||||
});
|
||||
}
|
||||
|
||||
let screenshot = |content_span: &lib::video::ContentSpan| -> Analyzed {
|
||||
let ts = (content_span.start + content_span.stop) / 2.0;
|
||||
Analyzed {
|
||||
start: content_span.start.to_string(),
|
||||
stop: content_span.stop.to_string(),
|
||||
screenshot: match lib::video::screenshot_png(&file, ts) {
|
||||
Ok(png) => general_purpose::STANDARD.encode(&png),
|
||||
Err(_) => a_png.to_string(),
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Analysis{
|
||||
with_content: content_spans.iter().map(screenshot).collect(),
|
||||
without_content: non_content_spans.iter().map(screenshot).collect(),
|
||||
err: "".to_string(),
|
||||
}
|
||||
content_spans.unwrap().iter()
|
||||
.map(|content_span| {
|
||||
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 + content_span.stop) / 2.0,
|
||||
) {
|
||||
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) -> String {
|
||||
|
|
|
|||
Loading…
Reference in New Issue