Refactor shared script helpers

This commit is contained in:
ajp_anton
2026-06-08 02:55:31 +00:00
parent ae05bc9710
commit b6024d8b65
10 changed files with 855 additions and 356 deletions
+49
View File
@@ -0,0 +1,49 @@
from __future__ import annotations
import json
import subprocess
from pathlib import Path
from shutil import which
def require_exiftool() -> str:
executable = which("exiftool")
if executable:
return executable
raise RuntimeError(
"exiftool was not found on PATH. Install ExifTool and make sure the "
"'exiftool' command works before running this script."
)
def run_exiftool_json(executable: str, paths: list[Path]) -> list[dict]:
results: list[dict] = []
for start in range(0, len(paths), 80):
chunk = paths[start : start + 80]
command = [
executable,
"-j",
"-G",
"-api",
"QuickTimeUTC=1",
"-charset",
"filename=UTF8",
*[str(path) for path in chunk],
]
completed = subprocess.run(command, check=True, capture_output=True, text=True)
results.extend(json.loads(completed.stdout or "[]"))
return results
def run_exiftool_write(executable: str, path: Path, args: list[str]) -> None:
if not args:
return
command = [
executable,
"-overwrite_original",
"-charset",
"filename=UTF8",
*args,
str(path),
]
subprocess.run(command, check=True)