Enhance Avisynth video workflow and metadata tools
This commit is contained in:
+13
-12
@@ -5,6 +5,7 @@ import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
from tools.exiftool import run_exiftool_command
|
||||
from tools.filesystem import unique_path
|
||||
|
||||
|
||||
EXCLUDED_COPY_TAGS = [
|
||||
@@ -66,9 +67,16 @@ def copy_meaningful_metadata(
|
||||
exiftool: str,
|
||||
source: Path,
|
||||
destination: Path,
|
||||
*,
|
||||
extra_excluded_tags: list[str] | None = None,
|
||||
) -> None:
|
||||
if destination.suffix.lower() in {".mp4", ".mov"}:
|
||||
copy_meaningful_metadata_with_exiftool(exiftool, source, destination)
|
||||
copy_meaningful_metadata_with_exiftool(
|
||||
exiftool,
|
||||
source,
|
||||
destination,
|
||||
extra_excluded_tags=extra_excluded_tags,
|
||||
)
|
||||
return
|
||||
copy_container_metadata_with_ffmpeg(source, destination)
|
||||
|
||||
@@ -77,6 +85,8 @@ def copy_meaningful_metadata_with_exiftool(
|
||||
exiftool: str,
|
||||
source: Path,
|
||||
destination: Path,
|
||||
*,
|
||||
extra_excluded_tags: list[str] | None = None,
|
||||
) -> None:
|
||||
args = [
|
||||
"-overwrite_original",
|
||||
@@ -84,6 +94,7 @@ def copy_meaningful_metadata_with_exiftool(
|
||||
str(source),
|
||||
"-all:all",
|
||||
*EXCLUDED_COPY_TAGS,
|
||||
*(extra_excluded_tags or []),
|
||||
str(destination),
|
||||
]
|
||||
run_exiftool_command(
|
||||
@@ -102,7 +113,7 @@ def copy_container_metadata_with_ffmpeg(source: Path, destination: Path) -> None
|
||||
return
|
||||
|
||||
temp_output = destination.with_name(f"{destination.stem}.metadata-copy{destination.suffix}")
|
||||
temp_output = _unique_path(temp_output)
|
||||
temp_output = unique_path(temp_output)
|
||||
command = [
|
||||
ffmpeg,
|
||||
"-y",
|
||||
@@ -127,13 +138,3 @@ def copy_container_metadata_with_ffmpeg(source: Path, destination: Path) -> None
|
||||
finally:
|
||||
if temp_output.exists():
|
||||
temp_output.unlink()
|
||||
|
||||
|
||||
def _unique_path(path: Path) -> Path:
|
||||
if not path.exists():
|
||||
return path
|
||||
for index in range(1, 10000):
|
||||
candidate = path.with_name(f"{path.stem}-{index}{path.suffix}")
|
||||
if not candidate.exists():
|
||||
return candidate
|
||||
raise RuntimeError(f"Could not find a unique temporary path for {path}")
|
||||
|
||||
Reference in New Issue
Block a user