Add regex-based path preprocessing for playlist sync

This commit is contained in:
Koha9
2025-11-25 21:33:04 +09:00
parent d7f00408e5
commit 0ad64216f5
7 changed files with 220 additions and 1 deletions
+9
View File
@@ -15,6 +15,7 @@ class ServerConfig:
self.url = ""
self.scheme = "https"
self.port = "32400"
self.path_rules: list[dict[str, str]] = []
self.load()
def load(self) -> None:
@@ -37,6 +38,7 @@ class ServerConfig:
self.url = config.get("server_url", "")
self.scheme = config.get("server_scheme", "https")
self.port = config.get("server_port", "32400")
self.path_rules = config.get("path_rules", []) or []
logger.info(f"Server config loaded: {self.__dict__}")
def save(self):
@@ -46,6 +48,7 @@ class ServerConfig:
"server_url": self.url,
"server_scheme": self.scheme,
"server_port": self.port,
"path_rules": self.path_rules,
}
with open(CONFIG_PATH, "w", encoding="utf-8") as f:
json.dump(config, f, indent=4, ensure_ascii=False)
@@ -70,6 +73,9 @@ class ServerConfig:
raise ValueError("Invalid theme. Must be 'auto', 'dark', or 'light'.")
self.theme = theme
def set_path_rules(self, path_rules: list[dict[str, str]]) -> None:
self.path_rules = path_rules or []
def set_and_save_config(
self,
theme: str = None,
@@ -77,6 +83,7 @@ class ServerConfig:
url: str = None,
scheme: str = None,
port: str = None,
path_rules: list[dict[str, str]] | None = None,
) -> None:
if theme is not None:
self.set_theme(theme)
@@ -88,6 +95,8 @@ class ServerConfig:
self.set_scheme(scheme)
if port is not None:
self.set_port(port)
if path_rules is not None:
self.set_path_rules(path_rules)
self.save()