mirror of
https://github.com/onyx-and-iris/slobs-cli.git
synced 2025-06-27 15:20:24 +01:00
implement scene command group
minor bump
This commit is contained in:
parent
3242a866e3
commit
f35a1594c6
@ -1,6 +1,6 @@
|
|||||||
[project]
|
[project]
|
||||||
name = "slobs-cli"
|
name = "slobs-cli"
|
||||||
version = "0.1.1"
|
version = "0.2.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"]
|
||||||
|
5
src/slobs_cli/__init__.py
Normal file
5
src/slobs_cli/__init__.py
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
from .cli import cli
|
||||||
|
from .scene import scene
|
||||||
|
from .stream import stream
|
||||||
|
|
||||||
|
__all__ = ["cli", "scene", "stream"]
|
86
src/slobs_cli/scene.py
Normal file
86
src/slobs_cli/scene.py
Normal file
@ -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)
|
Loading…
x
Reference in New Issue
Block a user