fix: double entry of OBS files into state upon startup
This commit is contained in:
@@ -8,13 +8,13 @@ import logging
|
|||||||
import json
|
import json
|
||||||
import shutil
|
import shutil
|
||||||
|
|
||||||
|
from threading import Lock
|
||||||
from watchdog.observers import Observer
|
from watchdog.observers import Observer
|
||||||
from watchdog.events import FileSystemEventHandler
|
from watchdog.events import FileSystemEventHandler
|
||||||
from rewind.paths import load_config
|
from rewind.paths import load_config
|
||||||
from rewind.core import mark, marker_exists, remove_marker
|
from rewind.core import mark, marker_exists, remove_marker
|
||||||
from rewind.state import add_file_to_state, create_state_file_if_needed, cleanup_state_files
|
from rewind.state import add_file_to_state, create_state_file_if_needed, cleanup_state_files
|
||||||
|
|
||||||
INTERVAL = 10
|
|
||||||
running = True
|
running = True
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@@ -22,9 +22,13 @@ logger.setLevel(logging.DEBUG)
|
|||||||
logging.basicConfig(format="%(levelname)s:%(name)s:%(message)s")
|
logging.basicConfig(format="%(levelname)s:%(name)s:%(message)s")
|
||||||
logging.getLogger("obsws_python").setLevel(logging.CRITICAL)
|
logging.getLogger("obsws_python").setLevel(logging.CRITICAL)
|
||||||
|
|
||||||
|
INTERVAL = 10
|
||||||
SENTINEL_FILE = os.path.expanduser("~/.config/obs-studio/.sentinel")
|
SENTINEL_FILE = os.path.expanduser("~/.config/obs-studio/.sentinel")
|
||||||
OBS_MAX_RETRIES = 10
|
OBS_MAX_RETRIES = 10
|
||||||
|
|
||||||
|
seen_files = set()
|
||||||
|
seen_lock = Lock()
|
||||||
|
|
||||||
def open_obs():
|
def open_obs():
|
||||||
kill_command = subprocess.run(['pkill', 'obs'])
|
kill_command = subprocess.run(['pkill', 'obs'])
|
||||||
if kill_command.returncode not in [0, 1]:
|
if kill_command.returncode not in [0, 1]:
|
||||||
@@ -107,6 +111,11 @@ class Handler(FileSystemEventHandler):
|
|||||||
if not event.src_path.endswith(".ts"):
|
if not event.src_path.endswith(".ts"):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
with seen_lock:
|
||||||
|
if event.src_path in seen_files:
|
||||||
|
return
|
||||||
|
seen_files.add(event.src_path)
|
||||||
|
|
||||||
add_file_to_state(event.src_path)
|
add_file_to_state(event.src_path)
|
||||||
logger.info(f"Added new file to state: {event.src_path}")
|
logger.info(f"Added new file to state: {event.src_path}")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user