fix: markers only update upon calling rewind list - now update in daemon

This commit is contained in:
2026-01-27 23:30:23 +00:00
parent aae6540678
commit eb47077b8c
3 changed files with 17 additions and 17 deletions

View File

@@ -78,8 +78,6 @@ def get_marker_timestamp(name: str) -> float:
raise ValueError("Marker name does not exist") raise ValueError("Marker name does not exist")
def print_markers() -> None: def print_markers() -> None:
_clean_old_markers(load_config()["record"]["max_record_time"])
markers_file = os.path.join(os.path.dirname(__file__), "markers.json") markers_file = os.path.join(os.path.dirname(__file__), "markers.json")
if not os.path.exists(markers_file): if not os.path.exists(markers_file):
print("No markers found.") 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) subprocess.run(cmd)
os.remove("file_list.txt") 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: def get_duration(file_path: str) -> float:
result = subprocess.run( result = subprocess.run(
["ffprobe", "-v", "error", "-show_entries", ["ffprobe", "-v", "error", "-show_entries",

View File

@@ -6,6 +6,7 @@ import time
import obsws_python as obs import obsws_python as obs
import subprocess import subprocess
import logging import logging
import json
from watchdog.observers import Observer from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler from watchdog.events import FileSystemEventHandler
@@ -68,6 +69,20 @@ def cleanup_physical_files(directory: str, max_age_seconds: int) -> None:
os.remove(file_path) os.remove(file_path)
print(f"Removed old file: {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): def handle_shutdown(signum, frame):
global running global running
running = False running = False
@@ -79,6 +94,7 @@ class Handler(FileSystemEventHandler):
print(f"Added new file to state: {event.src_path}") print(f"Added new file to state: {event.src_path}")
def main() -> None: def main() -> None:
print("NEW")
signal.signal(signal.SIGINT, handle_shutdown) signal.signal(signal.SIGINT, handle_shutdown)
signal.signal(signal.SIGTERM, handle_shutdown) signal.signal(signal.SIGTERM, handle_shutdown)
@@ -101,6 +117,7 @@ def main() -> None:
while running: while running:
cleanup_physical_files(recording_dir, config["record"]["max_record_time"]) cleanup_physical_files(recording_dir, config["record"]["max_record_time"])
cleanup_state_files() cleanup_state_files()
cleanup_markers(config["record"]["max_record_time"])
time.sleep(INTERVAL) time.sleep(INTERVAL)
finally: finally:
stop_recording(con) stop_recording(con)

View File

@@ -12,7 +12,6 @@ def get_config_dir() -> Path:
base = os.environ.get("XDG_CONFIG_HOME", Path.home() / ".config") base = os.environ.get("XDG_CONFIG_HOME", Path.home() / ".config")
return Path(base) / APP_NAME return Path(base) / APP_NAME
def load_config() -> dict: def load_config() -> dict:
config_dir = get_config_dir() config_dir = get_config_dir()
config_file = config_dir / CONFIG_NAME config_file = config_dir / CONFIG_NAME