mirror of
https://github.com/onyx-and-iris/obsws-cli.git
synced 2025-05-16 06:20:23 +01:00
add validation logic to clean up the trace stacks
This commit is contained in:
parent
c0dc55724f
commit
50b566bb71
@ -1,10 +1,8 @@
|
|||||||
"""module containing commands for manipulating groups in scenes."""
|
"""module containing commands for manipulating groups in scenes."""
|
||||||
|
|
||||||
import obsws_python as obsws
|
|
||||||
import typer
|
import typer
|
||||||
|
|
||||||
from .alias import AliasGroup
|
from .alias import AliasGroup
|
||||||
from .errors import ObswsCliBadParameter
|
|
||||||
from .protocols import DataclassProtocol
|
from .protocols import DataclassProtocol
|
||||||
|
|
||||||
app = typer.Typer(cls=AliasGroup)
|
app = typer.Typer(cls=AliasGroup)
|
||||||
@ -15,19 +13,27 @@ def main():
|
|||||||
"""Control groups in OBS scenes."""
|
"""Control groups in OBS scenes."""
|
||||||
|
|
||||||
|
|
||||||
|
def _scene_in_scenes(ctx: typer.Context, scene_name: str) -> bool:
|
||||||
|
"""Check if a scene exists in the list of scenes."""
|
||||||
|
resp = ctx.obj['obsws'].get_scene_list()
|
||||||
|
return any(scene.get('sceneName') == scene_name for scene in resp.scenes)
|
||||||
|
|
||||||
|
|
||||||
@app.command('list | ls')
|
@app.command('list | ls')
|
||||||
def list(ctx: typer.Context, scene_name: str):
|
def list(ctx: typer.Context, scene_name: str):
|
||||||
"""List groups in a scene."""
|
"""List groups in a scene."""
|
||||||
try:
|
if not _scene_in_scenes(ctx, scene_name):
|
||||||
resp = ctx.obj['obsws'].get_scene_item_list(scene_name)
|
typer.echo(
|
||||||
groups = (
|
f"Scene '{scene_name}' not found.",
|
||||||
item.get('sourceName') for item in resp.scene_items if item.get('isGroup')
|
err=True,
|
||||||
)
|
)
|
||||||
typer.echo('\n'.join(groups))
|
raise typer.Exit(code=1)
|
||||||
except obsws.error.OBSSDKRequestError as e:
|
|
||||||
if e.code == 600:
|
resp = ctx.obj['obsws'].get_scene_item_list(scene_name)
|
||||||
raise ObswsCliBadParameter(str(e)) from e
|
groups = (
|
||||||
raise
|
item.get('sourceName') for item in resp.scene_items if item.get('isGroup')
|
||||||
|
)
|
||||||
|
typer.echo('\n'.join(groups))
|
||||||
|
|
||||||
|
|
||||||
def _get_group(group_name: str, resp: DataclassProtocol) -> dict | None:
|
def _get_group(group_name: str, resp: DataclassProtocol) -> dict | None:
|
||||||
@ -46,36 +52,48 @@ def _get_group(group_name: str, resp: DataclassProtocol) -> dict | None:
|
|||||||
@app.command()
|
@app.command()
|
||||||
def show(ctx: typer.Context, scene_name: str, group_name: str):
|
def show(ctx: typer.Context, scene_name: str, group_name: str):
|
||||||
"""Show a group in a scene."""
|
"""Show a group in a scene."""
|
||||||
try:
|
if not _scene_in_scenes(ctx, scene_name):
|
||||||
resp = ctx.obj['obsws'].get_scene_item_list(scene_name)
|
typer.echo(
|
||||||
if (group := _get_group(group_name, resp)) is None:
|
f"Scene '{scene_name}' not found.",
|
||||||
raise ObswsCliBadParameter(f"Group '{group_name}' not found in scene.")
|
err=True,
|
||||||
|
|
||||||
ctx.obj['obsws'].set_scene_item_enabled(
|
|
||||||
scene_name=scene_name,
|
|
||||||
item_id=int(group.get('sceneItemId')),
|
|
||||||
enabled=True,
|
|
||||||
)
|
)
|
||||||
except obsws.error.OBSSDKRequestError as e:
|
raise typer.Exit(code=1)
|
||||||
if e.code == 600:
|
|
||||||
raise ObswsCliBadParameter(str(e)) from e
|
resp = ctx.obj['obsws'].get_scene_item_list(scene_name)
|
||||||
raise
|
if (group := _get_group(group_name, resp)) is None:
|
||||||
|
typer.echo(
|
||||||
|
f"Group '{group_name}' not found in scene {scene_name}.",
|
||||||
|
err=True,
|
||||||
|
)
|
||||||
|
raise typer.Exit(code=1)
|
||||||
|
|
||||||
|
ctx.obj['obsws'].set_scene_item_enabled(
|
||||||
|
scene_name=scene_name,
|
||||||
|
item_id=int(group.get('sceneItemId')),
|
||||||
|
enabled=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@app.command()
|
@app.command()
|
||||||
def hide(ctx: typer.Context, scene_name: str, group_name: str):
|
def hide(ctx: typer.Context, scene_name: str, group_name: str):
|
||||||
"""Hide a group in a scene."""
|
"""Hide a group in a scene."""
|
||||||
try:
|
if not _scene_in_scenes(ctx, scene_name):
|
||||||
resp = ctx.obj['obsws'].get_scene_item_list(scene_name)
|
typer.echo(
|
||||||
if (group := _get_group(group_name, resp)) is None:
|
f"Scene '{scene_name}' not found.",
|
||||||
raise ObswsCliBadParameter(f"Group '{group_name}' not found in scene.")
|
err=True,
|
||||||
|
|
||||||
ctx.obj['obsws'].set_scene_item_enabled(
|
|
||||||
scene_name=scene_name,
|
|
||||||
item_id=int(group.get('sceneItemId')),
|
|
||||||
enabled=False,
|
|
||||||
)
|
)
|
||||||
except obsws.error.OBSSDKRequestError as e:
|
raise typer.Exit(code=1)
|
||||||
if e.code == 600:
|
|
||||||
raise ObswsCliBadParameter(str(e)) from e
|
resp = ctx.obj['obsws'].get_scene_item_list(scene_name)
|
||||||
raise
|
if (group := _get_group(group_name, resp)) is None:
|
||||||
|
typer.echo(
|
||||||
|
f"Group '{group_name}' not found in scene {scene_name}.",
|
||||||
|
err=True,
|
||||||
|
)
|
||||||
|
raise typer.Exit(code=1)
|
||||||
|
|
||||||
|
ctx.obj['obsws'].set_scene_item_enabled(
|
||||||
|
scene_name=scene_name,
|
||||||
|
item_id=int(group.get('sceneItemId')),
|
||||||
|
enabled=False,
|
||||||
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user