Add YAPF style + ignore, and format tracked Python files

This commit is contained in:
2025-12-29 18:42:02 -08:00
parent c019c00aed
commit 507946a3e4
108 changed files with 11664 additions and 6494 deletions

View File

@@ -28,23 +28,32 @@ import pipeline as ctx
CMDLET = Cmdlet(
name="trim-file",
summary="Trim a media file using ffmpeg.",
usage="trim-file [-path <path>] [-input <path-or-url>] -range <start-end> [-outdir <dir>] [-delete]",
usage=
"trim-file [-path <path>] [-input <path-or-url>] -range <start-end> [-outdir <dir>] [-delete]",
arg=[
CmdletArg("-path", description="Path to the file (optional if piped)."),
CmdletArg("-path",
description="Path to the file (optional if piped)."),
CmdletArg(
"-input",
description="Override input media source (path or URL). Useful when piping store metadata but trimming from an mpv stream URL.",
description=
"Override input media source (path or URL). Useful when piping store metadata but trimming from an mpv stream URL.",
),
CmdletArg(
"-range",
required=True,
description="Time range to trim (e.g. '3:45-3:55', '00:03:45-00:03:55', or '1h3m-1h10m30s').",
description=
"Time range to trim (e.g. '3:45-3:55', '00:03:45-00:03:55', or '1h3m-1h10m30s').",
),
CmdletArg(
"-outdir",
description="Output directory for the clip (defaults to source folder for local files; otherwise uses config temp/videos).",
description=
"Output directory for the clip (defaults to source folder for local files; otherwise uses config temp/videos).",
),
CmdletArg(
"-delete",
type="flag",
description="Delete the original file after trimming."
),
CmdletArg("-delete", type="flag", description="Delete the original file after trimming."),
],
detail=[
"Creates a new file with 'clip_' prefix in the filename.",
@@ -153,7 +162,12 @@ def _extract_store_name(item: Any) -> Optional[str]:
def _persist_alt_relationship(
*, config: Dict[str, Any], store_name: str, alt_hash: str, king_hash: str
*,
config: Dict[str,
Any],
store_name: str,
alt_hash: str,
king_hash: str
) -> None:
"""Persist directional alt -> king relationship in the given backend."""
try:
@@ -169,17 +183,21 @@ def _persist_alt_relationship(
# Folder-backed local DB
try:
if (
type(backend).__name__ == "Folder"
and hasattr(backend, "location")
and callable(getattr(backend, "location"))
):
if (type(backend).__name__ == "Folder" and hasattr(backend,
"location")
and callable(getattr(backend,
"location"))):
from API.folder import API_folder_store
from pathlib import Path
root = Path(str(backend.location())).expanduser()
with API_folder_store(root) as db:
db.set_relationship_by_hash(alt_norm, king_norm, "alt", bidirectional=False)
db.set_relationship_by_hash(
alt_norm,
king_norm,
"alt",
bidirectional=False
)
return
except Exception:
pass
@@ -194,7 +212,10 @@ def _persist_alt_relationship(
def _trim_media(
input_source: str, output_path: Path, start_seconds: float, duration_seconds: float
input_source: str,
output_path: Path,
start_seconds: float,
duration_seconds: float
) -> bool:
"""Trim media using ffmpeg.
@@ -276,7 +297,9 @@ def _run(result: Any, args: Sequence[str], config: Dict[str, Any]) -> int:
# If path arg provided, add it to inputs
if path_arg:
inputs.append({"path": path_arg})
inputs.append({
"path": path_arg
})
if not inputs:
log("No input files provided.", file=sys.stderr)
@@ -317,13 +340,13 @@ def _run(result: Any, args: Sequence[str], config: Dict[str, Any]) -> int:
if outdir_arg:
output_dir = Path(str(outdir_arg)).expanduser()
elif store_name:
from config import resolve_output_dir
from SYS.config import resolve_output_dir
output_dir = resolve_output_dir(config or {})
elif path_obj is not None:
output_dir = path_obj.parent
else:
from config import resolve_output_dir
from SYS.config import resolve_output_dir
output_dir = resolve_output_dir(config or {})
@@ -450,7 +473,9 @@ def _run(result: Any, args: Sequence[str], config: Dict[str, Any]) -> int:
# Best-effort resolve stored path for folder backends.
try:
if type(backend).__name__ == "Folder" and hasattr(backend, "get_file"):
if type(backend).__name__ == "Folder" and hasattr(
backend,
"get_file"):
p = backend.get_file(str(stored_hash))
if isinstance(p, Path):
stored_path = str(p)
@@ -459,7 +484,10 @@ def _run(result: Any, args: Sequence[str], config: Dict[str, Any]) -> int:
except Exception:
stored_path = None
except Exception as exc:
log(f"Failed to add clip to store '{store_name}': {exc}", file=sys.stderr)
log(
f"Failed to add clip to store '{store_name}': {exc}",
file=sys.stderr
)
# If we stored it, persist relationship alt -> king in that store.
if stored_store and stored_hash and source_hash: