app: open the clips grid
The clips screen lists the clips folder: one card per mp4 the user exported, newest first, with the clip's 16:9 stage, the champion it stars when its recording is in the loaded history, share, and a menu whose Delete removes the file. The folder read runs when the screen opens, and again when an export finishes on it. Computed highlights were the first plan for the grid, but a real history parses hundreds of timelines and some run to tens of MB, so the grid now reads only what the user actually exported.
This commit is contained in:
1 parent
fac1ec00da
commit
3f82f87a81
9 files changed
+577
-9
No files matched your search
@@ -13,8 +13,49 @@ use ffmpeg_sidecar::download::{
|
||||
use ffmpeg_sidecar::event::{FfmpegEvent, LogLevel};
|
||||
use ffmpeg_sidecar::paths::{sidecar_dir, sidecar_path};
|
||||
|
||||
use std::time::SystemTime;
|
||||
|
||||
use crate::daemon;
|
||||
|
||||
/// A clip the user exported: one file in the clips folder.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Clip {
|
||||
/// The file's name without `.mp4`, as the export named it: often `{recording}-clip`.
|
||||
pub name: String,
|
||||
/// The file, for playing it and for deleting it.
|
||||
pub path: PathBuf,
|
||||
/// When the export finished: the file's modified time.
|
||||
pub exported: Option<SystemTime>,
|
||||
/// Bytes on disk.
|
||||
pub bytes: u64,
|
||||
}
|
||||
|
||||
/// Every clip in the clips folder, newest export first. Only `.mp4` counts: the folder is
|
||||
/// where a half-finished export writes too, and a clip without its pictures is no clip.
|
||||
pub fn list_clips() -> Vec<Clip> {
|
||||
let Ok(entries) = std::fs::read_dir(clips_dir()) else {
|
||||
return Vec::new();
|
||||
};
|
||||
let mut clips: Vec<Clip> = entries
|
||||
.flatten()
|
||||
.filter_map(|entry| {
|
||||
let path = entry.path();
|
||||
if path.extension().and_then(|ext| ext.to_str()) != Some("mp4") {
|
||||
return None;
|
||||
}
|
||||
let meta = entry.metadata().ok()?;
|
||||
Some(Clip {
|
||||
name: path.file_stem()?.to_string_lossy().into_owned(),
|
||||
path: path.clone(),
|
||||
exported: meta.modified().ok(),
|
||||
bytes: meta.len(),
|
||||
})
|
||||
})
|
||||
.collect();
|
||||
clips.sort_by_key(|clip| std::cmp::Reverse(clip.exported));
|
||||
clips
|
||||
}
|
||||
|
||||
/// The clips folder beside the recordings.
|
||||
pub fn clips_dir() -> PathBuf {
|
||||
let dir = daemon::recordings_dir().join("clips");
|
||||
|
||||
Reference in new issue
Block a user