Refactor photo metadata workflow

This commit is contained in:
ajp_anton
2026-08-24 16:34:20 +00:00
parent 100cad1cb5
commit eb5937a629
15 changed files with 2111 additions and 1727 deletions
+6 -46
View File
@@ -1,11 +1,8 @@
from __future__ import annotations
import shutil
import subprocess
from pathlib import Path
from tools.exiftool import run_exiftool_command
from tools.filesystem import unique_path
EXCLUDED_COPY_TAGS = [
@@ -70,15 +67,12 @@ def copy_meaningful_metadata(
*,
extra_excluded_tags: list[str] | None = None,
) -> None:
if destination.suffix.lower() in {".mp4", ".mov"}:
copy_meaningful_metadata_with_exiftool(
exiftool,
source,
destination,
extra_excluded_tags=extra_excluded_tags,
)
return
copy_container_metadata_with_ffmpeg(source, destination)
copy_meaningful_metadata_with_exiftool(
exiftool,
source,
destination,
extra_excluded_tags=extra_excluded_tags,
)
def copy_meaningful_metadata_with_exiftool(
@@ -104,37 +98,3 @@ def copy_meaningful_metadata_with_exiftool(
capture_output=True,
text=True,
)
def copy_container_metadata_with_ffmpeg(source: Path, destination: Path) -> None:
ffmpeg = shutil.which("ffmpeg")
if not ffmpeg:
print(" metadata: ffmpeg not found; skipped best-effort metadata remux")
return
temp_output = destination.with_name(f"{destination.stem}.metadata-copy{destination.suffix}")
temp_output = unique_path(temp_output)
command = [
ffmpeg,
"-y",
"-hide_banner",
"-loglevel",
"error",
"-i",
str(destination),
"-i",
str(source),
"-map",
"0",
"-map_metadata",
"1",
"-c",
"copy",
str(temp_output),
]
try:
subprocess.run(command, check=True, capture_output=True, text=True)
temp_output.replace(destination)
finally:
if temp_output.exists():
temp_output.unlink()