mirror of
https://github.com/onyx-and-iris/obsws-cli.git
synced 2025-05-16 22:40:23 +01:00
41 lines
1.0 KiB
Python
41 lines
1.0 KiB
Python
"""module containing commands for controlling OBS scenes."""
|
|
|
|
import obsws_python as obsws
|
|
import typer
|
|
|
|
from .alias import AliasGroup
|
|
from .errors import ObswsCliBadParameter
|
|
|
|
app = typer.Typer(cls=AliasGroup)
|
|
|
|
|
|
@app.callback()
|
|
def main():
|
|
"""Control OBS scenes."""
|
|
|
|
|
|
@app.command('list | ls')
|
|
def list(ctx: typer.Context):
|
|
"""List all scenes."""
|
|
resp = ctx.obj['obsws'].get_scene_list()
|
|
scenes = (scene.get('sceneName') for scene in reversed(resp.scenes))
|
|
typer.echo('\n'.join(scenes))
|
|
|
|
|
|
@app.command('current | get')
|
|
def current(ctx: typer.Context):
|
|
"""Get the current program scene."""
|
|
resp = ctx.obj['obsws'].get_current_program_scene()
|
|
typer.echo(resp.current_program_scene_name)
|
|
|
|
|
|
@app.command('switch | set')
|
|
def switch(ctx: typer.Context, scene_name: str):
|
|
"""Switch to a scene."""
|
|
try:
|
|
ctx.obj['obsws'].set_current_program_scene(scene_name)
|
|
except obsws.error.OBSSDKRequestError as e:
|
|
if e.code == 600:
|
|
raise ObswsCliBadParameter(f"Scene '{scene_name}' not found.")
|
|
raise
|