diff --git a/example.config.toml b/example.config.toml index 9b8a0bc..3087968 100644 --- a/example.config.toml +++ b/example.config.toml @@ -1,4 +1,4 @@ -[connection] +[obs] host = "localhost" port = 4455 password = "6BQWrpHLbyJxNLPJ" \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 6df303d..0b0680d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,4 +11,7 @@ dependencies = [ [project.scripts] rewind = "rewind.clip:main" -rewind-daemon = "rewind.daemon:main" \ No newline at end of file +rewind-daemon = "rewind.daemon:main" + +[tool.setuptools.package-data] +rewind = ["config.toml"] diff --git a/rewind/daemon.py b/rewind/daemon.py index aedc3fd..644aa16 100755 --- a/rewind/daemon.py +++ b/rewind/daemon.py @@ -7,7 +7,7 @@ import obsws_python as obs import subprocess from rewind.video import get_duration -from rewind.paths import load_state, write_state +from rewind.paths import load_state, write_state, load_config INTERVAL = 10 MAX_AGE_SECONDS = 60 * 60 * 1 @@ -16,9 +16,9 @@ running = True def open_obs(): subprocess.Popen(["obs", "--minimize-to-tray"]) -def open_obs_connection() -> obs.ReqClient | None: +def open_obs_connection(host: str, port: int, password: str) -> obs.ReqClient | None: try: - con = obs.ReqClient() + con = obs.ReqClient(host=host, port=port, password=password) return con except ConnectionRefusedError: print("Could not connect to OBS. Is it running and is the WebSocket server enabled?") @@ -72,7 +72,9 @@ def main() -> None: open_obs() time.sleep(5) - con = open_obs_connection() + + config = load_config() + con = open_obs_connection(config["obs"]["host"], config["obs"]["port"], config["obs"]["password"]) if con is None: return recording_dir = con.get_record_directory().record_directory diff --git a/rewind/paths.py b/rewind/paths.py index c681755..7a538c8 100644 --- a/rewind/paths.py +++ b/rewind/paths.py @@ -1,7 +1,18 @@ from pathlib import Path -import os, json +import os, json, tomllib +from importlib import resources APP_NAME = "rewind" +USER_CONFIG = Path.home() / ".rewind.toml" + +def load_config() -> dict: + if USER_CONFIG.exists(): + with USER_CONFIG.open("rb") as f: + return tomllib.load(f) + + # fallback to packaged default + with resources.files("rewind").joinpath("config.toml").open("rb") as f: + return tomllib.load(f) def state_dir() -> Path: base = os.path.expanduser("~/.local/share")