diff --git a/pyproject.toml b/pyproject.toml index 6d1a4d5..7e87b00 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "slobs-cli" -version = "0.1.1" +version = "0.2.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 new file mode 100644 index 0000000..7a0c60e --- /dev/null +++ b/src/slobs_cli/__init__.py @@ -0,0 +1,5 @@ +from .cli import cli +from .scene import scene +from .stream import stream + +__all__ = ["cli", "scene", "stream"] diff --git a/src/slobs_cli/scene.py b/src/slobs_cli/scene.py new file mode 100644 index 0000000..77e2abd --- /dev/null +++ b/src/slobs_cli/scene.py @@ -0,0 +1,86 @@ +import asyncclick as click +from anyio import create_task_group +from pyslobs import ScenesService + +from .cli import cli + + +@cli.group() +def scene(): + """Scene management commands.""" + + +@scene.command() +@click.pass_context +async def list(ctx: click.Context): + """List all available scenes.""" + + conn = ctx.obj["connection"] + ss = ScenesService(conn) + + async def _run(): + scenes = await ss.get_scenes() + if not scenes: + click.echo("No scenes found.") + return + + click.echo("Available scenes:") + for scene in scenes: + click.echo(f"- {click.style(scene.name, fg='blue')} (ID: {scene.id})") + + conn.close() + + async with create_task_group() as tg: + tg.start_soon(conn.background_processing) + tg.start_soon(_run) + + +@scene.command() +@click.pass_context +async def current(ctx: click.Context): + """Show the currently active scene.""" + + conn = ctx.obj["connection"] + ss = ScenesService(conn) + + async def _run(conn): + active_scene = await ss.active_scene() + if active_scene: + click.echo( + f"Current active scene: {click.style(active_scene.name, fg='green')} (ID: {active_scene.id})" + ) + else: + click.echo("No active scene found.") + conn.close() + + async with create_task_group() as tg: + tg.start_soon(conn.background_processing) + tg.start_soon(_run, conn) + + +@scene.command() +@click.argument("scene_name", type=str) +@click.pass_context +async def switch(ctx: click.Context, scene_name: str): + """Switch to a scene by its name.""" + + conn = ctx.obj["connection"] + ss = ScenesService(conn) + + async def _run(conn): + scenes = await ss.get_scenes() + for scene in scenes: + if scene.name == scene_name: + await ss.make_scene_active(scene.id) + click.echo(f"Switched to scene: {click.style(scene.name, fg='green')}") + conn.close() + break + else: + conn.close() + raise click.ClickException( + click.style(f"Scene '{scene_name}' not found.", fg="red") + ) + + async with create_task_group() as tg: + tg.start_soon(conn.background_processing) + tg.start_soon(_run, conn)