add asked questions to project.toml

This commit is contained in:
Dominic 2024-05-25 14:25:23 +02:00
parent 1e7f5f95cd
commit 8b57b97c80
Signed by: msrd0
GPG key ID: AAF7C8430CA3345D

View file

@ -172,9 +172,15 @@ struct ProjectSource {
start: Option<Time>,
#[serde_as(as = "Option<DisplayFromStr>")]
end: Option<Time>,
#[serde(default)]
#[serde_as(as = "Vec<(DisplayFromStr, DisplayFromStr)>")]
fast: Vec<(Time, Time)>,
#[serde(default)]
#[serde_as(as = "Vec<(DisplayFromStr, DisplayFromStr, _)>")]
questions: Vec<(Time, Time, String)>,
metadata: Option<ProjectSourceMetadata>
}
@ -198,10 +204,22 @@ struct ProjectSourceMetadata {
#[derive(Default, Deserialize, Serialize)]
struct ProjectProgress {
#[serde(default)]
preprocessed: bool,
#[serde(default)]
asked_start_end: bool,
#[serde(default)]
asked_fast: bool,
#[serde(default)]
asked_questions: bool,
#[serde(default)]
rendered: bool,
#[serde(default)]
transcoded: BTreeSet<Resolution>
}
@ -209,10 +227,15 @@ fn ask(question: impl Display) -> String {
let mut stdout = io::stdout().lock();
let mut stdin = io::stdin().lock();
writeln!(stdout, "{} {question}", style("?").bold().yellow()).unwrap();
let mut line = String::new();
write!(stdout, "{} ", style(">").cyan()).unwrap();
write!(
stdout,
"{} {} ",
style(question).bold().magenta(),
style(">").cyan()
)
.unwrap();
stdout.flush().unwrap();
let mut line = String::new();
stdin.read_line(&mut line).unwrap();
line.trim().to_owned()
}
@ -288,7 +311,11 @@ fn main() {
print!(" {}", style(f).bold().yellow());
}
println!();
files = ask("Which source files would you like to use? (specify multiple files separated by whitespace)")
println!(
"{} Which source files would you like to use? (specify multiple files separated by whitespace)",
style("?").bold().yellow()
);
files = ask("files")
.split_ascii_whitespace()
.map(String::from)
.collect();
@ -308,6 +335,7 @@ fn main() {
start: None,
end: None,
fast: Vec::new(),
questions: Vec::new(),
metadata: None
},
progress: Default::default()
@ -366,6 +394,26 @@ fn main() {
fs::write(&project_path, toml::to_string(&project).unwrap().as_bytes()).unwrap();
}
// ask the user about questions from the audience that should be subtitled
if !project.progress.asked_questions {
println!(
"{} In which sections of the video were questions asked you want subtitles for? (0 to finish)",
style("?").bold().yellow()
);
loop {
let start = ask_time("from");
if start.seconds == 0 && start.micros == 0 {
break;
}
let end = ask_time("to ");
let text = ask("text");
project.source.questions.push((start, end, text));
}
project.progress.asked_questions = true;
fs::write(&project_path, toml::to_string(&project).unwrap().as_bytes()).unwrap();
}
// render the video
let mut videos = Vec::new();
videos.push(if project.progress.rendered {
@ -406,6 +454,10 @@ fn main() {
);
println!(" Videos:");
for v in &videos {
println!(" {} {v}", style("->").bold().cyan());
println!(
" {} {}",
style("->").bold().cyan(),
style(v).bold().yellow()
);
}
}