add toggle and visible commands to scene-item group

update README

minor bump
This commit is contained in:
2025-04-20 15:23:03 +01:00
parent 88635ed152
commit 5852dd4836
5 changed files with 87 additions and 33 deletions

View File

@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2025-present onyx-and-iris <code@onyxandiris.online>
#
# SPDX-License-Identifier: MIT
__version__ = "0.3.0"
__version__ = "0.4.0"

View File

@@ -15,6 +15,21 @@ def main():
"""Control groups in OBS scenes."""
@app.command('list | ls')
def list(ctx: typer.Context, scene_name: str):
"""List groups in a scene."""
try:
resp = ctx.obj['obsws'].get_scene_item_list(scene_name)
groups = (
item.get('sourceName') for item in resp.scene_items if item.get('isGroup')
)
typer.echo('\n'.join(groups))
except obsws.error.OBSSDKRequestError as e:
if e.code == 600:
raise ObswsCliBadParameter(str(e)) from e
raise
def _get_group(group_name: str, resp: DataclassProtocol) -> dict | None:
"""Get a group from the scene item list response."""
group = next(
@@ -64,18 +79,3 @@ def hide(ctx: typer.Context, scene_name: str, group_name: str):
if e.code == 600:
raise ObswsCliBadParameter(str(e)) from e
raise
@app.command('list | ls')
def list(ctx: typer.Context, scene_name: str):
"""List groups in a scene."""
try:
resp = ctx.obj['obsws'].get_scene_item_list(scene_name)
groups = (
item.get('sourceName') for item in resp.scene_items if item.get('isGroup')
)
typer.echo('\n'.join(groups))
except obsws.error.OBSSDKRequestError as e:
if e.code == 600:
raise ObswsCliBadParameter(str(e)) from e
raise

View File

@@ -58,7 +58,7 @@ def status(ctx: typer.Context):
typer.echo('Recording is not in progress.')
@app.command()
@app.command('toggle | tg')
def toggle(ctx: typer.Context):
"""Toggle recording."""
active, _ = _get_recording_status(ctx)

View File

@@ -14,6 +14,19 @@ def main():
"""Control items in OBS scenes."""
@app.command('list | ls')
def list(ctx: typer.Context, scene_name: str):
"""List all items in a scene."""
try:
resp = ctx.obj['obsws'].get_scene_item_list(scene_name)
items = (item.get('sourceName') for item in resp.scene_items)
typer.echo('\n'.join(items))
except obsws.error.OBSSDKRequestError as e:
if e.code == 600:
raise ObswsCliBadParameter(str(e)) from e
raise
@app.command()
def show(ctx: typer.Context, scene_name: str, item_name: str):
"""Show an item in a scene."""
@@ -48,13 +61,40 @@ def hide(ctx: typer.Context, scene_name: str, item_name: str):
raise
@app.command('list | ls')
def list(ctx: typer.Context, scene_name: str):
"""List all items in a scene."""
@app.command('toggle | tg')
def toggle(ctx: typer.Context, scene_name: str, item_name: str):
"""Toggle an item in a scene."""
try:
resp = ctx.obj['obsws'].get_scene_item_list(scene_name)
items = (item.get('sourceName') for item in resp.scene_items)
typer.echo('\n'.join(items))
resp = ctx.obj['obsws'].get_scene_item_id(scene_name, item_name)
enabled = ctx.obj['obsws'].get_scene_item_enabled(
scene_name=scene_name,
item_id=int(resp.scene_item_id),
)
new_state = not enabled.scene_item_enabled
ctx.obj['obsws'].set_scene_item_enabled(
scene_name=scene_name,
item_id=int(resp.scene_item_id),
enabled=new_state,
)
except obsws.error.OBSSDKRequestError as e:
if e.code == 600:
raise ObswsCliBadParameter(str(e)) from e
raise
@app.command()
def visible(ctx: typer.Context, scene_name: str, item_name: str):
"""Check if an item in a scene is visible."""
try:
resp = ctx.obj['obsws'].get_scene_item_id(scene_name, item_name)
enabled = ctx.obj['obsws'].get_scene_item_enabled(
scene_name=scene_name,
item_id=int(resp.scene_item_id),
)
typer.echo(
f"Item '{item_name}' in scene '{scene_name}' is currently {'visible' if enabled.scene_item_enabled else 'hidden'}."
)
except obsws.error.OBSSDKRequestError as e:
if e.code == 600:
raise ObswsCliBadParameter(str(e)) from e