From dcd34b0213c383959e623602d2a138046122c8b3 Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Tue, 10 Jun 2025 13:26:53 +0100 Subject: [PATCH] implement record command group minor bump --- pyproject.toml | 2 +- src/slobs_cli/__init__.py | 3 +- src/slobs_cli/record.py | 112 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 115 insertions(+), 2 deletions(-) create mode 100644 src/slobs_cli/record.py diff --git a/pyproject.toml b/pyproject.toml index 3c6f828..12efbe8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "slobs-cli" -version = "0.3.1" +version = "0.4.0" description = "A command line application for Streamlabs Desktop" authors = [{ name = "onyx-and-iris", email = "code@onyxandiris.online" }] dependencies = ["pyslobs>=2.0.4", "asyncclick>=8.1.8"] diff --git a/src/slobs_cli/__init__.py b/src/slobs_cli/__init__.py index 7a0c60e..1790eb6 100644 --- a/src/slobs_cli/__init__.py +++ b/src/slobs_cli/__init__.py @@ -1,5 +1,6 @@ from .cli import cli +from .record import record from .scene import scene from .stream import stream -__all__ = ["cli", "scene", "stream"] +__all__ = ["cli", "scene", "stream", "record"] diff --git a/src/slobs_cli/record.py b/src/slobs_cli/record.py new file mode 100644 index 0000000..0baa1d1 --- /dev/null +++ b/src/slobs_cli/record.py @@ -0,0 +1,112 @@ +import asyncclick as click +from anyio import create_task_group +from pyslobs import StreamingService + +from .cli import cli + + +@cli.group() +def record(): + """Recording management commands.""" + + +@record.command() +@click.pass_context +async def start(ctx: click.Context): + """Start recording.""" + + conn = ctx.obj["connection"] + ss = StreamingService(conn) + + async def _run(): + current_state = await ss.get_model() + active = current_state.recording_status != "offline" + + if active: + conn.close() + raise click.Abort(click.style("Recording is already active.", fg="red")) + + await ss.toggle_recording() + click.echo("Recording started.") + + conn.close() + + async with create_task_group() as tg: + tg.start_soon(conn.background_processing) + tg.start_soon(_run) + + +@record.command() +@click.pass_context +async def stop(ctx: click.Context): + """Stop recording.""" + + conn = ctx.obj["connection"] + ss = StreamingService(conn) + + async def _run(): + current_state = await ss.get_model() + active = current_state.recording_status != "offline" + + if not active: + conn.close() + raise click.Abort(click.style("Recording is already inactive.", fg="red")) + + await ss.toggle_recording() + click.echo("Recording stopped.") + + conn.close() + + async with create_task_group() as tg: + tg.start_soon(conn.background_processing) + tg.start_soon(_run) + + +@record.command() +@click.pass_context +async def status(ctx: click.Context): + """Get recording status.""" + + conn = ctx.obj["connection"] + ss = StreamingService(conn) + + async def _run(): + current_state = await ss.get_model() + active = current_state.recording_status != "offline" + + if active: + click.echo("Recording is currently active.") + else: + click.echo("Recording is currently inactive.") + + conn.close() + + async with create_task_group() as tg: + tg.start_soon(conn.background_processing) + tg.start_soon(_run) + + +@record.command() +@click.pass_context +async def toggle(ctx: click.Context): + """Toggle recording status.""" + + conn = ctx.obj["connection"] + ss = StreamingService(conn) + + async def _run(): + current_state = await ss.get_model() + active = current_state.recording_status != "offline" + + if active: + await ss.toggle_recording() + click.echo("Recording stopped.") + else: + await ss.toggle_recording() + click.echo("Recording started.") + + conn.close() + + async with create_task_group() as tg: + tg.start_soon(conn.background_processing) + tg.start_soon(_run)