From cef299b92f86f7ffe7151dd661c81c922381834f Mon Sep 17 00:00:00 2001 From: Dylan De Faoite Date: Tue, 16 Dec 2025 18:16:02 +0000 Subject: [PATCH] MODULARISE clip file into separate functions & ADD argparser --- ...example.config.toml => example.config.toml | 0 rewind/clip.py | 60 ++++++++++++++----- 2 files changed, 45 insertions(+), 15 deletions(-) rename rewind/example.config.toml => example.config.toml (100%) diff --git a/rewind/example.config.toml b/example.config.toml similarity index 100% rename from rewind/example.config.toml rename to example.config.toml diff --git a/rewind/clip.py b/rewind/clip.py index 31ebfa3..acdca08 100755 --- a/rewind/clip.py +++ b/rewind/clip.py @@ -1,29 +1,59 @@ #!/usr/bin/env python3 from datetime import datetime -from video import clip +from rewind.video import clip import obsws_python as obs -import sys, os +import sys, argparse command = sys.argv[1] if len(sys.argv) > 1 else None -con = obs.ReqClient() -response = con.get_version() -print(f"OBS WebSocket Version: {response.obs_web_socket_version}") - -if command == "start": +def start_recording(con): con.start_record() - print(f"Started recording") -elif command == "stop": + print("Started recording") + +def stop_recording(con): con.stop_record() print("Stopped recording") -elif command == "clip": + +def create_clip(con): record_dir = con.get_record_directory() - 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" clip(record_dir.record_directory, output_file_name) - print(f"Created clip: {output_file_name}") -else: - print("Unknown command. Use 'start', 'stop', or 'clip'.") -con.disconnect() +def build_parser(): + parser = argparse.ArgumentParser( + prog="rewind", + description="Control OBS recording and create instant clips", + ) + + sub = parser.add_subparsers(dest="command", required=True) + + sub.add_parser("start", help="Start OBS recording") + sub.add_parser("stop", help="Stop OBS recording") + sub.add_parser("clip", help="Create a clip from the current recording") + + return parser + +def main(argv=None): + parser = build_parser() + args = parser.parse_args(argv) + + con = obs.ReqClient() + + try: + if args.command == "start": + start_recording(con) + elif args.command == "stop": + stop_recording(con) + elif args.command == "clip": + create_clip(con) + else: + parser.error("Unknown command") + + finally: + con.disconnect() + + +if __name__ == "__main__": + sys.exit(main()) \ No newline at end of file