50 lines
1.3 KiB
Python
50 lines
1.3 KiB
Python
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)
|