ADD configuration loading from user and default config files
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
[connection]
|
[obs]
|
||||||
host = "localhost"
|
host = "localhost"
|
||||||
port = 4455
|
port = 4455
|
||||||
password = "6BQWrpHLbyJxNLPJ"
|
password = "6BQWrpHLbyJxNLPJ"
|
||||||
@@ -11,4 +11,7 @@ dependencies = [
|
|||||||
|
|
||||||
[project.scripts]
|
[project.scripts]
|
||||||
rewind = "rewind.clip:main"
|
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
|
import subprocess
|
||||||
|
|
||||||
from rewind.video import get_duration
|
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
|
INTERVAL = 10
|
||||||
MAX_AGE_SECONDS = 60 * 60 * 1
|
MAX_AGE_SECONDS = 60 * 60 * 1
|
||||||
@@ -16,9 +16,9 @@ running = True
|
|||||||
def open_obs():
|
def open_obs():
|
||||||
subprocess.Popen(["obs", "--minimize-to-tray"])
|
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:
|
try:
|
||||||
con = obs.ReqClient()
|
con = obs.ReqClient(host=host, port=port, password=password)
|
||||||
return con
|
return con
|
||||||
except ConnectionRefusedError:
|
except ConnectionRefusedError:
|
||||||
print("Could not connect to OBS. Is it running and is the WebSocket server enabled?")
|
print("Could not connect to OBS. Is it running and is the WebSocket server enabled?")
|
||||||
@@ -72,7 +72,9 @@ def main() -> None:
|
|||||||
|
|
||||||
open_obs()
|
open_obs()
|
||||||
time.sleep(5)
|
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:
|
if con is None:
|
||||||
return
|
return
|
||||||
recording_dir = con.get_record_directory().record_directory
|
recording_dir = con.get_record_directory().record_directory
|
||||||
|
|||||||
@@ -1,7 +1,18 @@
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import os, json
|
import os, json, tomllib
|
||||||
|
from importlib import resources
|
||||||
|
|
||||||
APP_NAME = "rewind"
|
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:
|
def state_dir() -> Path:
|
||||||
base = os.path.expanduser("~/.local/share")
|
base = os.path.expanduser("~/.local/share")
|
||||||
|
|||||||
Reference in New Issue
Block a user