ADD configuration loading from user and default config files
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
[connection]
|
||||
[obs]
|
||||
host = "localhost"
|
||||
port = 4455
|
||||
password = "6BQWrpHLbyJxNLPJ"
|
||||
@@ -11,4 +11,7 @@ dependencies = [
|
||||
|
||||
[project.scripts]
|
||||
rewind = "rewind.clip:main"
|
||||
rewind-daemon = "rewind.daemon:main"
|
||||
rewind-daemon = "rewind.daemon:main"
|
||||
|
||||
[tool.setuptools.package-data]
|
||||
rewind = ["config.toml"]
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user