doocus improvemnts
This commit is contained in:
@@ -11,10 +11,16 @@ from typing import Dict, Any, Optional
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
# Default run-folder name format. Tokens: {date} (YYYYMMDD), {run} (per-day
|
||||
# counter), {stem} (filename w/o ext), {name} (full filename incl. ext).
|
||||
DEFAULT_FOLDER_FORMAT = "{date}-{run:03d}-{stem}"
|
||||
|
||||
|
||||
class OutputManager:
|
||||
"""Manage output directories and manifest files for video processing."""
|
||||
|
||||
def __init__(self, video_path: Path, base_output_dir: str = "output", use_cache: bool = True):
|
||||
def __init__(self, video_path: Path, base_output_dir: str = "output",
|
||||
use_cache: bool = True, folder_format: str = DEFAULT_FOLDER_FORMAT):
|
||||
"""
|
||||
Initialize output manager.
|
||||
|
||||
@@ -22,10 +28,15 @@ class OutputManager:
|
||||
video_path: Path to the video file being processed
|
||||
base_output_dir: Base directory for all outputs
|
||||
use_cache: Whether to use existing directories if found
|
||||
folder_format: Run-folder name template. Tokens: {date}, {run},
|
||||
{stem}, {name}. When {run} is absent the counter is skipped and
|
||||
the expanded name is used directly (reuse-by-name = caching), which
|
||||
is how meetings land in a stable `<file>.meetus/` sidecar.
|
||||
"""
|
||||
self.video_path = video_path
|
||||
self.base_output_dir = Path(base_output_dir)
|
||||
self.use_cache = use_cache
|
||||
self.folder_format = folder_format or DEFAULT_FOLDER_FORMAT
|
||||
|
||||
# Find or create output directory
|
||||
self.output_dir = self._get_or_create_output_dir()
|
||||
@@ -34,16 +45,45 @@ class OutputManager:
|
||||
|
||||
logger.info(f"Output directory: {self.output_dir}")
|
||||
|
||||
def _has_run(self) -> bool:
|
||||
"""Whether the folder format uses the per-day {run} counter."""
|
||||
return "{run" in self.folder_format
|
||||
|
||||
def _expand(self, run: int = 1) -> str:
|
||||
"""Expand the folder-format template to a directory name."""
|
||||
return self.folder_format.format(
|
||||
date=datetime.now().strftime("%Y%m%d"),
|
||||
run=run,
|
||||
stem=self.video_path.stem,
|
||||
name=self.video_path.name,
|
||||
)
|
||||
|
||||
def _get_or_create_output_dir(self) -> Path:
|
||||
"""
|
||||
Get existing output directory or create a new one with incremental number.
|
||||
Get existing output directory or create one per the folder format.
|
||||
|
||||
With a {run} counter (the default) this reuses the most recent run for
|
||||
this video when caching, else creates the next-numbered folder. Without
|
||||
{run} (e.g. "{name}.meetus") the name is deterministic — reuse it when it
|
||||
exists (caching), else create it.
|
||||
|
||||
Returns:
|
||||
Path to output directory
|
||||
"""
|
||||
video_name = self.video_path.stem
|
||||
|
||||
# Look for existing directories if caching is enabled
|
||||
# Deterministic (no {run}) — stable name, reuse-by-name gives caching.
|
||||
if not self._has_run():
|
||||
dir_name = self._expand()
|
||||
output_dir = self.base_output_dir / dir_name
|
||||
if self.use_cache and output_dir.exists():
|
||||
logger.info(f"Found existing output: {dir_name}")
|
||||
else:
|
||||
output_dir.mkdir(parents=True, exist_ok=True)
|
||||
logger.info(f"Created new output directory: {dir_name}")
|
||||
return output_dir
|
||||
|
||||
# {run} counter (default): reuse most recent for this video, else next NNN.
|
||||
if self.use_cache and self.base_output_dir.exists():
|
||||
existing_dirs = sorted([
|
||||
d for d in self.base_output_dir.iterdir()
|
||||
@@ -76,7 +116,7 @@ class OutputManager:
|
||||
else:
|
||||
next_run = 1
|
||||
|
||||
dir_name = f"{date_str}-{next_run:03d}-{video_name}"
|
||||
dir_name = self._expand(run=next_run)
|
||||
output_dir = self.base_output_dir / dir_name
|
||||
output_dir.mkdir(parents=True, exist_ok=True)
|
||||
logger.info(f"Created new output directory: {dir_name}")
|
||||
|
||||
Reference in New Issue
Block a user