From a55403758db8e218908d31a94e589b91b7b7d9a2 Mon Sep 17 00:00:00 2001
From: Christoph Stahl <christoph.stahl@tu-dortmund.de>
Date: Sun, 12 Nov 2023 10:10:52 +0100
Subject: [PATCH] Switched from JSON config file to yaml

---
 pyproject.toml | 1 +
 syng/client.py | 8 ++++----
 syng/gui.py    | 6 +++---
 3 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/pyproject.toml b/pyproject.toml
index f2b9808..eff6d42 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -25,6 +25,7 @@ yt-dlp = "*"
 customtkinter = "^5.2.1"
 qrcode = "^7.4.2"
 pymediainfo = "^6.1.0"
+pyyaml = "^6.0.1"
 
 [build-system]
 requires = ["poetry-core"]
diff --git a/syng/client.py b/syng/client.py
index 15310f6..ea27b23 100644
--- a/syng/client.py
+++ b/syng/client.py
@@ -39,7 +39,7 @@ import tempfile
 from argparse import ArgumentParser
 from dataclasses import dataclass
 from dataclasses import field
-from json import load
+from yaml import load, Loader
 from traceback import print_exc
 from typing import Any
 from typing import Optional
@@ -385,7 +385,7 @@ async def start_client(config: dict[str, Any]) -> None:
     if "config" in config:
         last_song = (
             datetime.datetime.fromisoformat(config["config"]["last_song"])
-            if "last_song" in config["config"]
+            if "last_song" in config["config"] and config["config"]["last_song"]
             else None
         )
         state.config |= config["config"] | {"last_song": last_song}
@@ -423,14 +423,14 @@ def main() -> None:
 
     parser.add_argument("--room", "-r")
     parser.add_argument("--secret", "-s")
-    parser.add_argument("--config-file", "-C", default="syng-client.json")
+    parser.add_argument("--config-file", "-C", default="syng-client.yaml")
     parser.add_argument("--key", "-k", default=None)
     parser.add_argument("--server", "-S")
 
     args = parser.parse_args()
 
     with open(args.config_file, encoding="utf8") as file:
-        config = load(file)
+        config = load(file, Loader=Loader)
 
     if "config" not in config:
         config["config"] = {}
diff --git a/syng/gui.py b/syng/gui.py
index 7656296..5712662 100644
--- a/syng/gui.py
+++ b/syng/gui.py
@@ -1,5 +1,5 @@
 import builtins
-from json import load
+from yaml import load, Loader
 import customtkinter
 import qrcode
 import secrets
@@ -164,8 +164,8 @@ class SyngGui(customtkinter.CTk):
     def __init__(self):
         super().__init__(className="Syng")
 
-        with open("syng-client.json") as cfile:
-            loaded_config = load(cfile)
+        with open("syng-client.yaml") as cfile:
+            loaded_config = load(cfile, Loader=Loader)
         config = {"sources": {}, "config": default_config()}
         if "config" in loaded_config:
             config["config"] |= loaded_config["config"]