170 lines
4.9 KiB
Rust
170 lines
4.9 KiB
Rust
use serde::{Deserialize, Serialize};
|
|
use std::path::PathBuf;
|
|
|
|
pub const FORMATS: &[&str] = &[
|
|
"html",
|
|
"typst",
|
|
"pdf",
|
|
"pdf-dense",
|
|
"md",
|
|
"txt",
|
|
"json",
|
|
"ontime",
|
|
];
|
|
pub const NOTES: &[&str] = &[
|
|
"Duration applies PowerPoint trimming per video occurrence. Original is the media file duration.",
|
|
"Videos linked externally are not downloaded. Slide numbers follow presentation order.",
|
|
];
|
|
|
|
#[derive(Clone, Debug, Serialize, Deserialize, Default, PartialEq)]
|
|
pub struct Video {
|
|
pub slides: Vec<usize>,
|
|
pub duration_seconds: Option<f64>,
|
|
pub name: String,
|
|
pub size_bytes: u64,
|
|
pub resolution: String,
|
|
pub codec: String,
|
|
pub archive_path: String,
|
|
pub extracted_file: Option<String>,
|
|
}
|
|
|
|
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
|
|
pub struct Settings {
|
|
pub slide: Option<usize>,
|
|
pub shape_id: Option<String>,
|
|
pub trim_start_seconds: f64,
|
|
pub trim_end_seconds: f64,
|
|
pub playback_status: String,
|
|
pub playback_notes: Vec<String>,
|
|
}
|
|
impl Default for Settings {
|
|
fn default() -> Self {
|
|
Self {
|
|
slide: None,
|
|
shape_id: None,
|
|
trim_start_seconds: 0.0,
|
|
trim_end_seconds: 0.0,
|
|
playback_status: "normal".into(),
|
|
playback_notes: vec![],
|
|
}
|
|
}
|
|
}
|
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
|
pub struct Playback {
|
|
#[serde(flatten)]
|
|
pub video: Video,
|
|
#[serde(flatten)]
|
|
pub settings: Settings,
|
|
pub original_duration_seconds: Option<f64>,
|
|
pub ontime_eligible: bool,
|
|
}
|
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
|
pub struct ReportGroup {
|
|
pub title: String,
|
|
pub start: usize,
|
|
pub end: usize,
|
|
}
|
|
#[derive(Clone, Debug, Serialize, Deserialize, Default)]
|
|
pub struct Report {
|
|
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
|
pub groups: Vec<ReportGroup>,
|
|
pub presentation: String,
|
|
pub embedded_videos: usize,
|
|
pub total_size_bytes: u64,
|
|
pub total_duration_seconds: f64,
|
|
pub total_media_duration_seconds: f64,
|
|
pub known_durations: usize,
|
|
pub known_playback_durations: usize,
|
|
pub playbacks: Vec<Playback>,
|
|
pub videos: Vec<Video>,
|
|
pub external_media_slides: Vec<usize>,
|
|
pub notes: Vec<String>,
|
|
}
|
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
|
#[serde(default)]
|
|
pub struct Options {
|
|
pub source: PathBuf,
|
|
pub additional_sources: Vec<PathBuf>,
|
|
pub output: Option<PathBuf>,
|
|
pub extract_only: bool,
|
|
pub timings_only: bool,
|
|
pub overwrite: bool,
|
|
pub formats: Vec<String>,
|
|
pub ffprobe: Option<PathBuf>,
|
|
}
|
|
impl Default for Options {
|
|
fn default() -> Self {
|
|
Self {
|
|
source: PathBuf::new(),
|
|
additional_sources: vec![],
|
|
output: None,
|
|
extract_only: false,
|
|
timings_only: false,
|
|
overwrite: false,
|
|
formats: vec!["md".into(), "ontime".into()],
|
|
ffprobe: None,
|
|
}
|
|
}
|
|
}
|
|
impl Options {
|
|
pub fn output_dir(&self) -> PathBuf {
|
|
self.output.clone().unwrap_or_else(|| {
|
|
self.source.with_file_name(format!(
|
|
"{}_videos",
|
|
self.source
|
|
.file_stem()
|
|
.unwrap_or_default()
|
|
.to_string_lossy()
|
|
))
|
|
})
|
|
}
|
|
pub fn validate(&self) -> anyhow::Result<()> {
|
|
anyhow::ensure!(
|
|
!(self.extract_only && self.timings_only),
|
|
"Choose only one extraction mode."
|
|
);
|
|
for source in std::iter::once(&self.source).chain(&self.additional_sources) {
|
|
anyhow::ensure!(
|
|
source.is_dir()
|
|
|| (source.is_file()
|
|
&& source
|
|
.extension()
|
|
.is_some_and(|s| s.eq_ignore_ascii_case("pptx"))),
|
|
"Choose an existing .pptx file or folder: {}",
|
|
source.display()
|
|
);
|
|
}
|
|
anyhow::ensure!(
|
|
self.extract_only || !self.formats.is_empty(),
|
|
"Select at least one report."
|
|
);
|
|
for format in &self.formats {
|
|
anyhow::ensure!(
|
|
FORMATS.contains(&format.as_str()),
|
|
"Unknown report format: {format}"
|
|
);
|
|
}
|
|
Ok(())
|
|
}
|
|
}
|
|
pub fn formats(values: &[String]) -> anyhow::Result<Vec<String>> {
|
|
let mut out = vec![];
|
|
for group in values {
|
|
for item in group.split(',') {
|
|
let item = item.trim().to_lowercase();
|
|
let expanded: Vec<&str> = if item == "all" {
|
|
FORMATS.to_vec()
|
|
} else {
|
|
vec![&item]
|
|
};
|
|
for item in expanded {
|
|
anyhow::ensure!(FORMATS.contains(&item), "Unknown report format: {item}");
|
|
if !out.iter().any(|s| s == item) {
|
|
out.push(item.to_string());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
Ok(out)
|
|
}
|