ADD function signatures and remove unused recording commands

This commit is contained in:
2025-12-18 01:16:59 +00:00
parent fab19ae1b6
commit 36868a08ec
3 changed files with 11 additions and 22 deletions

View File

@@ -4,20 +4,12 @@ from rewind.video import combine_last_x_ts_files
import obsws_python as obs import obsws_python as obs
import sys, argparse import sys, argparse
def start_recording(con): def create_recording(seconds: int) -> None:
con.start_record()
print("Started recording")
def stop_recording(con):
con.stop_record()
print("Stopped recording")
def create_recording(seconds):
output_file_name = f"{datetime.now().strftime('%Y-%m-%d %H:%M:%S')}.mp4" output_file_name = f"{datetime.now().strftime('%Y-%m-%d %H:%M:%S')}.mp4"
combine_last_x_ts_files(seconds, output_file_name) combine_last_x_ts_files(seconds, output_file_name)
print(f"Created clip: {output_file_name}") print(f"Created clip: {output_file_name}")
def build_parser(): def build_parser() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
prog="rewind", prog="rewind",
description="Control OBS recording and create instant clips", description="Control OBS recording and create instant clips",
@@ -25,8 +17,6 @@ def build_parser():
sub = parser.add_subparsers(dest="command", required=True) sub = parser.add_subparsers(dest="command", required=True)
sub.add_parser("start", help="Start OBS recording")
sub.add_parser("stop", help="Stop OBS recording")
save = sub.add_parser("save", help="Save a section from the current recording") save = sub.add_parser("save", help="Save a section from the current recording")
save.add_argument( save.add_argument(
"-s", "--seconds", "-s", "--seconds",
@@ -37,7 +27,7 @@ def build_parser():
return parser return parser
def main(argv=None): def main(argv=None) -> int:
parser = build_parser() parser = build_parser()
args = parser.parse_args(argv) args = parser.parse_args(argv)
@@ -46,7 +36,7 @@ def main(argv=None):
else: else:
parser.error("Unknown command") parser.error("Unknown command")
return 0
if __name__ == "__main__": if __name__ == "__main__":
sys.exit(main()) sys.exit(main())

View File

@@ -18,7 +18,7 @@ def load_state() -> dict:
with get_state_file_path().open() as f: with get_state_file_path().open() as f:
return json.load(f) return json.load(f)
def write_state(state: dict): def write_state(state: dict) -> None:
tmp = get_state_file_path().with_suffix(".tmp") tmp = get_state_file_path().with_suffix(".tmp")
with tmp.open("w") as f: with tmp.open("w") as f:
json.dump(state, f, indent=2) json.dump(state, f, indent=2)

View File

@@ -4,7 +4,6 @@ import datetime
import time import time
import obsws_python as obs import obsws_python as obs
import subprocess import subprocess
import json
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
@@ -23,15 +22,15 @@ def open_obs_connection() -> obs.ReqClient | None:
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?")
return None return None
def start_recording(con): def start_recording(con: obs.ReqClient) -> None:
con.start_record() con.start_record()
print("Started recording") print("Started recording")
def stop_recording(con): def stop_recording(con: obs.ReqClient) -> None:
con.stop_record() con.stop_record()
print("Stopped recording") print("Stopped recording")
def cleanup_old_files(directory, max_age_seconds): def cleanup_old_files(directory: str, max_age_seconds: int) -> None:
for filename in os.listdir(directory): for filename in os.listdir(directory):
file_path = os.path.join(directory, filename) file_path = os.path.join(directory, filename)
if os.path.isfile(file_path): if os.path.isfile(file_path):
@@ -41,11 +40,11 @@ def cleanup_old_files(directory, max_age_seconds):
print(f"Removed old file: {file_path}") print(f"Removed old file: {file_path}")
def create_state_file(): def create_state_file() -> None:
state = {"files": []} state = {"files": []}
write_state(state) write_state(state)
def add_file_to_state(file_path): def add_file_to_state(file_path: str) -> None:
state = load_state() state = load_state()
files = state.get("files", []) files = state.get("files", [])
@@ -62,7 +61,7 @@ def add_file_to_state(file_path):
state["files"] = files state["files"] = files
write_state(state) write_state(state)
def main(): def main() -> None:
open_obs() open_obs()
time.sleep(5) time.sleep(5)
con = open_obs_connection() con = open_obs_connection()