diff --git a/rewind/core.py b/rewind/core.py index 49a83f4..0405da0 100644 --- a/rewind/core.py +++ b/rewind/core.py @@ -78,8 +78,6 @@ def get_marker_timestamp(name: str) -> float: raise ValueError("Marker name does not exist") def print_markers() -> None: - _clean_old_markers(load_config()["record"]["max_record_time"]) - markers_file = os.path.join(os.path.dirname(__file__), "markers.json") if not os.path.exists(markers_file): print("No markers found.") @@ -167,20 +165,6 @@ def _concat_ts_files(file_list: list[str], start_offset: float, end_offset: floa subprocess.run(cmd) os.remove("file_list.txt") -def _clean_old_markers(max_age_seconds: float) -> None: - markers_file = os.path.join(os.path.dirname(__file__), "markers.json") - if not os.path.exists(markers_file): - return - - with open(markers_file, "r") as f: - markers = json.load(f) - - current_time = datetime.datetime.now().timestamp() - markers = [m for m in markers if current_time - m['timestamp'] <= max_age_seconds] - - with open(markers_file, "w") as f: - json.dump(markers, f, indent=4) - def get_duration(file_path: str) -> float: result = subprocess.run( ["ffprobe", "-v", "error", "-show_entries", diff --git a/rewind/daemon.py b/rewind/daemon.py index 52a79db..028fc95 100755 --- a/rewind/daemon.py +++ b/rewind/daemon.py @@ -6,6 +6,7 @@ import time import obsws_python as obs import subprocess import logging +import json from watchdog.observers import Observer from watchdog.events import FileSystemEventHandler @@ -68,6 +69,20 @@ def cleanup_physical_files(directory: str, max_age_seconds: int) -> None: os.remove(file_path) print(f"Removed old file: {file_path}") +def cleanup_markers(max_age_seconds: float) -> None: + markers_file = os.path.join(os.path.dirname(__file__), "markers.json") + if not os.path.exists(markers_file): + return + + with open(markers_file, "r") as f: + markers = json.load(f) + + current_time = datetime.datetime.now().timestamp() + markers = [m for m in markers if current_time - m['timestamp'] <= max_age_seconds] + + with open(markers_file, "w") as f: + json.dump(markers, f, indent=4) + def handle_shutdown(signum, frame): global running running = False @@ -79,6 +94,7 @@ class Handler(FileSystemEventHandler): print(f"Added new file to state: {event.src_path}") def main() -> None: + print("NEW") signal.signal(signal.SIGINT, handle_shutdown) signal.signal(signal.SIGTERM, handle_shutdown) @@ -101,6 +117,7 @@ def main() -> None: while running: cleanup_physical_files(recording_dir, config["record"]["max_record_time"]) cleanup_state_files() + cleanup_markers(config["record"]["max_record_time"]) time.sleep(INTERVAL) finally: stop_recording(con) diff --git a/rewind/paths.py b/rewind/paths.py index c510f0a..6d4987b 100644 --- a/rewind/paths.py +++ b/rewind/paths.py @@ -12,7 +12,6 @@ def get_config_dir() -> Path: base = os.environ.get("XDG_CONFIG_HOME", Path.home() / ".config") return Path(base) / APP_NAME - def load_config() -> dict: config_dir = get_config_dir() config_file = config_dir / CONFIG_NAME