From c0d9c90c7cff64198f65fe1cf8933eba1e12f2e8 Mon Sep 17 00:00:00 2001 From: Abdussamet Kocak Date: Thu, 25 Jun 2026 08:46:52 +0300 Subject: [PATCH] feat(upload-images-to-immich): add server and api key flags --- upload_images_to_immich.py | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/upload_images_to_immich.py b/upload_images_to_immich.py index 4b706a5..bbe8050 100755 --- a/upload_images_to_immich.py +++ b/upload_images_to_immich.py @@ -19,8 +19,13 @@ logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s: %(m logger = logging.getLogger(__name__) logging.getLogger("httpx").setLevel(logging.WARNING) -IMMICH_SERVER_URL = "https://ph.abdus.dev" # Replace with your Immich server URL -IMMICH_API_KEY = os.getenv("IMMICH_API_KEY") + +def must_get_env(var_name: str, default: str | None = None) -> str: + """Get environment variable or raise error if not set.""" + value = os.getenv(var_name, default) + if not value: + raise ValueError(f"Environment variable {var_name} is not set") + return value class ImmichClient: @@ -252,11 +257,28 @@ def list_images(folder_path: Path) -> List[Path]: def parse_args(): parser = argparse.ArgumentParser(description="Upload images to Immich, grouping them by actor name from filename") parser.add_argument("image_paths", type=Path, nargs="+", help="Path to the images to upload") + parser.add_argument( + "--api-key", + type=str, + default=os.getenv("IMMICH_API_KEY"), + required=True, + help="API key for Immich server", + ) + parser.add_argument( + "--server-url", + type=str, + default=os.getenv("IMMICH_SERVER_URL", "https://ph.abdus.dev"), + required=True, + help="URL of the Immich server", + ) return parser.parse_args() def main(): args = parse_args() + + immich = ImmichClient(base_url=args.server_url, api_key=args.api_key) + image_paths: list[Path] = args.image_paths if not image_paths: @@ -271,8 +293,6 @@ def main(): uploaded_dir = image_paths[0].parent / "_uploaded" uploaded_dir.mkdir(exist_ok=True) - immich = ImmichClient(IMMICH_SERVER_URL, IMMICH_API_KEY) - for image_path in image_paths: if not image_path.is_file(): logger.warning(f"Skipping non-file path: {image_path}")