#!/usr/bin/env python3 """ Show metadata for one file. Drag a file onto this script, or run: python3 view_metadata.py path/to/file/or/directory [...] If more than one file is provided or found, only the first file is shown. """ from __future__ import annotations import subprocess import sys from pathlib import Path from tools.console import pause_if_interactive from tools.exiftool import require_exiftool from tools.filesystem import first_file_from_path def choose_file(args: list[str]) -> Path | None: for arg in args: file_path = first_file_from_path(Path(arg)) if file_path is not None: return file_path return None def run(argv: list[str]) -> int: if len(argv) < 2: print("Usage: python3 view_metadata.py path/to/file/or/directory [...]") return 2 try: exiftool = require_exiftool() except RuntimeError as exc: print(exc) return 1 file_path = choose_file(argv[1:]) if file_path is None: print("No file found.") return 1 print(f"Showing metadata for: {file_path}\n", flush=True) command = [ exiftool, "-a", "-u", "-ee", "-G0:1", "-s", "-charset", "filename=UTF8", str(file_path), ] return subprocess.run(command).returncode def main(argv: list[str]) -> int: try: return run(argv) finally: pause_if_interactive() if __name__ == "__main__": raise SystemExit(main(sys.argv))