RENAME clip.py to cli.py & RENAME video.py to core.py to better reflect purpose

In addition, added basic mark command
This commit is contained in:
2025-12-18 20:09:54 +00:00
parent f7b8910bd8
commit 3c870c7a69
4 changed files with 42 additions and 4 deletions

View File

@@ -11,7 +11,7 @@ dependencies = [
] ]
[project.scripts] [project.scripts]
rewind = "rewind.clip:main" rewind = "rewind.cli:main"
rewind-daemon = "rewind.daemon:main" rewind-daemon = "rewind.daemon:main"
[tool.setuptools.package-data] [tool.setuptools.package-data]

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import sys import sys
import argparse import argparse
from rewind.video import clip from rewind.core import clip, mark
def build_parser() -> argparse.ArgumentParser: def build_parser() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
@@ -19,6 +19,14 @@ def build_parser() -> argparse.ArgumentParser:
help="Number of seconds to include in the clip (default: 30)" help="Number of seconds to include in the clip (default: 30)"
) )
mark = sub.add_parser("mark", help="Mark the current time in the recording for later reference")
mark.add_argument(
"-n", "--name",
type=str,
required=True,
help="Name of the marker"
)
return parser return parser
def main(argv=None) -> int: def main(argv=None) -> int:
@@ -27,6 +35,8 @@ def main(argv=None) -> int:
if args.command == "save": if args.command == "save":
clip(args.seconds) clip(args.seconds)
elif args.command == "mark":
mark(args.name)
else: else:
parser.error("Unknown command") parser.error("Unknown command")

View File

@@ -2,6 +2,7 @@
import os import os
import datetime import datetime
import subprocess import subprocess
import json
from rewind.paths import load_state from rewind.paths import load_state
""" """
@@ -63,6 +64,27 @@ def clip(seconds_from_end: float) -> None:
combine_last_x_ts_files(seconds_from_end, output_file_name) combine_last_x_ts_files(seconds_from_end, output_file_name)
print(f"Created clip: {output_file_name}") print(f"Created clip: {output_file_name}")
def mark(name: str) -> None:
if not name:
raise ValueError("Marker name cannot be empty")
# writes marker to json file (not state)
markers_file = os.path.join(os.path.dirname(__file__), "markers.json")
if os.path.exists(markers_file):
with open(markers_file, "r") as f:
markers = json.load(f)
else:
markers = []
markers.append({
"name": name,
"timestamp": datetime.datetime.now().timestamp()
})
with open(markers_file, "w") as f:
json.dump(markers, f, indent=4)
print(f"Added marker: {name}")
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,7 +6,7 @@ import time
import obsws_python as obs import obsws_python as obs
import subprocess import subprocess
from rewind.video import get_duration from rewind.core import get_duration
from rewind.paths import load_state, write_state, load_config from rewind.paths import load_state, write_state, load_config
from watchdog.observers import Observer from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler from watchdog.events import FileSystemEventHandler
@@ -81,7 +81,13 @@ def main() -> None:
time.sleep(5) time.sleep(5)
config = load_config() config = load_config()
con = open_obs_connection(config["obs"]["host"], config["obs"]["port"], config["obs"]["password"])
con = None
for _ in range(10):
con = open_obs_connection(config["obs"]["host"], config["obs"]["port"], config["obs"]["password"])
if con is not None:
break
time.sleep(2)
recording_dir = con.get_record_directory().record_directory recording_dir = con.get_record_directory().record_directory
start_recording(con) start_recording(con)