diff --git a/README.md b/README.md index 2436737..c6921fd 100644 --- a/README.md +++ b/README.md @@ -486,6 +486,35 @@ obsws-cli hotkey trigger-sequence OBS_KEY_F1 --ctrl obsws-cli hotkey trigger-sequence OBS_KEY_F1 --shift --ctrl ``` +#### Filter + +- list: List filters for a source. + - args: + +```console +obsws-cli filter list "Mic/Aux" +``` + +- enable: Enable a filter for a source. + - args: + +```console +obsws-cli filter enable "Mic/Aux" "Test Compression Filter" +``` + +- disable: Disable a filter for a source. + - args: + +```console +obsws-cli filter disable "Mic/Aux" "Test Compression Filter" +``` + +- toggle: Toggle a filter for a source. + - args: + +```console +obsws-cli filter toggle "Mic/Aux" "Test Compression Filter" +``` ## License diff --git a/obsws_cli/app.py b/obsws_cli/app.py index d503a67..96cbf64 100644 --- a/obsws_cli/app.py +++ b/obsws_cli/app.py @@ -6,6 +6,7 @@ import obsws_python as obsws import typer from . import ( + filter, group, hotkey, input, @@ -24,6 +25,7 @@ from .alias import AliasGroup app = typer.Typer(cls=AliasGroup) for module in ( + filter, group, hotkey, input, diff --git a/obsws_cli/filter.py b/obsws_cli/filter.py new file mode 100644 index 0000000..f9b69b4 --- /dev/null +++ b/obsws_cli/filter.py @@ -0,0 +1,87 @@ +"""module containing commands for manipulating filters in scenes.""" + +import typer + +from .alias import AliasGroup + +app = typer.Typer(cls=AliasGroup) + + +@app.callback() +def main(): + """Control filters in OBS scenes.""" + + +@app.command('list | ls') +def list(ctx: typer.Context, source_name: str): + """List filters for a source.""" + resp = ctx.obj.get_source_filter_list(source_name) + + if not resp.filters: + typer.echo(f'No filters found for source {source_name}') + return + + for filter in resp.filters: + typer.echo(f'Filter: {filter["filterName"]}') + for key, value in filter.items(): + if key != 'filterName': + typer.echo(f' {key}: {value}') + + +def _get_filter_enabled(ctx: typer.Context, source_name: str, filter_name: str): + """Get the status of a filter for a source.""" + resp = ctx.obj.get_source_filter(source_name, filter_name) + return resp.filter_enabled + + +@app.command('enable | on') +def enable( + ctx: typer.Context, + source_name: str = typer.Argument(..., help='The source to enable the filter for'), + filter_name: str = typer.Argument(..., help='The name of the filter to enable'), +): + """Enable a filter for a source.""" + if _get_filter_enabled(ctx, source_name, filter_name): + typer.echo( + f'Filter {filter_name} is already enabled for source {source_name}', + err=True, + ) + raise typer.Exit(1) + + ctx.obj.set_source_filter_enabled(source_name, filter_name, enabled=True) + typer.echo(f'Enabled filter {filter_name} for source {source_name}') + + +@app.command('disable | off') +def disable( + ctx: typer.Context, + source_name: str = typer.Argument(..., help='The source to disable the filter for'), + filter_name: str = typer.Argument(..., help='The name of the filter to disable'), +): + """Disable a filter for a source.""" + if not _get_filter_enabled(ctx, source_name, filter_name): + typer.echo( + f'Filter {filter_name} is already disabled for source {source_name}', + err=True, + ) + raise typer.Exit(1) + + ctx.obj.set_source_filter_enabled(source_name, filter_name, enabled=False) + typer.echo(f'Disabled filter {filter_name} for source {source_name}') + + +@app.command('toggle | tg') +def toggle( + ctx: typer.Context, + source_name: str = typer.Argument(..., help='The source to toggle the filter for'), + filter_name: str = typer.Argument(..., help='The name of the filter to toggle'), +): + """Toggle a filter for a source.""" + is_enabled = _get_filter_enabled(ctx, source_name, filter_name) + new_state = not is_enabled + + ctx.obj.set_source_filter_enabled(source_name, filter_name, enabled=new_state) + if new_state: + typer.echo(f'Enabled filter {filter_name} for source {source_name}') + else: + typer.echo(f'Disabled filter {filter_name} for source {source_name}')