diff --git a/README.md b/README.md index 2b8000f..c1c4999 100644 --- a/README.md +++ b/README.md @@ -125,6 +125,34 @@ obsws-cli scene-item toggle START "Colour Source" obsws-cli scene-item visible START "Colour Source" ``` +#### Scene Collections + +- list: List all scene collections. + +```console +obsws-cli scene-collection list +``` + +- current: Get the current scene collection. + +```console +obsws-cli scene-collection current +``` + +- switch: Switch to a scene collection. + - args: + +```console +obsws-cli scene-collection switch LIVE +``` + +- create: Create a new scene collection. + - args: + +```console +obsws-cli scene-collection switch LIVE +``` + #### Group - list: List groups in a scene. diff --git a/obsws_cli/__about__.py b/obsws_cli/__about__.py index dcdf724..1717ffa 100644 --- a/obsws_cli/__about__.py +++ b/obsws_cli/__about__.py @@ -1,4 +1,4 @@ # SPDX-FileCopyrightText: 2025-present onyx-and-iris # # SPDX-License-Identifier: MIT -__version__ = "0.4.0" +__version__ = "0.5.0" diff --git a/obsws_cli/app.py b/obsws_cli/app.py index 5b92a43..e1e8f80 100644 --- a/obsws_cli/app.py +++ b/obsws_cli/app.py @@ -8,7 +8,7 @@ import typer from pydantic import ConfigDict from pydantic_settings import BaseSettings -from . import group, input, record, scene, sceneitem, stream +from . import group, input, record, scene, scenecollection, sceneitem, stream class Settings(BaseSettings): @@ -36,6 +36,7 @@ app.add_typer(group.app, name='group') app.add_typer(input.app, name='input') app.add_typer(record.app, name='record') app.add_typer(stream.app, name='stream') +app.add_typer(scenecollection.app, name='scene-collection') @app.command() diff --git a/obsws_cli/scenecollection.py b/obsws_cli/scenecollection.py new file mode 100644 index 0000000..92c431f --- /dev/null +++ b/obsws_cli/scenecollection.py @@ -0,0 +1,66 @@ +"""module containing commands for manipulating scene collections.""" + +import obsws_python as obsws +import typer + +from .alias import AliasGroup + +app = typer.Typer(cls=AliasGroup) + + +@app.callback() +def main(): + """Control scene collections in OBS.""" + + +@app.command('list | ls') +def list(ctx: typer.Context): + """List all scene collections.""" + resp = ctx.obj['obsws'].get_scene_collection_list() + typer.echo('\n'.join(resp.scene_collections)) + + +@app.command('current | get') +def current(ctx: typer.Context): + """Get the current scene collection.""" + resp = ctx.obj['obsws'].get_scene_collection_list() + typer.echo(resp.current_scene_collection_name) + + +@app.command('switch | set') +def switch(ctx: typer.Context, scene_collection_name: str): + """Switch to a scene collection.""" + current_scene_collection = ( + ctx.obj['obsws'].get_scene_collection_list().current_scene_collection_name + ) + if scene_collection_name == current_scene_collection: + typer.echo( + f'Scene collection "{scene_collection_name}" is already active.', err=True + ) + raise typer.Exit(code=1) + + try: + ctx.obj['obsws'].set_current_scene_collection(scene_collection_name) + typer.echo(f'Switched to scene collection {scene_collection_name}') + except obsws.error.OBSSDKRequestError as e: + if e.code == 600: + typer.echo( + f'Scene collection "{scene_collection_name}" does not exist.', + err=True, + ) + raise typer.Exit(code=e.code) + + +@app.command('create | new') +def create(ctx: typer.Context, scene_collection_name: str): + """Create a new scene collection.""" + try: + ctx.obj['obsws'].create_scene_collection(scene_collection_name) + typer.echo(f'Created scene collection {scene_collection_name}') + except obsws.error.OBSSDKRequestError as e: + if e.code == 601: + typer.echo( + f'Scene collection "{scene_collection_name}" already exists.', + err=True, + ) + raise typer.Exit(code=e.code) diff --git a/pyproject.toml b/pyproject.toml index 469db82..ae33594 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -39,6 +39,7 @@ obsws-cli = "obsws_cli:app" path = "obsws_cli/__about__.py" [tool.hatch.envs.default.scripts] +cli = "obsws-cli {args:obsws_cli}" test = "pytest {args:obsws_cli tests}" [tool.hatch.envs.hatch-test]