Spaces:
Running
Running
| import json | |
| import os | |
| from pathlib import Path | |
| from typing import Dict, Any | |
| class AppConfig: | |
| def __init__(self): | |
| self.config_dir = Path.home() / ".streamflow_iptv" | |
| self.config_file = self.config_dir / "config.json" | |
| self.data_dir = self.config_dir / "data" | |
| self.cache_dir = self.config_dir / "cache" | |
| self._ensure_directories() | |
| self._config = self._load_config() | |
| def _ensure_directories(self): | |
| self.config_dir.mkdir(exist_ok=True) | |
| self.data_dir.mkdir(exist_ok=True) | |
| self.cache_dir.mkdir(exist_ok=True) | |
| def _load_config(self) -> Dict[str, Any]: | |
| if self.config_file.exists(): | |
| with open(self.config_file, 'r', encoding='utf-8') as f: | |
| return json.load(f) | |
| return self._default_config() | |
| def _default_config(self) -> Dict[str, Any]: | |
| return { | |
| "theme": "dark", | |
| "accent_color": "#6366f1", | |
| "language": "pl", | |
| "player_volume": 80, | |
| "auto_refresh": False, | |
| "refresh_interval": 3600, | |
| "grid_columns": 4, | |
| "recent_limit": 20, | |
| "window_geometry": None | |
| } | |
| def save(self): | |
| with open(self.config_file, 'w', encoding='utf-8') as f: | |
| json.dump(self._config, f, indent=2, ensure_ascii=False) | |
| def get(self, key: str, default=None): | |
| return self._config.get(key, default) | |
| def set(self, key: str, value: Any): | |
| self._config[key] = value | |
| self.save() | |
| settings = AppConfig() |