#!/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 sys from pathlib import Path from tools.console import launch_terminal_if_needed, pause_if_interactive from tools.exiftool import require_exiftool, run_exiftool_command from tools.filesystem import first_file_from_path, input_paths 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: try: args = input_paths(argv) except RuntimeError as exc: print(exc) return 1 if not args: print("No inputs selected.") return 0 try: exiftool = require_exiftool() except RuntimeError as exc: print(exc) return 1 file_path = choose_file(args) if file_path is None: print("No file found.") return 1 print(f"Showing metadata for: {file_path}\n", flush=True) args = [ "-a", "-u", "-ee", "-G0:1", "-s", str(file_path), ] return run_exiftool_command(exiftool, args).returncode def main(argv: list[str]) -> int: if launch_terminal_if_needed(argv): return 0 try: return run(argv) finally: pause_if_interactive() if __name__ == "__main__": raise SystemExit(main(sys.argv))