implement record command group

minor bump
This commit is contained in:
onyx-and-iris 2025-06-10 13:26:53 +01:00
parent 7227183073
commit dcd34b0213
3 changed files with 115 additions and 2 deletions

View File

@ -1,6 +1,6 @@
[project] [project]
name = "slobs-cli" name = "slobs-cli"
version = "0.3.1" version = "0.4.0"
description = "A command line application for Streamlabs Desktop" description = "A command line application for Streamlabs Desktop"
authors = [{ name = "onyx-and-iris", email = "code@onyxandiris.online" }] authors = [{ name = "onyx-and-iris", email = "code@onyxandiris.online" }]
dependencies = ["pyslobs>=2.0.4", "asyncclick>=8.1.8"] dependencies = ["pyslobs>=2.0.4", "asyncclick>=8.1.8"]

View File

@ -1,5 +1,6 @@
from .cli import cli from .cli import cli
from .record import record
from .scene import scene from .scene import scene
from .stream import stream from .stream import stream
__all__ = ["cli", "scene", "stream"] __all__ = ["cli", "scene", "stream", "record"]

112
src/slobs_cli/record.py Normal file
View File

@ -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)