feat(upload-images-to-immich): add server and api key flags

This commit is contained in:
2026-06-25 08:46:52 +03:00
parent c199fe1c36
commit c0d9c90c7c
+24 -4
View File
@@ -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}")