from dataclasses import dataclass, asdict, field from pathlib import Path import json @dataclass class Config: # Immich server immich_url: str = "" immich_api_key: str = "" # Display image_duration: float = 10.0 transition_duration: float = 0.5 max_framerate: float = 30.0 auto_transition: bool = True display_size: str = "preview" # 'fullsize', 'preview', 'thumbnail' # Cache max_cache_assets: int = 100 # Albums data album_list: list[str] = field(default_factory=list) @classmethod def load(cls, filepath): with open(filepath, "r") as fp: return cls(**json.load(fp)) def save(self, filepath): Path(filepath).parent.mkdir(parents=True, exist_ok=True) # Create dir if not existing with open(filepath, "w") as fp: json.dump(asdict(self), fp, indent=2) def update(self, **config): for key, value in config.items(): setattr(self, key, value)