From ef68915f6a4ab3a4eba115268d9b36c2b9b54c49 Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Fri, 27 Jun 2025 08:17:04 +0100 Subject: [PATCH] implement pause + resume --- src/simple_recorder/pause.py | 30 ++++++++++++++++++++++++++++++ src/simple_recorder/resume.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 src/simple_recorder/pause.py create mode 100644 src/simple_recorder/resume.py diff --git a/src/simple_recorder/pause.py b/src/simple_recorder/pause.py new file mode 100644 index 0000000..ac2ed2d --- /dev/null +++ b/src/simple_recorder/pause.py @@ -0,0 +1,30 @@ +import obsws_python as obsws +from clypi import Command, arg +from typing_extensions import override + +from .errors import SimpleRecorderError + + +class Pause(Command): + """Pause recording.""" + + host: str = arg(inherited=True) + port: int = arg(inherited=True) + password: str = arg(inherited=True) + + @override + async def run(self): + try: + with obsws.ReqClient( + host=self.host, port=self.port, password=self.password, timeout=3 + ) as client: + resp = client.get_record_status() + if not resp.output_active: + raise SimpleRecorderError("No active recording to pause.") + if resp.output_paused: + raise SimpleRecorderError("Recording is already paused.") + + client.pause_record() + print("Recording paused successfully.") + except TimeoutError: + raise SimpleRecorderError("Failed to connect to OBS. Is it running?") diff --git a/src/simple_recorder/resume.py b/src/simple_recorder/resume.py new file mode 100644 index 0000000..2d8c5f1 --- /dev/null +++ b/src/simple_recorder/resume.py @@ -0,0 +1,30 @@ +import obsws_python as obsws +from clypi import Command, arg +from typing_extensions import override + +from .errors import SimpleRecorderError + + +class Resume(Command): + """Resume recording.""" + + host: str = arg(inherited=True) + port: int = arg(inherited=True) + password: str = arg(inherited=True) + + @override + async def run(self): + try: + with obsws.ReqClient( + host=self.host, port=self.port, password=self.password, timeout=3 + ) as client: + resp = client.get_record_status() + if not resp.output_active: + raise SimpleRecorderError("No active recording to resume.") + if not resp.output_paused: + raise SimpleRecorderError("Recording is not paused.") + + client.resume_record() + print("Recording resumed successfully.") + except TimeoutError: + raise SimpleRecorderError("Failed to connect to OBS. Is it running?")