add --preview flag to scene current and scene switch.

minor bump
This commit is contained in:
onyx-and-iris 2025-04-20 11:29:26 +01:00
parent 1ab07173e2
commit 618cdefc17
2 changed files with 44 additions and 10 deletions

View File

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

View File

@ -1,10 +1,12 @@
"""module containing commands for controlling OBS scenes.""" """module containing commands for controlling OBS scenes."""
from typing import Annotated
import obsws_python as obsws import obsws_python as obsws
import typer import typer
from .alias import AliasGroup from .alias import AliasGroup
from .errors import ObswsCliBadParameter from .errors import ObswsCliBadParameter, ObswsCliError
app = typer.Typer(cls=AliasGroup) app = typer.Typer(cls=AliasGroup)
@ -23,18 +25,50 @@ def list(ctx: typer.Context):
@app.command('current | get') @app.command('current | get')
def current(ctx: typer.Context): def current(
"""Get the current program scene.""" ctx: typer.Context,
preview: Annotated[
bool, typer.Option(help='Get the preview scene instead of the program scene')
] = False,
):
"""Get the current program scene or preview scene."""
try:
if preview:
resp = ctx.obj['obsws'].get_current_preview_scene()
typer.echo(resp.current_preview_scene_name)
else:
resp = ctx.obj['obsws'].get_current_program_scene() resp = ctx.obj['obsws'].get_current_program_scene()
typer.echo(resp.current_program_scene_name) typer.echo(resp.current_program_scene_name)
except obsws.error.OBSSDKRequestError as e:
match e.code:
case 506:
raise ObswsCliError(
'Not in studio mode, cannot get preview scene.'
) from e
raise
@app.command('switch | set') @app.command('switch | set')
def switch(ctx: typer.Context, scene_name: str): def switch(
ctx: typer.Context,
scene_name: str,
preview: Annotated[
bool,
typer.Option(help='Switch to the preview scene instead of the program scene'),
] = False,
):
"""Switch to a scene.""" """Switch to a scene."""
try: try:
if preview:
ctx.obj['obsws'].set_current_preview_scene(scene_name)
else:
ctx.obj['obsws'].set_current_program_scene(scene_name) ctx.obj['obsws'].set_current_program_scene(scene_name)
except obsws.error.OBSSDKRequestError as e: except obsws.error.OBSSDKRequestError as e:
if e.code == 600: match e.code:
raise ObswsCliBadParameter(f"Scene '{scene_name}' not found.") case 506:
raise ObswsCliError(
'Not in studio mode, cannot set preview scene.'
) from e
case 600:
raise ObswsCliBadParameter(f"Scene '{scene_name}' not found.") from e
raise raise