mirror of
https://github.com/onyx-and-iris/simple-recorder.git
synced 2025-06-27 18:00:23 +01:00
add pause, split and add chapter buttons to Recorder tab - they are not implemented yet add timeouts on requests + handle them add obs connected status message on GUI load
50 lines
1.5 KiB
Python
50 lines
1.5 KiB
Python
from datetime import datetime
|
|
|
|
import obsws_python as obsws
|
|
from clypi import Command, Positional, arg
|
|
from typing_extensions import override
|
|
|
|
from .errors import SimpleRecorderError
|
|
from .styler import highlight
|
|
|
|
|
|
class Start(Command):
|
|
"""Start recording."""
|
|
|
|
filename: Positional[str] = arg(
|
|
default="default_name",
|
|
help="Name of the recording",
|
|
prompt="Enter the name for the recording",
|
|
)
|
|
host: str = arg(inherited=True)
|
|
port: int = arg(inherited=True)
|
|
password: str = arg(inherited=True)
|
|
|
|
@staticmethod
|
|
def get_timestamp():
|
|
return datetime.now().strftime("%Y-%m-%d %H-%M-%S")
|
|
|
|
@override
|
|
async def run(self):
|
|
if not self.filename:
|
|
raise SimpleRecorderError("Recording name cannot be empty.")
|
|
|
|
try:
|
|
with obsws.ReqClient(
|
|
host=self.host, port=self.port, password=self.password, timeout=3
|
|
) as client:
|
|
resp = client.get_record_status()
|
|
if resp.output_active:
|
|
raise SimpleRecorderError("Recording is already active.")
|
|
|
|
filename = f"{self.filename} {self.get_timestamp()}"
|
|
client.set_profile_parameter(
|
|
"Output",
|
|
"FilenameFormatting",
|
|
filename,
|
|
)
|
|
client.start_record()
|
|
print(f"Recording started with filename: {highlight(filename)}")
|
|
except TimeoutError:
|
|
raise SimpleRecorderError("Failed to connect to OBS. Is it running?")
|